forked from zaquestion/lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issueList.go
53 lines (47 loc) · 1.08 KB
/
issueList.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
48
49
50
51
52
53
package cmd
import (
"fmt"
"log"
"github.com/spf13/cobra"
"github.com/xanzy/go-gitlab"
lab "github.com/zaquestion/lab/internal/gitlab"
)
var (
issueLabels []string
issueState string
)
var issueListCmd = &cobra.Command{
Use: "list [remote] [page]",
Aliases: []string{"ls"},
Short: "List issues",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
rn, page, err := parseArgs(args)
if err != nil {
log.Fatal(err)
}
issues, err := lab.IssueList(rn, &gitlab.ListProjectIssuesOptions{
ListOptions: gitlab.ListOptions{
Page: int(page),
PerPage: 10,
},
Labels: issueLabels,
State: &issueState,
OrderBy: gitlab.String("updated_at"),
})
if err != nil {
log.Fatal(err)
}
for _, issue := range issues {
fmt.Printf("#%d %s\n", issue.IID, issue.Title)
}
},
}
func init() {
issueListCmd.Flags().StringSliceVarP(
&issueLabels, "label", "l", []string{}, "filter issues by label")
issueListCmd.Flags().StringVarP(
&issueState, "state", "s", "opened",
"filter issues by state (opened/closed)")
issueCmd.AddCommand(issueListCmd)
}