-
Notifications
You must be signed in to change notification settings - Fork 7k
fix: #4263 show open prs only on default branch #4285
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
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.
Looks good! Do you think it will be possible to cover this behavior with a test scoped to findForBranch
?
pkg/cmd/pr/shared/finder.go
Outdated
@@ -314,7 +318,9 @@ func findForBranch(httpClient *http.Client, repo ghrepo.Interface, baseBranch, h | |||
|
|||
for _, pr := range prs { | |||
if pr.HeadLabel() == headBranch && (baseBranch == "" || pr.BaseRefName == baseBranch) { | |||
return &pr, nil | |||
if pr.State == "OPEN" || resp.Repository.DefaultBranchRef.Name != headBranch { |
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 condition looks good but could be merged with the if
condition that precedes it. Something like:
if pr.HeadLabel() == headBranch && (baseBranch == "" || pr.BaseRefName == baseBranch) && (pr.State == "OPEN" || resp.Repository.DefaultBranchRef.Name != headBranch) {
Feel free to split the condition into multiple lines if that looks better
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.
I am of 2 minds 😅. I can do it however you like.
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.
Well then just put it on 1-line if
condition and then we'll see. As long as it's not nested if
s 👍
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.
Done
I can't think of any way to do that, but I don't have much experience writing tests. If you have any ideas, please help me out. |
No worries. We'll try to add a test before this merges ✌️ |
I had a look at this fix and from the existing code coverage html report:
it seems just this line is not covered after : cli/pkg/cmd/pr/shared/finder.go Line 325 in 43b2785
so a test case that can get to there would effectively run through the new if condition.
I'd be willing to create a patch for |
I've created a commit andrewhsu@22d689f with the test. Feel free to cherry-pick or let me know where I should create a PR for this. The commit adds a test case to 2c2
< name: "no argument reads current branch",
---
> name: "current branch with merged pr",
23c23
< "state": "OPEN",
---
> "state": "MERGED",
29c29,32
< ]}
---
> ]},
> "defaultBranchRef":{
> "name": "blueberries"
> }
32,33c35
< wantPR: 13,
< wantRepo: "https://github.com/OWNER/REPO",
---
> wantErr: true, I found https://docs.github.com/en/graphql/overview/explorer helpful because this is my first time diving into GraphQL. Let me know if I've missed the pool. 🏊🏼♂️ |
To ensure only open PRs are shown on default branch when running `gh pr view`.
@andrewhsu Much appreciated! @AyushRawal Thank you for your patience 🙇 |
Fixes #4263