This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
issue_list.go
63 lines (57 loc) · 1.67 KB
/
issue_list.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
54
55
56
57
58
59
60
61
62
63
package commands
import (
"github.com/spf13/cobra"
"github.com/xanzy/go-gitlab"
"glab/internal/git"
)
var issueListCmd = &cobra.Command{
Use: "list [flags]",
Short: `List project issues`,
Long: ``,
Aliases: []string{"ls"},
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var state string
if lb, _ := cmd.Flags().GetBool("all"); lb {
state = "all"
} else if lb, _ := cmd.Flags().GetBool("closed"); lb {
state = "closed"
} else {
state = "opened"
}
l := &gitlab.ListProjectIssuesOptions{
State: gitlab.String(state),
}
if lb, _ := cmd.Flags().GetString("label"); lb != "" {
label := gitlab.Labels{
lb,
}
l.Labels = label
}
if lb, _ := cmd.Flags().GetString("milestone"); lb != "" {
l.Milestone = gitlab.String(lb)
}
if lb, _ := cmd.Flags().GetBool("confidential"); lb {
l.Confidential = gitlab.Bool(lb)
}
gitlabClient, repo := git.InitGitlabClient()
if r, _ := cmd.Flags().GetString("repo"); r != "" {
repo = r
}
issues, _, err := gitlabClient.Issues.ListProjectIssues(repo, l)
if err != nil {
return err
}
displayAllIssues(issues)
return nil
},
}
func init() {
issueListCmd.Flags().StringP("label", "l", "", "Filter issue by label <name>")
issueListCmd.Flags().StringP("milestone", "", "", "Filter issue by milestone <id>")
issueListCmd.Flags().BoolP("all", "a", false, "Get all issues")
issueListCmd.Flags().BoolP("closed", "c", false, "Get only closed issues")
issueListCmd.Flags().BoolP("opened", "o", false, "Get only opened issues")
issueListCmd.Flags().BoolP("confidential", "", false, "Filter by confidential issues")
issueCmd.AddCommand(issueListCmd)
}