-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow_cmd.go
144 lines (142 loc) · 4.12 KB
/
workflow_cmd.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package cmd
import (
"github.com/j-martin/nub/core"
"github.com/j-martin/nub/integrations/atlassian"
"github.com/j-martin/nub/integrations/github"
"github.com/j-martin/nub/utils"
"github.com/urfave/cli"
"os"
)
func buildWorkflowCmds(cfg *core.Configuration, manifest *core.Manifest) []cli.Command {
transition := "t"
noOperation := "noop"
compare := "compare-only"
unstash := "unstash"
unstashDesc := "Unstash changes at the end of the update."
return []cli.Command{
buildJIRAOpenBoardCmd(cfg),
buildJIRAClaimIssueCmd(cfg),
buildJIRAOpenIssueCmd(cfg),
buildJIRAViewIssueCmd(cfg),
buildJIRACommentOnIssuesCmd(cfg),
buildJIRAListAssignedIssuesCmd(cfg),
{
Name: "new-branch",
Aliases: []string{"n", "new"},
Usage: "Checkout a new branch based on JIRA issues assigned to you.",
Action: func(c *cli.Context) error {
return atlassian.MustInitJIRA(cfg).CreateBranchFromAssignedIssue()
},
},
{
Name: "checkout-branch",
Aliases: []string{"b"},
Usage: "Checkout an existing branch.",
Action: func(c *cli.Context) error {
return core.InitGit().CheckoutBranch()
},
},
{
Name: "commit",
Aliases: []string{"c"},
Usage: "MESSAGE [OPTS]...",
Action: func(c *cli.Context) error {
message := ""
if len(c.Args()) > 0 {
message = c.Args().Get(0)
}
return core.InitGit().CommitWithIssueKey(cfg, message, c.Args().Tail())
},
},
{
Name: "pull-request",
Aliases: []string{"pr"},
Usage: "Creates a PR for the current branch.",
Flags: []cli.Flag{
cli.BoolFlag{Name: compare, Usage: "Open only the compare page (PR creation page)."},
cli.BoolFlag{Name: transition, Usage: "Transition the issue to review."},
},
Action: func(c *cli.Context) error {
if c.Bool(compare) {
err := core.MustInitGit("").Push(cfg)
if err != nil {
return err
}
return github.MustInitGitHub(cfg).OpenCompareBranchPage(manifest)
}
var title, body string
if len(c.Args()) > 0 {
title = c.Args().Get(0)
}
if len(c.Args()) > 1 {
body = c.Args().Get(1)
}
return MustInitWorkflow(cfg, manifest).CreatePR(title, body, c.Bool("transition"))
},
},
buildJIRATransitionIssueCmd(cfg),
{
Name: "log",
Aliases: []string{"l"},
Usage: "Show git log and open PR, JIRA ticket, etc.",
Action: func(c *cli.Context) error {
return MustInitWorkflow(cfg, manifest).Log()
},
},
{
Name: "mass",
Aliases: []string{"m"},
Usage: "Mass repo changes. EXPERIMENTAL",
Subcommands: []cli.Command{
{
Name: "start",
Usage: "Clean the repository, checkout master, pull and create new branch.",
Flags: []cli.Flag{
cli.BoolFlag{Name: unstash, Usage: unstashDesc},
},
Action: func(c *cli.Context) error {
if !utils.AskForConfirmation("You will lose existing changes.") {
os.Exit(1)
}
return MustInitWorkflow(cfg, manifest).MassStart(c.Bool(unstash))
},
},
{
Name: "diff",
Aliases: []string{"d"},
Usage: "Shows the diff of all repos.",
Action: func(c *cli.Context) error {
return MustInitWorkflow(cfg, manifest).MassDiff()
},
},
{
Name: "done",
Usage: "Commit changes and create PRs. To be used after running '... start' and you made your changes.",
Flags: []cli.Flag{
cli.BoolFlag{Name: noOperation, Usage: "Do not do any actions."},
},
Action: func(c *cli.Context) error {
if !utils.AskForConfirmation("You will create a PR for every changes made to the repo. Use `--noop` to check first. Continue?") {
os.Exit(1)
}
return MustInitWorkflow(cfg, manifest).MassDone(c.Bool(noOperation))
},
},
{
Name: "update",
Aliases: []string{"u"},
Usage: "Clean the repository, checkout master and pull.",
Flags: []cli.Flag{
cli.BoolFlag{Name: unstash, Usage: unstashDesc},
},
Action: func(c *cli.Context) error {
if !utils.AskForConfirmation("You will lose existing changes.") {
os.Exit(1)
}
return MustInitWorkflow(cfg, manifest).MassUpdate(c.Bool(unstash))
},
},
},
},
}
}