-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Allow gh pr view <closed_pr_branch_name> to view closed PRs
#2276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
gh pr view to view closed PRsgh pr view <closed_pr_branch_name> to view closed PRs
|
Thanks for contributing! I think this is a good start but the solution runs into some issues with other uses of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find! Thanks for taking this on π
api/queries_pr.go
Outdated
| query PullRequestForBranch($owner: String!, $repo: String!, $headRefName: String!) { | ||
| repository(owner: $owner, name: $repo) { | ||
| pullRequests(headRefName: $headRefName, states: OPEN, first: 30) { | ||
| pullRequests(headRefName: $headRefName, first: 30) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes an immediate problem, but causes another one.
PullRequestForBranch is called in two places:
- find the PR for a branch, e.g. in
pr view; - check if there are open PRs for a branch during
pr create.
This change would break the feature described in (2).
I think the solution should be to have PullRequestForBranch accept an argument that dictates whether we're searching through open PRs or all PRs regardless of state. Also, when searching over all PRs, precedence should still be given to an open PR if one exists, even if a closed PR for the same branch exists and is chronologically newer.
api/queries_pr.go
Outdated
| return client.REST(repo.RepoHost(), "DELETE", path, nil, nil) | ||
| } | ||
|
|
||
| // sortPRsByPrecedence in the following order: OPEN, MERGED, CLOSED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is a neater way of doing this (for example in the GraphQL query) then I am all ears! π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our GraphQL API doesn't allow sorting by state, so doing it in memory like this is fine!
|
@samcoe / @mislav - thank you both for the swift & helpful review π I have attempted to address both of your comments in the subsequent commits. Couple of things to point out:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! Minor notes:
api/queries_pr.go
Outdated
| return client.REST(repo.RepoHost(), "DELETE", path, nil, nil) | ||
| } | ||
|
|
||
| // sortPRsByPrecedence in the following order: OPEN, MERGED, CLOSED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our GraphQL API doesn't allow sorting by state, so doing it in memory like this is fine!
api/queries_pr.go
Outdated
| if (prs[b].State == "MERGED" && prs[a].State =="CLOSED") || | ||
| (prs[b].State == "OPEN" && prs[a].State =="CLOSED") || | ||
| (prs[b].State == "OPEN" && prs[a].State == "MERGED") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're only sorting by open-first (other states do not matter), I think you can get away with simply:
return prs[a].State == "OPEN"In this case, you might want to use SliceStable instead of Slice to preserve the original order of records that rank the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense :) Updated this function, test & comment to reflect this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the requested changes. This looks good to me, had just one small naming comment π
api/queries_pr.go
Outdated
| } | ||
|
|
||
| // sortPRsByPrecedence ensures that OPEN PRs precede non-open states (MERGED, CLOSED) | ||
| func sortPRsByPrecedence(prs []PullRequest) []PullRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit is that can we name this sortPullRequestsByState?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course π
This method doesn't necessarily search through open pull requests.
1c24307 to
fb621d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work! <3
|
Thanks to you both for the swift & helpful reviews π |
Hello π This is my first PR being raised here, so please let me know if I'm getting something wrong π
Currently, you can't view closed PRs by branch. This is due to a
states: OPENfilter in the graphql query.However, viewing the closed PR by number does work as the query does not have this condition here.
This PR removes this condition from the
PullRequestForBranchfunction.Before this change
After this change
This closes #2270