Skip to content

Check if PR is already created#648

Merged
vilmibm merged 3 commits intocli:masterfrom
Tarasovych:check-if-pr-exists
Mar 18, 2020
Merged

Check if PR is already created#648
vilmibm merged 3 commits intocli:masterfrom
Tarasovych:check-if-pr-exists

Conversation

@Tarasovych
Copy link
Copy Markdown
Contributor

@Tarasovych Tarasovych commented Mar 13, 2020

Fixes #649

Copy link
Copy Markdown
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.

Thanks! This is a welcome addition, but it could use some tests please.

Also, when opening a PR for a bug that hasn't yet been filed as an issue, please open an issue first and then reference that issue number in your pull request body with a message such as Fixes #123. This helps us track bugs.

In this case, I will open an issue for this based on what your PR fixes.

return fmt.Errorf("must be on a branch named differently than %q", baseBranch)
}

_, err = api.PullRequestForBranch(client, headRepo, headBranch)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we query baseRepo here, since the "base" repository is the one where all the PRs are listed in?

Suggested change
_, err = api.PullRequestForBranch(client, headRepo, headBranch)
_, err = api.PullRequestForBranch(client, baseRepo, headBranch)

}

_, err = api.PullRequestForBranch(client, headRepo, headBranch)
if err != fmt.Errorf("no open pull requests found for branch %q", headBranch) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm worried that this check will fail if we ever tweak the text of the original error message.

To reliably detect the type of an error, I think that PullRequestForBranch() should return a special type for the "not found" case, perhaps one named ErrNotFound. Then we could do this:

Suggested change
if err != fmt.Errorf("no open pull requests found for branch %q", headBranch) {
if !errors.Is(err, api.ErrNotFound) {

How does this sound?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think, we can reuse api.NotFoundError here


_, err = api.PullRequestForBranch(client, headRepo, headBranch)
if err != fmt.Errorf("no open pull requests found for branch %q", headBranch) {
return fmt.Errorf("pull request for branch %q already exists", headBranch)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we perhaps print the URL to the existing pull request in this error message or at least instruct the viewer that they can open the existing PR with gh pr view?

@vilmibm vilmibm merged commit 23dfeff into cli:master Mar 18, 2020
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 create shoud fail faster if a PR already exists

3 participants