File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff 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 : 'unrelatedpkg@v1.2.3' , 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' } } ,
Original file line number Diff line number Diff 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. `foo@v2.3.4`) 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 /**
You can’t perform that action at this time.
0 commit comments