- 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`)
|
||||||
|
})
|
||||||
+5
-5
@@ -52,7 +52,7 @@ export class Tags {
|
|||||||
ignorePreReleases: boolean,
|
ignorePreReleases: boolean,
|
||||||
maxTagsToFetch: number
|
maxTagsToFetch: number
|
||||||
): Promise<TagInfo | null> {
|
): Promise<TagInfo | null> {
|
||||||
const tags = this.sortTags(await this.getTags(owner, repo, maxTagsToFetch))
|
const tags = sortTags(await this.getTags(owner, repo, maxTagsToFetch))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const length = tags.length
|
const length = tags.length
|
||||||
@@ -76,6 +76,7 @@ export class Tags {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Sorts an array of tags as shown below:
|
Sorts an array of tags as shown below:
|
||||||
@@ -91,8 +92,8 @@ export class Tags {
|
|||||||
2020.3.1-a01
|
2020.3.1-a01
|
||||||
2020.3.0
|
2020.3.0
|
||||||
*/
|
*/
|
||||||
private sortTags(commits: TagInfo[]): TagInfo[] {
|
export function sortTags(tags: TagInfo[]): TagInfo[] {
|
||||||
commits.sort((b, a) => {
|
tags.sort((b, a) => {
|
||||||
const partsA = a.name.replace(/^v/, '').split('-')
|
const partsA = a.name.replace(/^v/, '').split('-')
|
||||||
const partsB = b.name.replace(/^v/, '').split('-')
|
const partsB = b.name.replace(/^v/, '').split('-')
|
||||||
const versionCompare = partsA[0].localeCompare(partsB[0])
|
const versionCompare = partsA[0].localeCompare(partsB[0])
|
||||||
@@ -108,6 +109,5 @@ export class Tags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return commits
|
return tags
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user