diff options
Diffstat (limited to 'source/features/show-open-prs-of-forks.tsx')
-rw-r--r-- | source/features/show-open-prs-of-forks.tsx | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/source/features/show-open-prs-of-forks.tsx b/source/features/show-open-prs-of-forks.tsx index 0b2a91a7..93c04c2f 100644 --- a/source/features/show-open-prs-of-forks.tsx +++ b/source/features/show-open-prs-of-forks.tsx @@ -6,35 +6,39 @@ import * as pageDetect from 'github-url-detection'; import * as api from '../libs/api'; import features from '../libs/features'; -import {getForkedRepo, getUsername, pluralize} from '../libs/utils'; +import {getForkedRepo, getUsername, pluralize, getRepoURL} from '../libs/utils'; function getLinkCopy(count: number): string { return pluralize(count, 'one open pull request', '$$ open pull requests'); } const countPRs = cache.function(async (forkedRepo: string): Promise<[number, number?]> => { - // Grab the PR count and the first PR's URL - // This allows to link to the PR directly if only one is found const {search} = await api.v4(` search( - first: 1, + first: 100, type: ISSUE, query: "repo:${forkedRepo} is:pr is:open author:${getUsername()}" ) { - issueCount nodes { ... on PullRequest { number + headRepository { + nameWithOwner + } } } } `); - if (search.issueCount === 1) { - return [1, search.nodes[0].number]; + // Only show PRs originated from the current repo + const prs = search.nodes.filter((pr: AnyObject) => pr.headRepository.nameWithOwner.toLowerCase() === getRepoURL()); + + // If only one is found, pass the PR number so we can link to the PR directly + if (prs.length === 1) { + return [1, prs[0].number]; } - return [search.issueCount]; + return [prs.length]; }, { maxAge: 1 / 2, // Stale after 12 hours staleWhileRevalidate: 2, @@ -95,7 +99,7 @@ features.add({ init: initHeadHint }, { include: [ - pageDetect.isRepoSettings + pageDetect.isRepoMainSettings ], exclude: [ () => !pageDetect.isForkedRepo() |