Skip to content

Commit 2c2fe6d

Browse files
Use YAML for team data
Use YAML files for human consumption. Also add a sprinkle of refactoring.
1 parent c1c4929 commit 2c2fe6d

34 files changed

+11771
-362
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
build: pretriage triage posttriage doctext
22

3-
pretriage: cmd/pretriage pkg/jiraclient pkg/query
3+
pretriage: cmd/pretriage pkg/jiraclient pkg/query pkg/slack pkg/team
44
go build ./$<
55

6-
triage: cmd/triage pkg/jiraclient pkg/query
6+
triage: cmd/triage pkg/jiraclient pkg/query pkg/slack pkg/team
77
go build ./$<
88

99
posttriage: cmd/posttriage pkg/jiraclient pkg/query
1010
go build ./$<
1111

12-
doctext: cmd/doctext pkg/jiraclient pkg/query
12+
doctext: cmd/doctext pkg/jiraclient pkg/query pkg/slack pkg/team
1313
go build ./$<
1414

1515
lint:

README.md

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,27 @@ Required environment variables:
2020

2121
* `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
2222
* `SLACK_HOOK`: a [Slack hook](https://api.slack.com/messaging/webhooks) URL
23-
* `TEAM_MEMBERS_DICT` is a JSON object in the form:
24-
25-
```json
26-
{
27-
"kerberos_id1": {
28-
"slack_id": "UG65473AM",
29-
"bz_id": "[email protected]",
30-
"components": ["component1"],
31-
"jira_name": "user1",
32-
"jira_components": ["component1/sub-component1"]
33-
},
34-
"kerberos_id2": {
35-
"slack_id": "UGF8B93HA",
36-
"bz_id": "[email protected]",
37-
"components": [],
38-
"jira_name": "user2",
39-
"jira_components": []
40-
}
41-
}
23+
* `PEOPLE`: an address book. It is a YAML object in the form:
24+
25+
```yaml
26+
- kerberos: user1
27+
github_handle: ghuser
28+
jira_name: jirauser
29+
slack_id: U012334
30+
- kerberos: user2
31+
github_handle: ghuser2
32+
jira_name: jirauser2
33+
slack_id: U0122345
4234
```
4335
44-
Optional environment variable: `TEAM_VACATION` in the form:
45-
46-
```json
47-
[
48-
{
49-
"kerberos": "jdoe",
50-
"start": "2022-01-01",
51-
"end": "2022-01-15"
52-
},
53-
{
54-
"kerberos": "jdoe",
55-
"start": "2022-06-12",
56-
"end": "2022-06-15"
57-
}
58-
]
36+
* `TEAM`: an object containing team members, referencing the `kerberos` property of PEOPLE. It is a YAML object in the form:
37+
38+
```yaml
39+
user1:
40+
bug_triage: true
41+
leave:
42+
- start: 2024-11-21
43+
end: 2025-02-28
5944
```
6045

6146
### Local testing
@@ -82,7 +67,7 @@ Required environment variables:
8267

8368
* `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
8469
* `SLACK_HOOK`: a [Slack hook](https://api.slack.com/messaging/webhooks) URL
85-
* `TEAM_MEMBERS_DICT` is a JSON object in the form described [above][pretriage].
70+
* `PEOPLE` and `TEAM` described [above][pretriage].
8671

8772
## posttriage
8873

@@ -112,4 +97,4 @@ Required environment variables:
11297

11398
* `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
11499
* `SLACK_HOOK`: a [Slack hook](https://api.slack.com/messaging/webhooks) URL
115-
* `TEAM_MEMBERS_DICT` is a JSON object in the form:
100+
* `PEOPLE` and `TEAM` described [above][pretriage].

cmd/check/main.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This program checks that the variables are syntactically correct.
2+
package main
3+
4+
import (
5+
"fmt"
6+
"log"
7+
"os"
8+
"strings"
9+
10+
"github.com/shiftstack/bugwatcher/pkg/team"
11+
)
12+
13+
var (
14+
PEOPLE = os.Getenv("PEOPLE")
15+
TEAM = os.Getenv("TEAM")
16+
)
17+
18+
func main() {
19+
people, err := team.Load(strings.NewReader(PEOPLE), strings.NewReader(TEAM))
20+
if err != nil {
21+
log.Fatalf("Error loading team members: %v", err)
22+
}
23+
24+
fmt.Printf("Found %d people:\n", len(people))
25+
}
26+
27+
func init() {
28+
log.SetFlags(log.Ldate | log.Ltime | log.LUTC)
29+
30+
ex_usage := false
31+
if PEOPLE == "" {
32+
ex_usage = true
33+
log.Print("Required environment variable not found: PEOPLE")
34+
}
35+
36+
if TEAM == "" {
37+
ex_usage = true
38+
log.Print("Required environment variable not found: TEAM")
39+
}
40+
41+
if ex_usage {
42+
log.Print("Exiting.")
43+
os.Exit(64)
44+
}
45+
}

cmd/doctext/main.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@ import (
1111
"github.com/shiftstack/bugwatcher/pkg/jiraclient"
1212
"github.com/shiftstack/bugwatcher/pkg/query"
1313
"github.com/shiftstack/bugwatcher/pkg/slack"
14+
"github.com/shiftstack/bugwatcher/pkg/team"
1415
)
1516

1617
const queryTriaged = query.ShiftStack + `AND status in ("Release Pending", Verified, ON_QA) AND "Release Note Text" is EMPTY`
1718

1819
var (
19-
SLACK_HOOK = os.Getenv("SLACK_HOOK")
20-
JIRA_TOKEN = os.Getenv("JIRA_TOKEN")
21-
TEAM_MEMBERS_DICT = os.Getenv("TEAM_MEMBERS_DICT")
20+
SLACK_HOOK = os.Getenv("SLACK_HOOK")
21+
JIRA_TOKEN = os.Getenv("JIRA_TOKEN")
22+
PEOPLE = os.Getenv("PEOPLE")
23+
TEAM = os.Getenv("TEAM")
2224
)
2325

2426
func main() {
2527
ctx := context.Background()
2628

27-
var team Team
28-
if err := team.Load(strings.NewReader(TEAM_MEMBERS_DICT)); err != nil {
29-
log.Fatalf("error unmarshaling TEAM_MEMBERS_DICT: %v", err)
29+
var people []team.Person
30+
{
31+
var err error
32+
people, err = team.Load(strings.NewReader(PEOPLE), strings.NewReader(TEAM))
33+
if err != nil {
34+
log.Fatalf("error fetching team information: %v", err)
35+
}
3036
}
3137

3238
jiraClient, err := jiraclient.NewWithToken(query.JiraBaseURL, JIRA_TOKEN)
@@ -67,7 +73,7 @@ func main() {
6773
log.Printf("INFO: Missing DocText for %q", issue.Key)
6874
var assignee string
6975
if issue.Fields.Assignee == nil {
70-
assignee = "team"
76+
assignee = ""
7177
} else {
7278
assignee = issue.Fields.Assignee.Name
7379
}
@@ -78,12 +84,15 @@ func main() {
7884
}
7985
wg.Wait()
8086

81-
for assignee, issues := range issuesNeedingAttention {
82-
teamMember, ok := team[assignee]
83-
if !ok {
84-
teamMember = team["team"]
87+
for assigneeJiraName, issues := range issuesNeedingAttention {
88+
var slackId string
89+
if person, ok := team.PersonByJiraName(people, assigneeJiraName); ok {
90+
slackId = person.Slack
91+
} else {
92+
slackId = team.TeamSlackId
8593
}
86-
if err := slackClient.Send(SLACK_HOOK, notification(issues, teamMember)); err != nil {
94+
95+
if err := slackClient.Send(SLACK_HOOK, notification(issues, slackId)); err != nil {
8796
gotErrors = true
8897
log.Print(err)
8998
return
@@ -109,9 +118,14 @@ func init() {
109118
log.Print("Required environment variable not found: JIRA_TOKEN")
110119
}
111120

112-
if TEAM_MEMBERS_DICT == "" {
121+
if PEOPLE == "" {
122+
ex_usage = true
123+
log.Print("Required environment variable not found: PEOPLE")
124+
}
125+
126+
if TEAM == "" {
113127
ex_usage = true
114-
log.Print("Required environment variable not found: TEAM_MEMBERS_DICT")
128+
log.Print("Required environment variable not found: TEAM")
115129
}
116130

117131
if ex_usage {

cmd/doctext/notify.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@ import (
88
"github.com/shiftstack/bugwatcher/pkg/slack"
99
)
1010

11-
func notification(issues []jira.Issue, assignee TeamMember) string {
12-
var slackId string
13-
if strings.HasPrefix(assignee.SlackId, "!subteam^") {
14-
slackId = "<" + assignee.SlackId + ">"
15-
} else {
16-
slackId = "<@" + assignee.SlackId + ">"
17-
}
18-
11+
func notification(issues []jira.Issue, slackId string) string {
1912
var notification strings.Builder
20-
notification.WriteString(slackId + " please check the Release Note Text of these bugs:")
13+
notification.WriteByte('<')
14+
notification.WriteString(slackId)
15+
notification.WriteString("> please check the Release Note Text of these bugs:")
2116
for _, issue := range issues {
2217
notification.WriteByte(' ')
2318
notification.WriteString(slack.Link(query.JiraBaseURL+"browse/"+issue.Key, issue.Key))

cmd/doctext/team.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

cmd/pretriage/assign.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
jira "github.com/andygrunwald/go-jira"
99
)
1010

11-
func assign(jiraClient *jira.Client, issue jira.Issue, assignee TeamMember) error {
12-
res, err := jiraClient.Issue.UpdateAssignee(issue.ID, &jira.User{Name: assignee.JiraName})
11+
func assign(jiraClient *jira.Client, issue jira.Issue, assigneeJiraName string) error {
12+
res, err := jiraClient.Issue.UpdateAssignee(issue.ID, &jira.User{Name: assigneeJiraName})
1313
if err != nil && res == nil {
1414
// we only error out early if there's no response to work with
1515
return fmt.Errorf("error while assigning bug %s: %w", issue.Key, err)

0 commit comments

Comments
 (0)