Skip to content

Commit

Permalink
Merge pull request #1210 from rsteube/gh-match-head-commit
Browse files Browse the repository at this point in the history
gh: pr merge - match-head-commit completion
  • Loading branch information
rsteube authored Jun 24, 2022
2 parents bbf2fa0 + aa26333 commit 1833fee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions completers/gh_completer/cmd/action/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
})
})
}
6 changes: 6 additions & 0 deletions completers/gh_completer/cmd/pr_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1833fee

Please sign in to comment.