Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f208ea2

Browse files
authored
closing-remarks - Show nightly tag if nothing else is found (refined-github#9918)
1 parent 89f6ca5 commit f208ea2

2 files changed

Lines changed: 31 additions & 24 deletions

File tree

source/features/closing-remarks.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
type Props = {
1212
tagName?: string;
1313
postMerge?: boolean;
14+
mergeCommit?: string;
1415
};
1516
16-
const {tagName, postMerge = false}: Props = $props();
17+
const {tagName, postMerge = false, mergeCommit}: Props = $props();
1718
1819
const explanationHref =
1920
'https://github.com/refined-github/refined-github/wiki/Extended-feature-descriptions#closing-remarks';
@@ -46,7 +47,11 @@
4647
{#if postMerge}
4748
Now you can release this change
4849
{:else}
49-
No <a href={explanationHref}>stable version tags</a> for this PR.
50+
This PR hasn't been released yet, <a href={explanationHref}>
51+
judging
52+
</a> by its <a href={buildRepoUrl('commits', mergeCommit!)}>
53+
merge commit
54+
</a>.
5055
{/if}
5156
{/snippet}
5257
{#await userHasPushAccess() then hasPushAccess}

source/features/closing-remarks.tsx

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ import observe from '../helpers/selector-observer.js';
1313
import ClosingRemarks from './closing-remarks.svelte';
1414
import 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-
2116
const 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

4448
async 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

5962
void 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

Comments
 (0)