Skip to content

Commit

Permalink
gh: emoji completion in body
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 21, 2023
1 parent e46d166 commit b786fed
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 15 deletions.
16 changes: 14 additions & 2 deletions completers/gh_completer/cmd/action/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,29 @@ import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/gh"
"github.com/rsteube/carapace-bin/pkg/styles"
"github.com/spf13/cobra"
)

func ActionKeywordLinks(cmd *cobra.Command) carapace.Action {
func ActionBody(cmd *cobra.Command) carapace.Action {
return carapace.ActionMultiParts(" ", func(c carapace.Context) carapace.Action {
if strings.HasPrefix(c.CallbackValue, "@") {
switch {
case strings.HasPrefix(c.CallbackValue, ":"):
return gh.ActionEmojis()

case strings.HasPrefix(c.CallbackValue, "@"):
c.CallbackValue = strings.TrimPrefix(c.CallbackValue, "@")
return ActionMentionableUsers(cmd).Invoke(c).Prefix("@").ToA()

default:
return ActionKeywordLinks(cmd)
}
})
}

func ActionKeywordLinks(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
keywordsOfficial := []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"}
keywordsCustom := []string{"causes", "caused-by", "closed_by", "fixed_by", "related", "resolved_by", "see"}

Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/issue_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
issueCmd.AddCommand(issue_closeCmd)

carapace.Gen(issue_closeCmd).FlagCompletion(carapace.ActionMap{
"comment": action.ActionKeywordLinks(issue_closeCmd),
"comment": action.ActionBody(issue_closeCmd),
"reason": carapace.ActionValues("completed", "not planned"),
})

Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
issueCmd.AddCommand(issue_commentCmd)

carapace.Gen(issue_commentCmd).FlagCompletion(carapace.ActionMap{
"body": action.ActionKeywordLinks(issue_commentCmd),
"body": action.ActionBody(issue_commentCmd),
"body-file": carapace.ActionFiles(),
})
carapace.Gen(issue_commentCmd).PositionalCompletion(
Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/issue_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {

carapace.Gen(issue_createCmd).FlagCompletion(carapace.ActionMap{
"assignee": action.ActionAssignableUsers(issue_createCmd).UniqueList(","),
"body": action.ActionKeywordLinks(issue_createCmd),
"body": action.ActionBody(issue_createCmd),
"body-file": carapace.ActionFiles(),
"label": action.ActionLabels(issue_createCmd).UniqueList(","),
"milestone": action.ActionMilestones(issue_createCmd),
Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/issue_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
"add-assignee": action.ActionAssignableUsers(issue_editCmd).UniqueList(","),
"add-label": action.ActionLabels(issue_editCmd).UniqueList(","),
"add-project": action.ActionProjects(issue_editCmd, action.ProjectOpts{Open: true}),
"body": action.ActionKeywordLinks(issue_editCmd),
"body": action.ActionBody(issue_editCmd),
"body-file": carapace.ActionFiles(),
"milestone": action.ActionMilestones(issue_editCmd),
"remove-assignee": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/issue_reopen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {
issueCmd.AddCommand(issue_reopenCmd)

carapace.Gen(issue_reopenCmd).FlagCompletion(carapace.ActionMap{
"comment": action.ActionKeywordLinks(issue_reopenCmd),
"comment": action.ActionBody(issue_reopenCmd),
})

carapace.Gen(issue_reopenCmd).PositionalCompletion(
Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/pr_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func init() {
prCmd.AddCommand(pr_closeCmd)

carapace.Gen(pr_closeCmd).FlagCompletion(carapace.ActionMap{
"comment": action.ActionKeywordLinks(pr_closeCmd),
"comment": action.ActionBody(pr_closeCmd),
})

carapace.Gen(pr_closeCmd).PositionalCompletion(
Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/pr_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
prCmd.AddCommand(pr_commentCmd)

carapace.Gen(pr_commentCmd).FlagCompletion(carapace.ActionMap{
"body": action.ActionKeywordLinks(pr_commentCmd),
"body": action.ActionBody(pr_commentCmd),
"body-file": carapace.ActionFiles(),
})

Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/pr_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {
carapace.Gen(pr_createCmd).FlagCompletion(carapace.ActionMap{
"assignee": action.ActionAssignableUsers(pr_createCmd).UniqueList(","),
"base": action.ActionBranches(pr_createCmd),
"body": action.ActionKeywordLinks(pr_createCmd),
"body": action.ActionBody(pr_createCmd),
"body-file": carapace.ActionFiles(),
"head": action.ActionBranches(pr_createCmd),
"label": action.ActionLabels(pr_createCmd).UniqueList(","),
Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/pr_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {
"add-project": action.ActionProjects(pr_editCmd, action.ProjectOpts{Open: true}),
"add-reviewer": action.ActionAssignableUsers(pr_editCmd).UniqueList(","),
"base": action.ActionBranches(pr_editCmd),
"body": action.ActionKeywordLinks(pr_editCmd),
"body": action.ActionBody(pr_editCmd),
"body-file": carapace.ActionFiles(),
"milestone": action.ActionMilestones(pr_editCmd),
"remove-assignee": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/pr_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {

// TODO match-head-commit
carapace.Gen(pr_mergeCmd).FlagCompletion(carapace.ActionMap{
"body": action.ActionKeywordLinks(pr_mergeCmd),
"body": action.ActionBody(pr_mergeCmd),
"body-file": carapace.ActionFiles(),
"match-head-commit": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Args) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/pr_reopen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {
prCmd.AddCommand(pr_reopenCmd)

carapace.Gen(pr_reopenCmd).FlagCompletion(carapace.ActionMap{
"comment": action.ActionKeywordLinks(pr_reopenCmd),
"comment": action.ActionBody(pr_reopenCmd),
})

carapace.Gen(pr_reopenCmd).PositionalCompletion(
Expand Down
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/pr_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func init() {
prCmd.AddCommand(pr_reviewCmd)

carapace.Gen(pr_reviewCmd).FlagCompletion(carapace.ActionMap{
"body": action.ActionKeywordLinks(pr_reviewCmd),
"body": action.ActionBody(pr_reviewCmd),
"body-file": carapace.ActionFiles(),
"comment": action.ActionKeywordLinks(pr_reviewCmd),
"comment": action.ActionBody(pr_reviewCmd),
})

carapace.Gen(pr_reviewCmd).PositionalCompletion(
Expand Down

0 comments on commit b786fed

Please sign in to comment.