- make sortTags method to be accessible for test
- add test to verify ordering of tags
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { resolveConfiguration } from '../src/utils';
|
||||
import { ReleaseNotesBuilder } from '../src/releaseNotesBuilder';
|
||||
import { TagInfo, sortTags } from '../src/tags';
|
||||
|
||||
it('Should order tags correctly', async () => {
|
||||
jest.setTimeout(180000)
|
||||
|
||||
const tags: TagInfo[] = [
|
||||
{ name: "2020.4.0", commit: "" },
|
||||
{ name: "2020.4.0-rc02", commit: "" },
|
||||
{ name: "2020.3.2", commit: "" },
|
||||
{ name: "v2020.3.1", commit: "" },
|
||||
{ name: "2020.3.1-rc03", commit: "" },
|
||||
{ name: "2020.3.1-rc01", commit: "" },
|
||||
{ name: "2020.3.1-b01", commit: "" },
|
||||
{ name: "v2020.3.0", commit: "" }
|
||||
]
|
||||
|
||||
const sorted = sortTags(tags).map(function (tag) {
|
||||
return tag.name
|
||||
}).join(",")
|
||||
|
||||
expect(sorted).toStrictEqual(`2020.4.0,2020.4.0-rc02,2020.3.2,v2020.3.1,2020.3.1-rc03,2020.3.1-rc01,2020.3.1-b01,v2020.3.0`)
|
||||
})
|
||||
+19
-19
@@ -52,7 +52,7 @@ export class Tags {
|
||||
ignorePreReleases: boolean,
|
||||
maxTagsToFetch: number
|
||||
): Promise<TagInfo | null> {
|
||||
const tags = this.sortTags(await this.getTags(owner, repo, maxTagsToFetch))
|
||||
const tags = sortTags(await this.getTags(owner, repo, maxTagsToFetch))
|
||||
|
||||
try {
|
||||
const length = tags.length
|
||||
@@ -76,8 +76,9 @@ export class Tags {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
Sorts an array of tags as shown below:
|
||||
|
||||
2020.4.0
|
||||
@@ -91,23 +92,22 @@ export class Tags {
|
||||
2020.3.1-a01
|
||||
2020.3.0
|
||||
*/
|
||||
private sortTags(commits: TagInfo[]): TagInfo[] {
|
||||
commits.sort((b, a) => {
|
||||
const partsA = a.name.replace(/^v/, '').split('-')
|
||||
const partsB = b.name.replace(/^v/, '').split('-')
|
||||
const versionCompare = partsA[0].localeCompare(partsB[0])
|
||||
if (versionCompare !== 0) {
|
||||
return versionCompare
|
||||
export function sortTags(tags: TagInfo[]): TagInfo[] {
|
||||
tags.sort((b, a) => {
|
||||
const partsA = a.name.replace(/^v/, '').split('-')
|
||||
const partsB = b.name.replace(/^v/, '').split('-')
|
||||
const versionCompare = partsA[0].localeCompare(partsB[0])
|
||||
if (versionCompare !== 0) {
|
||||
return versionCompare
|
||||
} else {
|
||||
if (partsA.length === 1) {
|
||||
return 0
|
||||
} else if (partsB.length === 1) {
|
||||
return 1
|
||||
} else {
|
||||
if (partsA.length === 1) {
|
||||
return 0
|
||||
} else if (partsB.length === 1) {
|
||||
return 1
|
||||
} else {
|
||||
return partsA[1].localeCompare(partsB[1])
|
||||
}
|
||||
return partsA[1].localeCompare(partsB[1])
|
||||
}
|
||||
})
|
||||
return commits
|
||||
}
|
||||
}
|
||||
})
|
||||
return tags
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user