diff options
-rw-r--r-- | package-lock.json | 6 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | source/features/show-open-prs-of-forks.tsx | 22 |
3 files changed, 17 insertions, 13 deletions
diff --git a/package-lock.json b/package-lock.json index 5562ed4b..566a4589 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7572,9 +7572,9 @@ } }, "github-url-detection": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/github-url-detection/-/github-url-detection-1.0.0.tgz", - "integrity": "sha512-xtbyN8FNQStN3kuW3wGRJvtBfRLeNVoMtwJfA7wy8d09zDauiXlcObSBEpGKWRdMIG+gF6Hs24OAL4KuUoAhCg==" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/github-url-detection/-/github-url-detection-1.1.2.tgz", + "integrity": "sha512-AQ8IXCiJfrRU9nHbeWLLVFkKE2S1OdOrXcfQT9yHxR+L3WPDk6LZEzO8trXV+3XEpkbw3xfw0UR/83ksQjWAHA==" }, "glob": { "version": "7.1.6", diff --git a/package.json b/package.json index 2ce17cd2..4dda991d 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "element-ready": "^4.1.1", "fit-textarea": "^2.0.0", "github-reserved-names": "^1.1.8", - "github-url-detection": "^1.0.0", + "github-url-detection": "^1.1.2", "image-promise": "^7.0.0", "indent-textarea": "^2.0.1", "linkify-issues": "2.0.0-nolookbehind", 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() |