Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@rimazmk
Copy link
Contributor

@rimazmk rimazmk commented Aug 1, 2020

Summary

closes #1429

Details

Using the same approach as gh pr merge, this adds the option to delete a local and remote branch with gh pr close as follows:

gh pr close 2 --delete-branch=true
or
gh pr close 2 -d

by default, the delete-branch flag is set to false.

@tierninho
Copy link
Contributor

tierninho commented Aug 5, 2020

@rimazk123 Many thanks for your contribution! I was using this functionality and noticed a few things:

  • gh pr close 11 --delete-branch results in the branch being deleted. Was this the intention if the user did not include the true or false flag? I would imagine it should be the same as using -d but just wanted to check as the Help menu says:

    To delete the branch, use '--delete-branch=true'.
    -d, --delete-branch   Delete the local and remote branch after close
    
  • Secondly, the protected branches are not recognized. For instance if I run gh pr close 11 -d and the branch is marked as protected (and cannot be deleted), the result says otherwise:

    ✔ Closed pull request #11 (sdfsdf)
    ✔ Deleted branch tierninho-patch-11
    

@rimazmk
Copy link
Contributor Author

rimazmk commented Aug 5, 2020

@tierninho

  • That was the intention, I can go ahead and update the help menu to reflect that.

  • I just copied the logic from prMerge on deleting the branch. I can take a deeper look but I'd imagine if that issue is happening here, gh pr merge 11 would have a similar issue.

@tierninho
Copy link
Contributor

Oops, sorry, I forgot to add "not" in my message. It should read "Secondly, the protected branches are not recognized."

@rimazmk
Copy link
Contributor Author

rimazmk commented Aug 5, 2020

Oops, sorry, I forgot to add "not" in my message. It should read "Secondly, the protected branches are not recognized."

Yeah I figured as much. Is there anything under api that checks if a branch is protected? That would be pretty useful here.

@tierninho
Copy link
Contributor

Is there anything under api that checks if a branch is protected?

I suspect there may not be anything as this issue remains open probably for the same reason. I will wait for one of the devs to confirm though.

Thanks for checking!

@rimazmk
Copy link
Contributor Author

rimazmk commented Aug 6, 2020

I noticed this condition when checking to log an error when deleting a branch:

if err != nil && (!errors.As(err, &httpErr) || httpErr.StatusCode != 422) {
	err = fmt.Errorf("failed to delete remote branch %s: %w", utils.Cyan(pr.HeadRefName), err)
	return err
}	

I'm not entirely sure what the condition after checking if err is nil is serving, but in this case since it deliberately seems to be ignoring 422s (the status code recieved after trying to delete a protected branch). I'm wondering if it's ok if I just remove this check? That way we get something like this when a user tries to delete a protected branch:

✔ Closed pull request #2 (Create README.md)
failed to delete remote branch test: HTTP 422: Cannot delete this protected branch (https://api.github.com/repos/rimazk123/boatymcbotface/git/refs/heads/test)

@vilmibm vilmibm self-requested a review August 19, 2020 22:08
Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

Thanks for getting this started, @rimazk123 . I went in to reconcile this with the new command structure and additionally added some test coverage; in the future please include tests with PRs ✨

@vilmibm vilmibm merged commit b9292f5 into cli:trunk Aug 20, 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.

gh pr close should have the option to delete branch

3 participants