From 86cd9ebb29e4787b445f3c7ca93c057ec617e855 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 30 May 2023 11:57:59 +0100 Subject: [PATCH] Add debug mode It can be helpful to debug the behavior of the bot tools without having anything post to Slack. Make this possible, starting with the doctext tool. Signed-off-by: Stephen Finucane --- README.md | 29 +++++++++++++++-------- cmd/doctext/main.go | 56 +++++++++++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index c72ef5b..282db1e 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,19 @@ ## pretriage -Usage: +**Usage:** + ```shell go build ./cmd/pretriage && ./pretriage` ``` Finds untriaged, unassigned Shiftstack bugs and assigns them to a team member. -Required environment variables: +**Required environment variables:** * `JIRA_TOKEN`: a [Jira API token](https://issues.redhat.com/secure/ViewProfile.jspa?selectedTab=com.atlassian.pats.pats-plugin:jira-user-personal-access-tokens) of an account that can access the OCPBUGS project * `SLACK_HOOK`: a [Slack hook](https://api.slack.com/messaging/webhooks) URL -* `TEAM_MEMBERS_DICT` is a JSON object in the form: +* `TEAM_MEMBERS_DICT`: a JSON object in the form: ```json { @@ -34,7 +35,9 @@ Required environment variables: } ``` -Optional environment variable: `TEAM_VACATION` in the form: +**Optional environment variables:** + +* `TEAM_VACATION`: a JSON object in the form: ```json [ @@ -53,28 +56,34 @@ Optional environment variable: `TEAM_VACATION` in the form: ## posttriage -Usage: +**Usage:** + ```shell go build ./cmd/posttriage && ./posttriage ``` Resets the `Triaged` keyword on bugs that still need attention. -Required environment variables: +**Required environment variables:** * `JIRA_TOKEN`: a [Jira API token](https://issues.redhat.com/secure/ViewProfile.jspa?selectedTab=com.atlassian.pats.pats-plugin:jira-user-personal-access-tokens) of an account that can access the OCPBUGS project ## doctext -Usage: +**Usage:** + ```shell go build ./cmd/doctext && ./doctext ``` Finds resolved bugs lacking a doc text, and posts a reminder to Slack. -Required environment variables: +**Required environment variables:** * `JIRA_TOKEN`: a [Jira API token](https://issues.redhat.com/secure/ViewProfile.jspa?selectedTab=com.atlassian.pats.pats-plugin:jira-user-personal-access-tokens) of an account that can access the OCPBUGS project -* `SLACK_HOOK`: a [Slack hook](https://api.slack.com/messaging/webhooks) URL -* `TEAM_MEMBERS_DICT` is a JSON object in the form: +* `SLACK_HOOK`: a [Slack hook](https://api.slack.com/messaging/webhooks) URL (optional and ignored if `BUGWATCHER_DEBUG` set) +* `TEAM_MEMBERS_DICT`: a JSON object in the form described previously (optional and ignored if `BUGWATCHER_DEBUG` set) + +**Optional environment variables:** + +* `BUGWATCHER_DEBUG`: enable debug mode, where found bugs are logged to output instead of Slack diff --git a/cmd/doctext/main.go b/cmd/doctext/main.go index 230a59f..1f94eb5 100644 --- a/cmd/doctext/main.go +++ b/cmd/doctext/main.go @@ -15,6 +15,7 @@ import ( const queryTriaged = query.ShiftStack + `AND status in ("Release Pending", Verified, ON_QA) AND "Release Note Text" is EMPTY` var ( + BUGWATCHER_DEBUG = os.Getenv("BUGWATCHER_DEBUG") SLACK_HOOK = os.Getenv("SLACK_HOOK") JIRA_TOKEN = os.Getenv("JIRA_TOKEN") TEAM_MEMBERS_DICT = os.Getenv("TEAM_MEMBERS_DICT") @@ -23,11 +24,6 @@ var ( func main() { ctx := context.Background() - var team Team - if err := team.Load(strings.NewReader(TEAM_MEMBERS_DICT)); err != nil { - log.Fatalf("error unmarshaling TEAM_MEMBERS_DICT: %v", err) - } - var jiraClient *jira.Client { var err error @@ -49,7 +45,6 @@ func main() { gotErrors bool wg sync.WaitGroup ) - slackClient := &http.Client{} issues := make(map[string][]jira.Issue) for issue := range searchIssues(ctx, jiraClient, queryTriaged) { wg.Add(1) @@ -84,15 +79,30 @@ func main() { } wg.Wait() - for assignee, issue := range issues { - teamMember, ok := team[assignee] - if !ok { - teamMember = team["team"] + if BUGWATCHER_DEBUG == "" { + var team Team + if err := team.Load(strings.NewReader(TEAM_MEMBERS_DICT)); err != nil { + log.Fatalf("error unmarshaling TEAM_MEMBERS_DICT: %v", err) } - if err := notify(SLACK_HOOK, slackClient, issue, teamMember); err != nil { - gotErrors = true - log.Print(err) - return + + slackClient := &http.Client{} + for assignee, issue := range issues { + teamMember, ok := team[assignee] + if !ok { + teamMember = team["team"] + } + if err := notify(SLACK_HOOK, slackClient, issue, teamMember); err != nil { + gotErrors = true + log.Print(err) + return + } + } + } else { + for assignee, issue := range issues { + log.Printf("Found %d issues for assignee %s", len(issue), assignee) + for _, x := range issue { + log.Printf("- %s (%s)", x.Key, x.Fields.Summary) + } } } @@ -105,19 +115,21 @@ func main() { func init() { ex_usage := false - if SLACK_HOOK == "" { - ex_usage = true - log.Print("Required environment variable not found: SLACK_HOOK") - } - if JIRA_TOKEN == "" { ex_usage = true log.Print("Required environment variable not found: JIRA_TOKEN") } - if TEAM_MEMBERS_DICT == "" { - ex_usage = true - log.Print("Required environment variable not found: TEAM_MEMBERS_DICT") + if BUGWATCHER_DEBUG == "" { + if SLACK_HOOK == "" { + ex_usage = true + log.Print("Required environment variable not found: SLACK_HOOK") + } + + if TEAM_MEMBERS_DICT == "" { + ex_usage = true + log.Print("Required environment variable not found: TEAM_MEMBERS_DICT") + } } if ex_usage {