Browse Source

Stops filtering out root prs on forks

main
Eric Amodio 3 years ago
parent
commit
e8ac453a51
1 changed files with 9 additions and 4 deletions
  1. +9
    -4
      src/github/github.ts

+ 9
- 4
src/github/github.ts View File

@ -275,6 +275,7 @@ export class GitHubApi {
closedAt
mergedAt
repository {
isFork
owner {
login
}
@ -309,15 +310,16 @@ export class GitHubApi {
...options,
});
// Filter to ensure we only get the owner we expect, as GitHub seems to sometimes return PRs for forks
// If the pr is not from a fork, keep it e.g. show root pr's on forks, otherwise, ensure the repo owners match
const prs = rsp?.repository?.refs.nodes[0]?.associatedPullRequests?.nodes?.filter(
pr => pr.repository.owner.login === owner,
pr => !pr.repository.isFork || pr.repository.owner.login === owner,
);
if (prs == null || prs.length === 0) return undefined;
if (prs.length > 1) {
prs.sort(
(a, b) =>
(a.repository.owner.login === owner ? -1 : 1) - (b.repository.owner.login === owner ? -1 : 1) ||
(a.state === 'OPEN' ? -1 : 1) - (b.state === 'OPEN' ? -1 : 1) ||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),
);
@ -374,6 +376,7 @@ export class GitHubApi {
closedAt
mergedAt
repository {
isFork
owner {
login
}
@ -404,15 +407,16 @@ export class GitHubApi {
...options,
});
// Filter to ensure we only get the owner we expect, as GitHub seems to sometimes return PRs for forks
// If the pr is not from a fork, keep it e.g. show root pr's on forks, otherwise, ensure the repo owners match
const prs = rsp?.repository?.object?.associatedPullRequests?.nodes?.filter(
pr => pr.repository.owner.login === owner,
pr => !pr.repository.isFork || pr.repository.owner.login === owner,
);
if (prs == null || prs.length === 0) return undefined;
if (prs.length > 1) {
prs.sort(
(a, b) =>
(a.repository.owner.login === owner ? -1 : 1) - (b.repository.owner.login === owner ? -1 : 1) ||
(a.state === 'OPEN' ? -1 : 1) - (b.state === 'OPEN' ? -1 : 1) ||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),
);
@ -456,6 +460,7 @@ interface GitHubPullRequest {
closedAt: string | null;
mergedAt: string | null;
repository: {
isFork: boolean;
owner: {
login: string;
};

Loading…
Cancel
Save