mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 03:42:27 +03:00
Updated version handling in Admin-X Settings
fix https://linear.app/tryghost/issue/DEV-22/add-support-to-admin-for-parsing-ghost-git-version - we need to be handle the output given by `git describe`, to account for upcoming changes to our versioning - this commit allows Admin-X Settings to parse these strings, and adds tests to check for this
This commit is contained in:
parent
1f3e72eac8
commit
c29dc48370
@ -1,20 +1,35 @@
|
|||||||
import semverParse from 'semver/functions/parse';
|
import semverParse from 'semver/functions/parse';
|
||||||
|
|
||||||
export function linkToGitHubReleases(version: string):string {
|
// This function needs to support:
|
||||||
if (version.includes('-pre.')) {
|
// - 5.94.1+moya
|
||||||
try {
|
// - 5.94.1-0-g1f3e72eac8+moya
|
||||||
const semverVersion = semverParse(version, {includePrerelease: true} as any);
|
// - 5.95.0-pre-g028c1a6+moya
|
||||||
|
export function linkToGitHubReleases(version: string): string {
|
||||||
|
if (!version) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if (semverVersion && semverVersion.build?.[0]) {
|
const cleanedVersion = version.replace('+moya', '');
|
||||||
return `https://github.com/TryGhost/Ghost/commit/${semverVersion.build[0]}`;
|
|
||||||
|
try {
|
||||||
|
const semverVersion = semverParse(cleanedVersion, {includePrerelease: true} as any);
|
||||||
|
const prerelease = semverVersion?.prerelease;
|
||||||
|
|
||||||
|
if (prerelease && prerelease?.length > 0) {
|
||||||
|
const splitPrerelease = String(prerelease[0]).split('-');
|
||||||
|
const commitHash = splitPrerelease[1];
|
||||||
|
|
||||||
|
if (!commitHash || !commitHash.startsWith('g')) {
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
const commitHashWithoutG = commitHash.slice(1);
|
||||||
} catch (e) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let cleanedVersion = version.replace('+moya', '');
|
|
||||||
|
|
||||||
return `https://github.com/TryGhost/Ghost/releases/tag/v${cleanedVersion}`;
|
return `https://github.com/TryGhost/Ghost/commit/${commitHashWithoutG}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `https://github.com/TryGhost/Ghost/releases/tag/v${cleanedVersion}`;
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,33 @@ import * as assert from 'assert/strict';
|
|||||||
import {linkToGitHubReleases} from '../../../src/utils/linkToGithubReleases';
|
import {linkToGitHubReleases} from '../../../src/utils/linkToGithubReleases';
|
||||||
|
|
||||||
describe('linkToGithubRelease', function () {
|
describe('linkToGithubRelease', function () {
|
||||||
it('generates a link to a release', function () {
|
it('handles empty version', function () {
|
||||||
let version = '5.69.0';
|
const link = linkToGitHubReleases('');
|
||||||
let link = linkToGitHubReleases(version);
|
assert.equal(link, '');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles plain version release', function () {
|
||||||
|
const link = linkToGitHubReleases('5.69.0');
|
||||||
assert.equal(link, 'https://github.com/TryGhost/Ghost/releases/tag/v5.69.0');
|
assert.equal(link, 'https://github.com/TryGhost/Ghost/releases/tag/v5.69.0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('strips moya from the version', function () {
|
it('handles plain version with +moya suffix', function () {
|
||||||
let version = '5.69.0+moya';
|
const link = linkToGitHubReleases('5.69.0+moya');
|
||||||
let link = linkToGitHubReleases(version);
|
|
||||||
assert.equal(link, 'https://github.com/TryGhost/Ghost/releases/tag/v5.69.0');
|
assert.equal(link, 'https://github.com/TryGhost/Ghost/releases/tag/v5.69.0');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles git describe output', function () {
|
||||||
|
const link = linkToGitHubReleases('5.69.0-0-gabcdef');
|
||||||
|
assert.equal(link, 'https://github.com/TryGhost/Ghost/commit/abcdef');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles git describe output with +moya suffix', function () {
|
||||||
|
const link = linkToGitHubReleases('5.69.0-0-gabcdef+moya');
|
||||||
|
assert.equal(link, 'https://github.com/TryGhost/Ghost/commit/abcdef');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles prerelease version', function () {
|
||||||
|
const link = linkToGitHubReleases('5.70.0-pre-gabcdef+moya');
|
||||||
|
assert.equal(link, 'https://github.com/TryGhost/Ghost/commit/abcdef');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user