This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
/
issue_update.go
100 lines (85 loc) · 3.04 KB
/
issue_update.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package update
import (
"errors"
"fmt"
"github.com/profclems/glab/commands/cmdutils"
"github.com/profclems/glab/commands/issue/issueutils"
"github.com/profclems/glab/internal/utils"
"github.com/profclems/glab/pkg/api"
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
"github.com/xanzy/go-gitlab"
)
func NewCmdUpdate(f *cmdutils.Factory) *cobra.Command {
var issueUpdateCmd = &cobra.Command{
Use: "update <id>",
Short: `Update issue`,
Long: ``,
Example: heredoc.Doc(`
$ glab issue update 42 --label ui,ux
$ glab issue update 42 --unlabel working
`),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var err error
out := f.IO.StdOut
if cmd.Flags().Changed("lock-discussion") && cmd.Flags().Changed("unlock-discussion") {
return &cmdutils.FlagError{Err: errors.New("--lock-discussion and --unlock-discussion can't be used together")}
}
if cmd.Flags().Changed("confidential") && cmd.Flags().Changed("public") {
return &cmdutils.FlagError{Err: errors.New("--public and --confidential can't be used together")}
}
apiClient, err := f.HttpClient()
if err != nil {
return err
}
repo, err := f.BaseRepo()
if err != nil {
return err
}
issueID := utils.StringToInt(args[0])
l := &gitlab.UpdateIssueOptions{}
if m, _ := cmd.Flags().GetString("title"); m != "" {
l.Title = gitlab.String(m)
}
if m, _ := cmd.Flags().GetBool("lock-discussion"); m {
l.DiscussionLocked = gitlab.Bool(m)
}
if m, _ := cmd.Flags().GetBool("unlock-discussion"); m {
l.DiscussionLocked = gitlab.Bool(false)
}
if m, _ := cmd.Flags().GetString("description"); m != "" {
l.Description = gitlab.String(m)
}
if m, _ := cmd.Flags().GetStringArray("label"); len(m) != 0 {
l.AddLabels = gitlab.Labels(m)
}
if m, _ := cmd.Flags().GetStringArray("unlabel"); len(m) != 0 {
l.RemoveLabels = gitlab.Labels(m)
}
if m, _ := cmd.Flags().GetBool("public"); m {
l.Confidential = gitlab.Bool(false)
}
if m, _ := cmd.Flags().GetBool("confidential"); m {
l.Confidential = gitlab.Bool(true)
}
fmt.Fprintf(out, "- Updating issue #%d\n", issueID)
issue, err := api.UpdateIssue(apiClient, repo.FullName(), issueID, l)
if err != nil {
return err
}
fmt.Fprintln(out, utils.GreenCheck(), "Updated")
fmt.Fprintln(out, issueutils.DisplayIssue(issue))
return nil
},
}
issueUpdateCmd.Flags().StringP("title", "t", "", "Title of issue")
issueUpdateCmd.Flags().BoolP("lock-discussion", "", false, "Lock discussion on issue")
issueUpdateCmd.Flags().BoolP("unlock-discussion", "", false, "Unlock discussion on issue")
issueUpdateCmd.Flags().StringP("description", "d", "", "Issue description")
issueUpdateCmd.Flags().StringArrayP("label", "l", []string{}, "add labels")
issueUpdateCmd.Flags().StringArrayP("unlabel", "u", []string{}, "remove labels")
issueUpdateCmd.Flags().BoolP("public", "p", false, "Make issue public")
issueUpdateCmd.Flags().BoolP("confidential", "c", false, "Make issue confidential")
return issueUpdateCmd
}