Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/github-repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('GithubRepo', () => {
it('returns undefined if there is no matching tag', async() => {
githubRepo = getTestGithubRepo({
paginate: sinon.stub().resolves([
{ name: '[email protected]', commit: { sha: 'sha-1' } },
{ name: 'v0.0.6', commit: { sha: 'sha-1' } },
{ name: 'v0.0.3-draft.0', commit: { sha: 'sha-2' } },
{ name: 'v0.0.3-draft.1', commit: { sha: 'sha-3' } },
Expand Down
9 changes: 8 additions & 1 deletion src/github-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ export class GithubRepo {

/**
* Get all tags from the Github repository, sorted by highest version to lowest version.
* Tagged package releases (e.g. `[email protected]`) are sorted alphabetically, following tags
* that are not associated with a specific package.
*/
private async getTagsOrdered(): Promise<Tag[]> {
const tags = await this.octokit.paginate<{name: string, commit: {sha: string}}>(
Expand All @@ -178,8 +180,13 @@ export class GithubRepo {
.map((t) => ({
name: t.name,
sha: t.commit.sha,
compareKey: ['', ...t.name.split('@')].slice(-2) // [pkgname | '', semver]
}))
.sort((t1, t2) => -1 * semver.compare(t1.name, t2.name));
.sort((t1, t2) => {
if (t1.compareKey[0] < t2.compareKey[0]) return -1;
if (t1.compareKey[0] > t2.compareKey[0]) return 1;
return semver.rcompare(t1.compareKey[1], t2.compareKey[1]);
}).map(({ name, sha }) => ({ name, sha }));
}

/**
Expand Down