summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/features/closing-remarks.tsx5
-rw-r--r--source/features/releases-tab.gql3
-rw-r--r--source/features/releases-tab.tsx48
3 files changed, 34 insertions, 22 deletions
diff --git a/source/features/closing-remarks.tsx b/source/features/closing-remarks.tsx
index 03858779..47e2e86c 100644
--- a/source/features/closing-remarks.tsx
+++ b/source/features/closing-remarks.tsx
@@ -12,7 +12,7 @@ import TimelineItem from '../github-helpers/timeline-item.js';
import attachElement from '../helpers/attach-element.js';
import {canEditEveryComment} from './quick-comment-edit.js';
import {buildRepoURL, getRepo, isRefinedGitHubRepo} from '../github-helpers/index.js';
-import {releasesCount} from './releases-tab.js';
+import {getReleases} from './releases-tab.js';
import observe from '../helpers/selector-observer.js';
// TODO: Not an exact match; Moderators can edit comments but not create releases
@@ -91,7 +91,8 @@ function addExistingTagLinkFooter(tagName: string, tagUrl: string): void {
}
async function addReleaseBanner(text = 'Now you can release this change'): Promise<void> {
- if (await releasesCount.get(getRepo()!.nameWithOwner) === 0) {
+ const [releases] = await getReleases();
+ if (releases === 0) {
return;
}
diff --git a/source/features/releases-tab.gql b/source/features/releases-tab.gql
index a7f43d66..ef8be1f9 100644
--- a/source/features/releases-tab.gql
+++ b/source/features/releases-tab.gql
@@ -3,5 +3,8 @@ query GetReleasesCount($owner: String!, $name: String!) {
releases {
totalCount
}
+ tags: refs(refPrefix: "refs/tags/") {
+ totalCount
+ }
}
}
diff --git a/source/features/releases-tab.tsx b/source/features/releases-tab.tsx
index 712b1110..483152d4 100644
--- a/source/features/releases-tab.tsx
+++ b/source/features/releases-tab.tsx
@@ -19,31 +19,39 @@ function detachHighlightFromCodeTab(codeTab: HTMLAnchorElement): void {
codeTab.dataset.selectedLinks = codeTab.dataset.selectedLinks!.replace('repo_releases ', '');
}
-async function fetchFromApi(nameWithOwner: string): Promise<number> {
+export async function getReleases(): Promise<[0] | [number, 'Tags' | 'Releases']> {
+ const repo = getRepo()!.nameWithOwner;
+ return releasesCount.get(repo);
+}
+
+async function fetchCounts(nameWithOwner: string): Promise<[0] | [number, 'Tags' | 'Releases'] > {
const [owner, name] = nameWithOwner.split('/');
- const {repository} = await api.v4(GetReleasesCount, {
+ const {repository: {releases, tags}} = await api.v4(GetReleasesCount, {
variables: {name, owner},
});
- return repository.releases.totalCount;
+ if (releases.totalCount) {
+ return [releases.totalCount, 'Releases'];
+ }
+
+ if (tags.totalCount) {
+ return [tags.totalCount, 'Tags'];
+ }
+
+ return [0];
}
-// Release count can be not found in DOM if:
-// - It is disabled by repository owner on the home page (release DOM element won't be there)
-// - It only contains pre-releases (count badge won't be shown)
-// For this reason, if we can't find a count from the DOM, we ask the API instead (see #6298)
export const releasesCount = new CachedFunction('releases-count', {
- updater: fetchFromApi,
+ updater: fetchCounts,
+ shouldRevalidate: cachedValue => typeof cachedValue === 'number',
maxAge: {hours: 1},
staleWhileRevalidate: {days: 3},
cacheKey: cacheByRepo,
});
async function addReleasesTab(repoNavigationBar: HTMLElement): Promise<false | void> {
- const repo = getRepo()!.nameWithOwner;
- const count = await releasesCount.get(repo);
-
- if (count === 0) {
+ const [count, type] = await getReleases();
+ if (!type) {
return false;
}
@@ -53,7 +61,7 @@ async function addReleasesTab(repoNavigationBar: HTMLElement): Promise<false | v
repoNavigationBar.append(
<li className="d-flex">
<a
- href={buildRepoURL('releases')}
+ href={buildRepoURL(type.toLowerCase())}
className="js-selected-navigation-item UnderlineNav-item hx_underlinenav-item no-wrap js-responsive-underlinenav-item rgh-releases-tab"
data-hotkey="g r"
data-selected-links="repo_releases"
@@ -61,8 +69,8 @@ async function addReleasesTab(repoNavigationBar: HTMLElement): Promise<false | v
data-turbo-frame="repo-content-turbo-frame" /* Required for `data-selected-links` to work */
>
<TagIcon className="UnderlineNav-octicon d-none d-sm-inline"/>
- <span data-content="Releases">Releases</span>
- {count && <span className="Counter" title={count > 999 ? String(count) : ''}>{abbreviateNumber(count)}</span>}
+ <span data-content={type}>{type}</span>
+ <span className="Counter" title={count > 999 ? String(count) : ''}>{abbreviateNumber(count)}</span>
</a>
</li>,
);
@@ -71,10 +79,9 @@ async function addReleasesTab(repoNavigationBar: HTMLElement): Promise<false | v
}
async function addReleasesDropdownItem(dropdownMenu: HTMLElement): Promise<false | void> {
- const repo = getRepo()!.nameWithOwner;
- const count = await releasesCount.get(repo);
+ const [, type] = await getReleases();
- if (count === 0) {
+ if (!type) {
$('.dropdown-divider', dropdownMenu)?.remove();
return false;
}
@@ -82,7 +89,7 @@ async function addReleasesDropdownItem(dropdownMenu: HTMLElement): Promise<false
appendBefore(
dropdownMenu,
'.dropdown-divider', // Won't exist if `more-dropdown` is disabled
- createDropdownItem('Releases', buildRepoURL('releases'), {
+ createDropdownItem(type, buildRepoURL(type.toLowerCase()), {
'data-menu-item': 'rgh-releases-item',
}),
);
@@ -110,6 +117,7 @@ void features.add(import.meta.url, {
Test URLs:
-https://github.com/refined-github/refined-github
+Releases: https://github.com/refined-github/refined-github
+Tags: https://github.com/python/cpython
*/