"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/pr/merge/merge.go" between
gh-cli-1.12.1.tar.gz and gh-cli-1.13.1.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

merge.go  (gh-cli-1.12.1):merge.go  (gh-cli-1.13.1)
skipping to change at line 159 skipping to change at line 159
cmd.Flags().BoolVar(&opts.AutoMergeEnable, "auto", false, "Automatically merge only after necessary requirements are met") cmd.Flags().BoolVar(&opts.AutoMergeEnable, "auto", false, "Automatically merge only after necessary requirements are met")
cmd.Flags().BoolVar(&opts.AutoMergeDisable, "disable-auto", false, "Disab le auto-merge for this pull request") cmd.Flags().BoolVar(&opts.AutoMergeDisable, "disable-auto", false, "Disab le auto-merge for this pull request")
return cmd return cmd
} }
func mergeRun(opts *MergeOptions) error { func mergeRun(opts *MergeOptions) error {
cs := opts.IO.ColorScheme() cs := opts.IO.ColorScheme()
findOptions := shared.FindOptions{ findOptions := shared.FindOptions{
Selector: opts.SelectorArg, Selector: opts.SelectorArg,
Fields: []string{"id", "number", "state", "title", "lastCommit" , "mergeable", "headRepositoryOwner", "headRefName"}, Fields: []string{"id", "number", "state", "title", "lastCommit" , "mergeStateStatus", "headRepositoryOwner", "headRefName"},
} }
pr, baseRepo, err := opts.Finder.Find(findOptions) pr, baseRepo, err := opts.Finder.Find(findOptions)
if err != nil { if err != nil {
return err return err
} }
isTerminal := opts.IO.IsStdoutTTY() isTerminal := opts.IO.IsStdoutTTY()
httpClient, err := opts.HttpClient() httpClient, err := opts.HttpClient()
if err != nil { if err != nil {
skipping to change at line 194 skipping to change at line 194
if opts.SelectorArg == "" && len(pr.Commits.Nodes) > 0 { if opts.SelectorArg == "" && len(pr.Commits.Nodes) > 0 {
if localBranchLastCommit, err := git.LastCommit(); err == nil { if localBranchLastCommit, err := git.LastCommit(); err == nil {
if localBranchLastCommit.Sha != pr.Commits.Nodes[len(pr.C ommits.Nodes)-1].Commit.OID { if localBranchLastCommit.Sha != pr.Commits.Nodes[len(pr.C ommits.Nodes)-1].Commit.OID {
fmt.Fprintf(opts.IO.ErrOut, fmt.Fprintf(opts.IO.ErrOut,
"%s Pull request #%d (%s) has diverged fr om local branch\n", cs.Yellow("!"), pr.Number, pr.Title) "%s Pull request #%d (%s) has diverged fr om local branch\n", cs.Yellow("!"), pr.Number, pr.Title)
} }
} }
} }
if pr.Mergeable == "CONFLICTING" { isPRAlreadyMerged := pr.State == "MERGED"
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d (%s) has conflic if blocked := blockedReason(pr.MergeStateStatus); !opts.AutoMergeEnable &
ts and isn't mergeable\n", cs.Red("!"), pr.Number, pr.Title) & !isPRAlreadyMerged && blocked != "" {
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d is not mergeable
: %s.\n", cs.FailureIcon(), pr.Number, blocked)
fmt.Fprintf(opts.IO.ErrOut, "To have the pull request merged afte
r all the requirements have been met, add the `--auto` flag.\n")
return cmdutil.SilentError return cmdutil.SilentError
} }
deleteBranch := opts.DeleteBranch deleteBranch := opts.DeleteBranch
crossRepoPR := pr.HeadRepositoryOwner.Login != baseRepo.RepoOwner() crossRepoPR := pr.HeadRepositoryOwner.Login != baseRepo.RepoOwner()
autoMerge := opts.AutoMergeEnable && !isImmediatelyMergeable(pr.MergeStat eStatus)
isPRAlreadyMerged := pr.State == "MERGED"
if !isPRAlreadyMerged { if !isPRAlreadyMerged {
payload := mergePayload{ payload := mergePayload{
repo: baseRepo, repo: baseRepo,
pullRequestID: pr.ID, pullRequestID: pr.ID,
method: opts.MergeMethod, method: opts.MergeMethod,
auto: opts.AutoMergeEnable, auto: autoMerge,
commitBody: opts.Body, commitBody: opts.Body,
setCommitBody: opts.BodySet, setCommitBody: opts.BodySet,
} }
if opts.InteractiveMode { if opts.InteractiveMode {
r, err := api.GitHubRepo(apiClient, baseRepo) r, err := api.GitHubRepo(apiClient, baseRepo)
if err != nil { if err != nil {
return err return err
} }
payload.method, err = mergeMethodSurvey(r) payload.method, err = mergeMethodSurvey(r)
skipping to change at line 297 skipping to change at line 299
Message: fmt.Sprintf("Pull request #%d was already merged . Delete the branch locally?", pr.Number), Message: fmt.Sprintf("Pull request #%d was already merged . Delete the branch locally?", pr.Number),
Default: false, Default: false,
}, &deleteBranch) }, &deleteBranch)
if err != nil { if err != nil {
return fmt.Errorf("could not prompt: %w", err) return fmt.Errorf("could not prompt: %w", err)
} }
} else if crossRepoPR { } else if crossRepoPR {
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d was already merg ed\n", cs.WarningIcon(), pr.Number) fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d was already merg ed\n", cs.WarningIcon(), pr.Number)
} }
if !deleteBranch || crossRepoPR || opts.AutoMergeEnable { if !deleteBranch || crossRepoPR || autoMerge {
return nil return nil
} }
branchSwitchString := "" branchSwitchString := ""
if opts.CanDeleteLocalBranch { if opts.CanDeleteLocalBranch {
currentBranch, err := opts.Branch() currentBranch, err := opts.Branch()
if err != nil { if err != nil {
return err return err
} }
skipping to change at line 454 skipping to change at line 456
} }
func (e *userEditor) Edit(filename, startingText string) (string, error) { func (e *userEditor) Edit(filename, startingText string) (string, error) {
editorCommand, err := cmdutil.DetermineEditor(e.config) editorCommand, err := cmdutil.DetermineEditor(e.config)
if err != nil { if err != nil {
return "", err return "", err
} }
return surveyext.Edit(editorCommand, filename, startingText, e.io.In, e.i o.Out, e.io.ErrOut, nil) return surveyext.Edit(editorCommand, filename, startingText, e.io.In, e.i o.Out, e.io.ErrOut, nil)
} }
// blockedReason translates various MergeStateStatus GraphQL values into human-r
eadable reason
func blockedReason(status string) string {
switch status {
case "BLOCKED":
return "the base branch policy prohibits the merge"
case "BEHIND":
return "the head branch is not up to date with the base branch"
case "DIRTY":
return "the merge commit cannot be cleanly created"
default:
return ""
}
}
func isImmediatelyMergeable(status string) bool {
switch status {
case "CLEAN", "HAS_HOOKS", "UNSTABLE":
return true
default:
return false
}
}
 End of changes. 7 change blocks. 
7 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)