/
pr.go
47 lines (41 loc) · 1011 Bytes
/
pr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cmd
import (
"github.com/chriswalz/complete/v3"
"strconv"
"strings"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
// prCmd represents the pr command
var prCmd = &cobra.Command{
Use: "pr",
Short: "Check out a pull request from Github (requires GH CLI)",
Long: `bit pr
bit pr`,
Run: func(cmd *cobra.Command, args []string) {
suggestionTree := &complete.CompTree{
Sub: map[string]*complete.CompTree{
"pr": {
Desc: "Check out a pull request from Github (requires GH CLI)",
Dynamic: lazyLoad(GitHubPRSuggestions("")),
},
},
}
runPr(suggestionTree)
},
Args: cobra.NoArgs,
}
func init() {
BitCmd.AddCommand(prCmd)
}
func runPr(suggestionMap *complete.CompTree) {
branchName := SuggestionPrompt("> bit pr ", specificCommandCompleter("pr", suggestionMap))
split := strings.Split(branchName, "#")
prNumber, err := strconv.Atoi(split[len(split)-1])
if err != nil {
log.Debug().Err(err).Send()
return
}
checkoutPullRequest(prNumber)
return
}