Skip to content

Commit cf2b19f

Browse files
authored
Merge pull request #1646 from rsteube/tea-pullrequest
tea: complete pull requests
2 parents dc34686 + 8669664 commit cf2b19f

File tree

12 files changed

+138
-11
lines changed

12 files changed

+138
-11
lines changed

completers/tea_completer/cmd/action/action.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ func ActionIssues(cmd *cobra.Command, open bool) carapace.Action {
2424
})
2525
}
2626

27+
func ActionPullrequests(cmd *cobra.Command, open bool) carapace.Action {
28+
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
29+
opts := tea.PullrequestOpts{}
30+
if f := cmd.Flag("login"); f != nil {
31+
opts.Login = f.Value.String()
32+
}
33+
if f := cmd.Flag("remote"); f != nil {
34+
opts.Remote = f.Value.String()
35+
}
36+
if f := cmd.Flag("repo"); f != nil {
37+
opts.Repo = f.Value.String()
38+
}
39+
opts.Open = open
40+
opts.Closed = !open
41+
return tea.ActionPullrequests(opts)
42+
})
43+
}
44+
2745
func ActionLabels(cmd *cobra.Command) carapace.Action {
2846
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
2947
opts := tea.RepoOpts{}

completers/tea_completer/cmd/pulls_approve.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/tea_completer/cmd/action"
56
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
67
"github.com/rsteube/carapace-bin/pkg/actions/tools/tea"
78
"github.com/spf13/cobra"
@@ -28,4 +29,8 @@ func init() {
2829
"output": tea.ActionOutputFormats(),
2930
"remote": git.ActionRemotes(),
3031
})
32+
33+
carapace.Gen(pulls_approveCmd).PositionalCompletion(
34+
action.ActionPullrequests(pulls_approveCmd, true),
35+
)
3136
}

completers/tea_completer/cmd/pulls_checkout.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/tea_completer/cmd/action"
56
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
67
"github.com/rsteube/carapace-bin/pkg/actions/tools/tea"
78
"github.com/spf13/cobra"
@@ -29,4 +30,8 @@ func init() {
2930
"output": tea.ActionOutputFormats(),
3031
"remote": git.ActionRemotes(),
3132
})
33+
34+
carapace.Gen(pulls_checkoutCmd).PositionalCompletion(
35+
action.ActionPullrequests(pulls_checkoutCmd, true),
36+
)
3237
}

completers/tea_completer/cmd/pulls_clean.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/tea_completer/cmd/action"
56
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
67
"github.com/rsteube/carapace-bin/pkg/actions/tools/tea"
78
"github.com/spf13/cobra"
@@ -28,4 +29,8 @@ func init() {
2829
"output": tea.ActionOutputFormats(),
2930
"remote": git.ActionRemotes(),
3031
})
32+
33+
carapace.Gen(pulls_cleanCmd).PositionalCompletion(
34+
action.ActionPullrequests(pulls_cleanCmd, false),
35+
)
3136
}

completers/tea_completer/cmd/pulls_close.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/tea_completer/cmd/action"
56
"github.com/rsteube/carapace-bin/pkg/actions/tools/tea"
67
"github.com/spf13/cobra"
78
)
@@ -25,4 +26,8 @@ func init() {
2526
carapace.Gen(pulls_closeCmd).FlagCompletion(carapace.ActionMap{
2627
"output": tea.ActionOutputFormats(),
2728
})
29+
30+
carapace.Gen(pulls_closeCmd).PositionalCompletion(
31+
action.ActionPullrequests(pulls_closeCmd, true),
32+
)
2833
}

completers/tea_completer/cmd/pulls_merge.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/tea_completer/cmd/action"
56
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
67
"github.com/rsteube/carapace-bin/pkg/actions/tools/tea"
78
"github.com/spf13/cobra"
@@ -32,4 +33,8 @@ func init() {
3233
"remote": git.ActionRemotes(),
3334
"style": carapace.ActionValues("merge", "rebase", "squash", "rebase-merge"),
3435
})
36+
37+
carapace.Gen(pulls_mergeCmd).PositionalCompletion(
38+
action.ActionPullrequests(pulls_mergeCmd, true),
39+
)
3540
}

completers/tea_completer/cmd/pulls_reject.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/tea_completer/cmd/action"
56
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
67
"github.com/rsteube/carapace-bin/pkg/actions/tools/tea"
78
"github.com/spf13/cobra"
@@ -27,4 +28,8 @@ func init() {
2728
"output": tea.ActionOutputFormats(),
2829
"remote": git.ActionRemotes(),
2930
})
31+
32+
carapace.Gen(pulls_rejectCmd).PositionalCompletion(
33+
action.ActionPullrequests(pulls_rejectCmd, true),
34+
)
3035
}

completers/tea_completer/cmd/pulls_reopen.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/tea_completer/cmd/action"
56
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
67
"github.com/rsteube/carapace-bin/pkg/actions/tools/tea"
78
"github.com/spf13/cobra"
@@ -28,4 +29,8 @@ func init() {
2829
"output": tea.ActionOutputFormats(),
2930
"remote": git.ActionRemotes(),
3031
})
32+
33+
carapace.Gen(pulls_reopenCmd).PositionalCompletion(
34+
action.ActionPullrequests(pulls_reopenCmd, false),
35+
)
3136
}

completers/tea_completer/cmd/pulls_review.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace-bin/completers/tea_completer/cmd/action"
56
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
67
"github.com/rsteube/carapace-bin/pkg/actions/tools/tea"
78
"github.com/spf13/cobra"
@@ -27,4 +28,8 @@ func init() {
2728
"output": tea.ActionOutputFormats(),
2829
"remote": git.ActionRemotes(),
2930
})
31+
32+
carapace.Gen(pulls_reviewCmd).PositionalCompletion(
33+
action.ActionPullrequests(pulls_reviewCmd, true),
34+
)
3035
}

pkg/actions/tools/tea/issue.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"strconv"
55

66
"github.com/rsteube/carapace"
7-
"github.com/rsteube/carapace/pkg/style"
7+
"github.com/rsteube/carapace-bin/pkg/styles"
88
)
99

1010
// ActionIssueFields completes issue fields
@@ -64,15 +64,7 @@ func ActionIssues(opts IssueOpts) carapace.Action {
6464
return actionYamlQuery(repoOpts, &issues, args...)(func() carapace.Action {
6565
vals := make([]string, 0)
6666
for _, issue := range issues {
67-
s := ""
68-
switch issue.State {
69-
case "open":
70-
s = style.Green
71-
case "closed":
72-
s = style.Red
73-
}
74-
75-
vals = append(vals, strconv.Itoa(issue.Index), issue.Title, s)
67+
vals = append(vals, strconv.Itoa(issue.Index), issue.Title, styles.Tea.ForState(issue.State, c))
7668
}
7769
return carapace.ActionStyledValuesDescribed(vals...)
7870
})

0 commit comments

Comments
 (0)