Skip to content

Fix detecting PR status when passing branch as arg#3351

Merged
vilmibm merged 4 commits intocli:trunkfrom
cristiand391:fix-pr-reopen
Apr 20, 2021
Merged

Fix detecting PR status when passing branch as arg#3351
vilmibm merged 4 commits intocli:trunkfrom
cristiand391:fix-pr-reopen

Conversation

@cristiand391
Copy link
Contributor

@cristiand391 cristiand391 commented Apr 3, 2021

Fixes #3350

PullRequestForBranch wasn't fetching the closed field thus making gh pr reopen <branch> detect a closed PR as already open (pr.Closed zero value = false).

Edit:
This PR makes gh rely only on the state field to detect the current PR status (either CLOSED, MERGED or OPEN) (thanks Mislav).

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!

If you don't mind, I'd like to take an approach that avoids the ambiguity of "closed".

number
title
state
closed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good, but since the concept of "closed" is ambiguous for pull requests, and we're already fetching the state field, I would say let's go a few extra steps and rely just on the state field and avoid fetching the closed property altogether.

The two non-open states of Pull Requests are "closed" and "merged". Unless explicitly clarified, it can be ambiguous whether "closed" includes "merged" or not. For instance, pr.State == "CLOSED" does not include the "merged" state.

To avoid this ambiguity in our Go code, let's quit querying the closed field and change all pr.Closed checks (3 that I count right now) to actually reflect what they are checking for: the not-open state !pr.IsOpen(). That would involve adding an extra IsOpen() method to PullRequest, but I think it will be worth it. The benefit is that we can fetch one fewer field in GraphQL. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely agree that it's a clearer and more efficient approach, thanks!

Just for reference, per the GraphQL API docs, CLOSED means that a PR was closed without being merged.

@cristiand391 cristiand391 requested a review from mislav April 8, 2021 03:35
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you 🌟

@vilmibm vilmibm merged commit d098964 into cli:trunk Apr 20, 2021
@cristiand391 cristiand391 deleted the fix-pr-reopen branch April 20, 2021 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pr reopen fails when passing a branch as arg

3 participants