In my case, I have this dummy fork https://github.com/fregante/refined-github but all of PRs are directly on the source (https://github.com/sindresorhus/refined-github)

cc @loilo
Fair point. I'll take care of it. 馃檪
Oof. From what I can tell, GitHub has no search filter in place to limit results to a certain head repo.
This creates two problems:
I'm not sure how to handle this.
We could solve part of it by checking if the user has write access not only to the forked repo but also to the source repo. This should be solvable in one API request and could be cached for a long time.
What do you think @fregante?
Here: https://developer.github.com/v4/explorer/
We'd have to fetch _all_ your PR info, not just the first one, but it's not a lot of data.
query {
search(
first: 100,
type: ISSUE,
query: "repo:sindresorhus/refined-github is:pr is:open author:fregante"
) {
nodes {
... on PullRequest {
baseRepository {
nameWithOwner
}
number
}
}
}
}
```json
{
"data": {
"search": {
"nodes": [
{
"baseRepository": {
"nameWithOwner": "sindresorhus/refined-github"
},
"number": 2925
}
]
}
}
}
Then something like:
```js
const prs = search.nodes.filter(pr => pr.baseRepository.nameWithOwner === getRepoURL());
Yes, I had tried it out in the explorer, that's basically how I imagined it to be implemented. The "lot" of data was more in comparison with before, and it grows linearly with number of PRs.
I think this would be a reasonable implementation. In the (probably a bit absurd) case that somebody has > 100 open PRs, I'd bail out of counting.
How'd you deal with the link problem?
I don鈥檛 expect anyone to have a considerable amount of PRs open from a fork, they鈥檙e distant outliers.
As for the link, there鈥檚 no direct fix, but:
pr-branches feature will help them understand which is whichAlternatively, I think that the search accepts searching by number and logical operators. If that works, we could link to the search _Not possible_issue:2 OR issue:30 OR issue:40
Doesn't seem to be possible though. 馃檨
If some one wants to send a PR I tested https://github.com/sindresorhus/refined-github/issues/2934#issuecomment-604146813 and it looks fine to me. (I changed it to headRepository because I think that is correct)
https://github.com/yakov116/refined-github/commit/b698cf3f3e8f2f5d38e815f4eedbd2cb9aa47888
@@ -17,24 +17,28 @@ const countPRs = cache.function(async (forkedRepo: string): Promise<[number, num
// 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];
+ const prs = search.nodes.filter((pr: AnyObject) => pr.headRepository.nameWithOwner.toLowerCase() === getRepoURL());
+
+ if (prs.length === 1) {
+ return [1, prs[0].number];
}
- return [search.issueCount];
+ return [prs.length];
}, {
maxAge: 1 / 2, // Stale after 12 hours
staleWhileRevalidate: 2,