@@ -13,17 +13,21 @@ import observe from '../helpers/selector-observer.js';
1313import ClosingRemarks from './closing-remarks.svelte' ;
1414import HeaderTag from '../components/closing-remarks-header-tag.svelte' ;
1515
16- function excludeNightliesAndJunk ( { textContent} : HTMLAnchorElement ) : boolean {
17- // https://github.com/refined-github/refined-github/issues/7206
18- return ! textContent . includes ( 'nightly' ) && / \d [ . ] \d / . test ( textContent ) ;
19- }
20-
2116const firstTag = new CachedFunction ( 'first-tag' , {
2217 async updater ( commit : string ) : Promise < string | false > {
2318 const tagsAndBranches = await fetchDom ( buildRepoUrl ( 'branch_commits' , commit ) ) ;
2419 const tags = $$optional ( 'ul.branches-tag-list a' , tagsAndBranches ) ;
25- // eslint-disable-next-line unicorn/no-array-callback-reference -- Just this once, I swear
26- return tags . findLast ( excludeNightliesAndJunk ) ?. textContent ?? false ;
20+ // Prefer versioned tags https://github.com/refined-github/refined-github/issues/7206
21+ const tag = tags . findLast ( ( { textContent} ) =>
22+ ! textContent . includes ( 'nightly' ) && / \d [ . ] \d / . test ( textContent ) ,
23+ )
24+
25+ // But still select any tag if no versioned tags are found
26+ // https://github.com/refined-github/refined-github/issues/9831
27+ ?? tags . at ( - 1 ) ;
28+
29+ // No tags might be found at all
30+ return tag ?. textContent ?? false ;
2731 } ,
2832 cacheKey : ( [ commit ] ) => [ getRepo ( ) ! . nameWithOwner , commit ] . join ( ':' ) ,
2933} ) ;
@@ -42,18 +46,17 @@ function mountClosingRemarks(props: ComponentProps<typeof ClosingRemarks>, signa
4246}
4347
4448async function init ( signal : AbortSignal ) : Promise < void > {
45- const hash = getMergeCommitHash ( ) ;
46- const tagName = await firstTag . get ( hash ) ;
47-
48- if ( tagName ) {
49- mountClosingRemarks ( { tagName} , signal ) ;
50- observe ( '[class*="PullRequestHeaderSummary"] relative-time' , relativeTime => {
51- mount ( HeaderTag , { target : relativeTime . parentElement ! , props : { tagName} } ) ;
52- } , { signal} ) ;
49+ const mergeCommit = getMergeCommitHash ( ) ;
50+ const tagName = await firstTag . get ( mergeCommit ) ;
51+ if ( ! tagName ) {
52+ mountClosingRemarks ( { mergeCommit} , signal ) ;
5353 return ;
5454 }
5555
56- mountClosingRemarks ( { } , signal ) ;
56+ mountClosingRemarks ( { tagName, mergeCommit} , signal ) ;
57+ observe ( '[class*="PullRequestHeaderSummary"] relative-time' , relativeTime => {
58+ mount ( HeaderTag , { target : relativeTime . parentElement ! , props : { tagName} } ) ;
59+ } , { signal} ) ;
5760}
5861
5962void features . add ( import . meta. url , {
@@ -84,11 +87,10 @@ Test URLs
8487- PR: https://github.com/refined-github/refined-github/pull/5600
8588- Locked PR: https://github.com/eslint/eslint/pull/17
8689- Archived repo: https://github.com/fregante/iphone-inline-video/pull/130
87- - Junk tag: https://github.com/refined-github/sandbox/pull/1
88- - See: https://github.com/refined-github/sandbox/branch_commits/f743c334f6475021ef133591b587bc282c0cf4c4
89- - Normal tag: https://togithub.com/refined-github/refined-github/pull/7127
90- - See https://github.com/refined-github/refined-github/branch_commits/5321825
91- - Nightly tag: https://togithub.com/neovim/neovim/pull/22060
92- - see: https://github.com/neovim/neovim/branch_commits/27b81af
90+ - Untagged PR: https://github.com/mwmwmwmwmwmwmwmwmwmwmwwwmwmwmwmwmwmwmwm/closing-remarks/pull/3
91+ - Prefer versioned tag: https://github.com/mwmwmwmwmwmwmwmwmwmwmwwwmwmwmwmwmwmwmwm/closing-remarks/pull/1
92+ - See: https://github.com/mwmwmwmwmwmwmwmwmwmwmwwwmwmwmwmwmwmwmwm/closing-remarks/branch_commits/60eb1e5ee0953c70e6fc6150dbeacd1cf20899be
93+ - Show nightly tag if alone: https://github.com/mwmwmwmwmwmwmwmwmwmwmwwwmwmwmwmwmwmwmwm/closing-remarks/pull/2
94+ - See https://github.com/mwmwmwmwmwmwmwmwmwmwmwwwmwmwmwmwmwmwmwm/closing-remarks/branch_commits/7571f5312ab5db9c23aa11a7e40c5ec88624a11b
9395
9496*/
0 commit comments