diff --git a/cmd/doctext/main.go b/cmd/doctext/main.go index 1045cce..36cebc9 100644 --- a/cmd/doctext/main.go +++ b/cmd/doctext/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "log" "net/http" "os" @@ -20,7 +21,7 @@ var ( TEAM_MEMBERS_DICT = os.Getenv("TEAM_MEMBERS_DICT") ) -func main() { +func docText(dryRun bool) { ctx := context.Background() var team Team @@ -89,10 +90,13 @@ func main() { if !ok { teamMember = team["team"] } - if err := notify(SLACK_HOOK, slackClient, issue, teamMember); err != nil { - gotErrors = true - log.Print(err) - return + log.Printf("INFO: Notifying %q about %d issues", assignee, len(issue)) + if ! dryRun { + if err := notify(SLACK_HOOK, slackClient, issue, teamMember); err != nil { + gotErrors = true + log.Print(err) + return + } } } @@ -103,6 +107,21 @@ func main() { } } +func main() { + var help = flag.Bool("help", false, "Show help") + var dryRun = false + flag.BoolVar(&dryRun, "dryRun", false, "Dry run (do not assign)") + + flag.Parse() + + if *help { + flag.Usage() + os.Exit(0) + } + + docText(dryRun) +} + func init() { ex_usage := false if SLACK_HOOK == "" { diff --git a/cmd/posttriage/main.go b/cmd/posttriage/main.go index 19e666a..76b42e8 100644 --- a/cmd/posttriage/main.go +++ b/cmd/posttriage/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "log" "os" "strings" @@ -15,7 +16,7 @@ const queryTriaged = query.ShiftStack + `AND labels = "Triaged"` var JIRA_TOKEN = os.Getenv("JIRA_TOKEN") -func main() { +func postTriage(dryRun bool) { ctx := context.Background() var jiraClient *jira.Client @@ -68,9 +69,11 @@ func main() { comment.WriteString("* " + reason + "\n") } - if err := untriage(ctx, jiraClient, issue, comment.String()); err != nil { - gotErrors = true - log.Printf("ERROR: Failed to untriage %q: %v", issue.Key, err) + if ! dryRun { + if err := untriage(ctx, jiraClient, issue, comment.String()); err != nil { + gotErrors = true + log.Printf("ERROR: Failed to untriage %q: %v", issue.Key, err) + } } } }(issue) @@ -84,6 +87,21 @@ func main() { } } +func main() { + var help = flag.Bool("help", false, "Show help") + var dryRun = false + flag.BoolVar(&dryRun, "dryRun", false, "Dry run (do not assign)") + + flag.Parse() + + if *help { + flag.Usage() + os.Exit(0) + } + + postTriage(dryRun) +} + func init() { if JIRA_TOKEN == "" { log.Print("FATAL: Required environment variable not found: JIRA_TOKEN") diff --git a/cmd/pretriage/main.go b/cmd/pretriage/main.go index cb26559..638c3e0 100644 --- a/cmd/pretriage/main.go +++ b/cmd/pretriage/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "log" "net/http" "os" @@ -22,7 +23,7 @@ var ( TEAM_VACATION = os.Getenv("TEAM_VACATION") ) -func main() { +func preTriage(dryRun bool) { var team Team if err := team.Load(strings.NewReader(TEAM_MEMBERS_DICT), strings.NewReader(TEAM_VACATION)); err != nil { log.Fatalf("error unmarshaling TEAM_MEMBERS_DICT: %v", err) @@ -81,16 +82,17 @@ func main() { log.Printf("Assigning issue %q to %q", issue.Key, censorEmail(assignee.JiraName)) - if err := assign(jiraClient, issue, assignee); err != nil { - gotErrors = true - log.Print(err) - return - } - - if err := notify(SLACK_HOOK, slackClient, issue, assignee); err != nil { - gotErrors = true - log.Print(err) - return + if ! dryRun { + if err := assign(jiraClient, issue, assignee); err != nil { + gotErrors = true + log.Print(err) + return + } + if err := notify(SLACK_HOOK, slackClient, issue, assignee); err != nil { + gotErrors = true + log.Print(err) + return + } } }(issue) } @@ -101,6 +103,21 @@ func main() { } } +func main() { + var help = flag.Bool("help", false, "Show help") + var dryRun = false + flag.BoolVar(&dryRun, "dryRun", false, "Dry run (do not assign)") + + flag.Parse() + + if *help { + flag.Usage() + os.Exit(0) + } + + preTriage(dryRun) +} + func init() { ex_usage := false if SLACK_HOOK == "" { diff --git a/cmd/triage/main.go b/cmd/triage/main.go index d8d0cb2..11ac941 100644 --- a/cmd/triage/main.go +++ b/cmd/triage/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "log" "net/http" "os" @@ -21,7 +22,7 @@ var ( TEAM_MEMBERS_DICT = os.Getenv("TEAM_MEMBERS_DICT") ) -func main() { +func triage(dryRun bool) { ctx := context.Background() var team Team @@ -78,10 +79,12 @@ func main() { teamMember = team["team"] } - if err := notify(SLACK_HOOK, slackClient, issues, teamMember); err != nil { - gotErrors = true - log.Print(err) - return + if ! dryRun { + if err := notify(SLACK_HOOK, slackClient, issues, teamMember); err != nil { + gotErrors = true + log.Print(err) + return + } } } @@ -90,6 +93,21 @@ func main() { } } +func main() { + var help = flag.Bool("help", false, "Show help") + var dryRun = false + flag.BoolVar(&dryRun, "dryRun", false, "Dry run (do not assign)") + + flag.Parse() + + if *help { + flag.Usage() + os.Exit(0) + } + + triage(dryRun) +} + func init() { ex_usage := false if SLACK_HOOK == "" {