Skip to content

Commit 0482164

Browse files
authored
fix: handle package name tags in getTagsOrdered (#8)
1 parent e3d7244 commit 0482164

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/github-repo.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ describe('GithubRepo', () => {
102102
it('returns undefined if there is no matching tag', async() => {
103103
githubRepo = getTestGithubRepo({
104104
paginate: sinon.stub().resolves([
105+
{ name: '[email protected]', commit: { sha: 'sha-1' } },
105106
{ name: 'v0.0.6', commit: { sha: 'sha-1' } },
106107
{ name: 'v0.0.3-draft.0', commit: { sha: 'sha-2' } },
107108
{ name: 'v0.0.3-draft.1', commit: { sha: 'sha-3' } },

src/github-repo.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ export class GithubRepo {
167167

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

185192
/**

0 commit comments

Comments
 (0)