Merge pull request #2798 from cli/pr-merge-crossrepo

Handle case when a cross-repo PR was already merged
This commit is contained in:
Mislav Marohnić 2021-01-21 17:36:00 +01:00 committed by GitHub
commit ad62d6a471
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View file

@ -124,8 +124,8 @@ func mergeRun(opts *MergeOptions) error {
}
if pr.Mergeable == "CONFLICTING" {
err := fmt.Errorf("%s Pull request #%d (%s) has conflicts and isn't mergeable ", cs.Red("!"), pr.Number, pr.Title)
return err
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d (%s) has conflicts and isn't mergeable\n", cs.Red("!"), pr.Number, pr.Title)
return cmdutil.SilentError
}
deleteBranch := opts.DeleteBranch
@ -162,7 +162,7 @@ func mergeRun(opts *MergeOptions) error {
}
fmt.Fprintf(opts.IO.ErrOut, "%s %s pull request #%d (%s)\n", cs.Magenta("✔"), action, pr.Number, pr.Title)
}
} else if !opts.IsDeleteBranchIndicated && opts.InteractiveMode {
} else if !opts.IsDeleteBranchIndicated && opts.InteractiveMode && !crossRepoPR {
err := prompt.SurveyAskOne(&survey.Confirm{
Message: fmt.Sprintf("Pull request #%d was already merged. Delete the branch locally?", pr.Number),
Default: false,
@ -170,15 +170,17 @@ func mergeRun(opts *MergeOptions) error {
if err != nil {
return fmt.Errorf("could not prompt: %w", err)
}
} else if crossRepoPR {
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d was already merged\n", cs.WarningIcon(), pr.Number)
}
if !deleteBranch {
if !deleteBranch || crossRepoPR {
return nil
}
branchSwitchString := ""
if opts.CanDeleteLocalBranch && !crossRepoPR {
if opts.CanDeleteLocalBranch {
currentBranch, err := opts.Branch()
if err != nil {
return err
@ -210,7 +212,7 @@ func mergeRun(opts *MergeOptions) error {
}
}
if !isPRAlreadyMerged && !crossRepoPR {
if !isPRAlreadyMerged {
err = api.BranchDeleteRemote(apiClient, baseRepo, pr.HeadRefName)
var httpErr api.HTTPError
// The ref might have already been deleted by GitHub

View file

@ -551,7 +551,7 @@ func TestPrMerge_alreadyMerged_nonInteractive(t *testing.T) {
}
assert.Equal(t, "", output.String())
assert.Equal(t, "", output.Stderr())
assert.Equal(t, "! Pull request #4 was already merged\n", output.Stderr())
}
func TestPRMerge_interactive(t *testing.T) {