diff --git a/completers/gh_completer/cmd/action/pullrequest.go b/completers/gh_completer/cmd/action/pullrequest.go index 401f75e5a4..7058a9685a 100644 --- a/completers/gh_completer/cmd/action/pullrequest.go +++ b/completers/gh_completer/cmd/action/pullrequest.go @@ -155,3 +155,28 @@ func ActionPullRequestReviewers(cmd *cobra.Command, id string) carapace.Action { return carapace.ActionValues(vals...) }) } + +type commit struct { + Sha string + Commit struct { + Message string + } +} + +func ActionPullRequestCommits(cmd *cobra.Command, id string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + repo, err := repoOverride(cmd) + if err != nil { + return carapace.ActionMessage(err.Error()) + } + + var queryResult []commit + return ApiV3Action(cmd, fmt.Sprintf(`repos/%v/%v/pulls/%v/commits`, repo.RepoOwner(), repo.RepoName(), id), &queryResult, func() carapace.Action { + vals := make([]string, 0) + for _, c := range queryResult { + vals = append(vals, c.Sha, c.Commit.Message) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/gh_completer/cmd/pr_merge.go b/completers/gh_completer/cmd/pr_merge.go index 682adb9bc4..6efd2d9d7f 100644 --- a/completers/gh_completer/cmd/pr_merge.go +++ b/completers/gh_completer/cmd/pr_merge.go @@ -31,6 +31,12 @@ func init() { carapace.Gen(pr_mergeCmd).FlagCompletion(carapace.ActionMap{ "body": action.ActionKeywordLinks(pr_mergeCmd), "body-file": carapace.ActionFiles(), + "match-head-commit": carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if len(c.Args) > 0 { + return action.ActionPullRequestCommits(pr_mergeCmd, c.Args[0]) + } + return carapace.ActionValues() + }), }) carapace.Gen(pr_mergeCmd).PositionalCompletion(