Skip to content

Commit 07f2f3d

Browse files
Refactor usage of actions whiteboard tags (fixes #89) (#100)
* Update README to new way of configuring * Change models and reformat configuration files * Update powered by JBI template * Remove the whiteboard_tag parameter * Bugzilla.lookup_action() * Adjust API unit tests * Raise if duplicated action tag * Do not change /whiteboard_tags/ endpoint * Test both configuration files * Rename action_tag to whiteboard_tag * Update src/jbi/models.py Co-authored-by: grahamalama <[email protected]> * Update src/jbi/whiteboard_actions/README.md Co-authored-by: grahamalama <[email protected]> * Update src/templates/powered_by_template.html Co-authored-by: grahamalama <[email protected]> * Document instead of promote * Use Field from pydantic Co-authored-by: grahamalama <[email protected]>
1 parent 3b71d1f commit 07f2f3d

21 files changed

+243
-176
lines changed

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"filename": "README.md",
107107
"hashed_secret": "04e78d6e804f2b59e6cb282cb9ed2c7bfd8a9737",
108108
"is_verified": false,
109-
"line_number": 152
109+
"line_number": 183
110110
}
111111
],
112112
"config/local_dev.env": [
@@ -126,5 +126,5 @@
126126
}
127127
]
128128
},
129-
"generated_at": "2022-07-13T07:01:04Z"
129+
"generated_at": "2022-07-13T09:34:14Z"
130130
}

.yamllint

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ ignore: |
1313

1414
rules:
1515
key-duplicates: enable
16-
key-ordering: enable
1716

1817

1918
yaml-files:

README.md

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,30 @@ System to sync Bugzilla bugs to Jira issues.
77

88
### Caveats
99
- The system accepts webhook events from Bugzilla
10-
- Bugs' whiteboard tags are used to determine if they should be synchronized or ignored
10+
- Bugs' `whiteboard` tags are used to determine if they should be synchronized or ignored
1111
- The events are transformed into Jira issues
1212
- The system sets the `see_also` field of the Bugzilla bug with the URL to the Jira issue
1313

1414
## Action Configuration
15-
The system reads the action configuration from a YAML file, one per environment. Each entry controls the synchronization between Bugzilla tickets with Jira issues.
15+
The system reads the actions configuration from a YAML file, one per environment. Each entry controls the synchronization between Bugzilla tickets and the Jira issues.
1616

1717

1818
Below is a full example of an action configuration:
1919
```yaml
20-
action: src.jbi.whiteboard_actions.default
21-
allow_private: false
22-
23-
description: example configuration
24-
enabled: true
25-
parameters:
26-
jira_project_key: EXMPL
27-
whiteboard_tag: example
20+
- whiteboard_tag: example
21+
allow_private: false
22+
23+
description: example configuration
24+
enabled: true
25+
module: src.jbi.whiteboard_actions.default
26+
parameters:
27+
jira_project_key: EXMPL
2828
```
2929
3030
A bit more about the different fields...
31-
- `action` (optional)
31+
- `whiteboard_tag`
3232
- string
33-
- default: [src.jbi.whiteboard_actions.default](src/jbi/whiteboard_actions/default.py)
34-
- The specified Python module must be available in the `PYTHONPATH`
33+
- The tag to be matched in the Bugzilla `whiteboard` field
3534
- `allow_private` (optional)
3635
- bool [true, false]
3736
- default: false
@@ -49,39 +48,71 @@ A bit more about the different fields...
4948
- bool [true, false]
5049
- default: false
5150
- If false, matching events will not be synchronized
51+
- `module` (optional)
52+
- string
53+
- default: [src.jbi.whiteboard_actions.default](src/jbi/whiteboard_actions/default.py)
54+
- The specified Python module must be available in the `PYTHONPATH`
5255
- `parameters` (optional)
5356
- dict
5457
- default: {}
5558
- The parameters will be validated to ensure the selected action accepts the specified values
56-
- The [default action](src/jbi/whiteboard_actions/default.py) expects both the `whiteboard_tag` and `jira_project_key` fields
5759

5860

5961
[View 'nonprod' configurations here.](config/config.nonprod.yaml)
6062

6163
[View 'prod' configurations here.](config/config.prod.yaml)
6264

6365

64-
## Default with assignee and status action
66+
## Available Actions
67+
68+
### Default
69+
The `src.jbi.whiteboard_actions.default` action will create or update the Jira issue and its comments.
70+
It will also set the Jira issue URL in the Bugzilla bug `see_also` field.
71+
72+
**Parameters**
73+
74+
- `jira_project_key`
75+
- string
76+
- The Jira project identifier
77+
78+
Example configuration:
79+
```yaml
80+
whiteboard_tag: example
81+
82+
description: example configuration
83+
module: src.jbi.whiteboard_actions.default
84+
parameters:
85+
jira_project_key: EXMPL
86+
```
87+
88+
### Default with assignee and status action
6589
The `src.jbi.whiteboard_actions.default_with_assignee_and_status` action adds some additional
6690
features on top of the default.
6791

6892
It will attempt to assign the Jira issue the same person as the bug is assigned to. This relies on
6993
the user using the same email address in both Bugzilla and Jira. If the user does not exist in Jira
7094
then the assignee is cleared from the Jira issue.
7195

72-
The action supports setting the Jira issues's status when the Bugzilla status and resolution change.
73-
This is defined using a mapping on a per-project basis configured in the `status_map` field of the
74-
`parameters` field.
96+
If configured, the action supports setting the Jira issues's status when the Bugzilla status and resolution change.
97+
98+
**Parameters**
7599

76-
An example configuration:
100+
- `jira_project_key`
101+
- string
102+
- The Jira project identifier
103+
- `status_map` (optional)
104+
- mapping [str, str]
105+
- If defined, map the Bugzilla bug status to Jira issue status
106+
107+
Example configuration:
77108
```yaml
78-
action: src.jbi.whiteboard_actions.default_with_assignee_and_status
109+
whiteboard_tag: example
79110
80111
description: example configuration
81112
enabled: true
113+
module: src.jbi.whiteboard_actions.default_with_assignee_and_status
82114
parameters:
83115
jira_project_key: EXMPL
84-
whiteboard_tag: example
85116
status_map:
86117
NEW: "In Progress"
87118
FIXED: "Closed"
@@ -93,7 +124,7 @@ linked Jira issue status to "Closed". If the bug changes to a status not listed
93124
no change will be made to the Jira issue.
94125

95126
### Custom Actions
96-
If you're looking for a unique capability for your team's data flow, you can add your own python methods and functionality[...read more here.](src/jbi/whiteboard_actions/README.md)
127+
If you're looking for a unique capability for your team's data flow, you can add your own Python methods and functionality[...read more here.](src/jbi/whiteboard_actions/README.md)
97128

98129

99130
## Diagram Overview
@@ -165,15 +196,15 @@ For the list of configured whiteboard tags:
165196
GET /whiteboard_tags/
166197
{
167198
"addons": {
168-
"action": "src.jbi.whiteboard_actions.default",
199+
"whiteboard_tag": "addons",
169200
"contact": "[email protected]",
170201
"description": "Addons whiteboard tag for AMO Team",
171202
"enabled": true,
203+
"module": "src.jbi.whiteboard_actions.default",
172204
"parameters": {
173-
"jira_project_key": "WEBEXT",
174-
"whiteboard_tag": "addons"
205+
"jira_project_key": "WEBEXT"
175206
}
176-
},
207+
}
177208
...
178209
}
179210
```

config/config.nonprod.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
---
22
# Action Config
3-
devtest:
3+
- whiteboard_tag: devtest
44
contact: tbd
55
description: DevTest whiteboard tag
66
enabled: true
77
parameters:
88
jira_project_key: JST
9-
whiteboard_tag: devtest
10-
flowstate:
11-
action: src.jbi.whiteboard_actions.default_with_assignee_and_status
9+
10+
- whiteboard_tag: flowstate
1211
allow_private: true
1312
1413
description: Flowstate whiteboard tag
1514
enabled: true
15+
module: src.jbi.whiteboard_actions.default_with_assignee_and_status
1616
parameters:
1717
jira_project_key: MR2
1818
status_map:
1919
ASSIGNED: In Progress
2020
FIXED: In Review
2121
REOPENED: In Progress
22-
whiteboard_tag: flowstate

config/config.prod.yaml

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,106 @@
11
---
22
# Action Config
3-
addons:
4-
# action: src.jbi.whiteboard_actions.default
3+
- whiteboard_tag: addons
54
contact: tbd
65
description: Addons whiteboard tag for AMO Team
76
enabled: true
7+
# module: src.jbi.whiteboard_actions.default
88
parameters:
99
jira_project_key: WEBEXT
10-
whiteboard_tag: addons
11-
fidedi:
10+
11+
- whiteboard_tag: fidedi
1212
contact: tbd
1313
description: Firefox Desktop Integration whiteboard tag
1414
enabled: true
1515
parameters:
1616
jira_project_key: FIDEDI
17-
whiteboard_tag: fidedi
18-
fidefe:
17+
18+
- whiteboard_tag: fidefe
1919
contact: tbd
2020
description: Firefox Front End whiteboard tag
2121
enabled: true
2222
parameters:
2323
jira_project_key: FIDEFE
24-
whiteboard_tag: fidefe
25-
flowstate:
26-
action: src.jbi.whiteboard_actions.default_with_assignee_and_status
24+
25+
- whiteboard_tag: flowstate
2726
allow_private: true
2827
2928
description: Flowstate whiteboard tag
3029
enabled: true
30+
module: src.jbi.whiteboard_actions.default_with_assignee_and_status
3131
parameters:
3232
jira_project_key: MR2
3333
status_map:
3434
ASSIGNED: In Progress
3535
FIXED: In Review
3636
REOPENED: In Progress
37-
whiteboard_tag: flowstate
38-
fxatps:
37+
38+
- whiteboard_tag: fxatps
3939
contact: tbd
4040
description: Privacy & Security and Anti-Tracking Team whiteboard tag
4141
enabled: true
4242
parameters:
4343
jira_project_key: FXATPS
44-
whiteboard_tag: fxatps
45-
fxcm:
44+
45+
- whiteboard_tag: fxcm
4646
contact: tbd
4747
description: Firefox Credential Management Team whiteboard tag
4848
enabled: true
4949
parameters:
5050
jira_project_key: FXCM
51-
whiteboard_tag: fxcm
52-
fxsync:
51+
52+
- whiteboard_tag: fxsync
5353
contact: tbd
5454
description: Firefox Sync Team whiteboard tag
5555
enabled: true
5656
parameters:
5757
jira_project_key: SYNC
58-
whiteboard_tag: fxsync
59-
gv:
58+
59+
- whiteboard_tag: gv
6060
contact: tbd
6161
description: GeckoView Team whiteboard tag
6262
enabled: true
6363
parameters:
6464
jira_project_key: ANDP
65-
whiteboard_tag: gv
66-
mv3:
65+
66+
- whiteboard_tag: mv3
6767
contact: tbd
6868
description: MV3 whiteboard tag
6969
enabled: true
7070
parameters:
7171
jira_project_key: WEBEXT
72-
whiteboard_tag: mv3
73-
nimbus:
72+
73+
- whiteboard_tag: nimbus
7474
contact: tbd
7575
description: Nimbus whiteboard tag
7676
enabled: true
7777
parameters:
7878
jira_project_key: EXP
79-
whiteboard_tag: nimbus
80-
prodtest:
79+
80+
- whiteboard_tag: prodtest
8181
contact: tbd
8282
description: ProdTest tag
8383
enabled: true
8484
parameters:
8585
jira_project_key: OSS
86-
whiteboard_tag: prodtest
87-
proton:
86+
87+
- whiteboard_tag: proton
8888
contact: tbd
8989
description: Proton whiteboard tag for Firefox Frontend
9090
enabled: true
9191
parameters:
9292
jira_project_key: FIDEFE
93-
whiteboard_tag: proton
94-
relops:
93+
94+
- whiteboard_tag: relops
9595
contact: tbd
9696
description: Release Operations Team Tag
9797
enabled: true
9898
parameters:
9999
jira_project_key: RELOPS
100-
whiteboard_tag: relops
101-
snt:
100+
101+
- whiteboard_tag: snt
102102
contact: tbd
103103
description: Search/NewTab Team Tag
104104
enabled: true
105105
parameters:
106106
jira_project_key: SNT
107-
whiteboard_tag: snt

src/app/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_whiteboard_tag(
111111
"""API for viewing whiteboard_tags and associated data"""
112112
if existing := actions.get(whiteboard_tag):
113113
return {whiteboard_tag: existing}
114-
return actions
114+
return actions.by_tag
115115

116116

117117
@app.get("/jira_projects/")
@@ -132,8 +132,7 @@ def powered_by_jbi(
132132
context = {
133133
"request": request,
134134
"title": "Powered by JBI",
135-
"num_configs": len(actions),
136-
"data": jsonable_encoder(actions),
135+
"actions": jsonable_encoder(actions),
137136
"enable_query": enabled,
138137
}
139138
return templates.TemplateResponse("powered_by_template.html", context)

src/jbi/bugzilla.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88
import logging
99
from functools import cached_property
10-
from typing import Dict, List, Optional, Tuple
10+
from typing import Dict, List, Optional
1111
from urllib.parse import ParseResult, urlparse
1212

1313
from pydantic import BaseModel # pylint: disable=no-name-in-module
@@ -148,7 +148,7 @@ def get_jira_labels(self) -> List[str]:
148148
return ["bugzilla"] + wb_list + wb_bracket_list
149149

150150
def get_potential_whiteboard_config_list(self) -> List[str]:
151-
"""Get all possible whiteboard_tag configuration values"""
151+
"""Get all possible tags from `whiteboard` field"""
152152
converted_list: List = []
153153
for whiteboard in self.get_whiteboard_as_list():
154154
first_tag = whiteboard.strip().lower().split(sep="-", maxsplit=1)[0]
@@ -198,13 +198,12 @@ def extract_from_see_also(self):
198198

199199
return None
200200

201-
def lookup_action(self, actions: Actions) -> Tuple[str, Action]:
201+
def lookup_action(self, actions: Actions) -> Action:
202202
"""Find first matching action from bug's whiteboard list"""
203203
tags: List[str] = self.get_potential_whiteboard_config_list()
204204
for tag in tags:
205-
tag = tag.lower()
206205
if action := actions.get(tag):
207-
return tag, action
206+
return action
208207
raise ActionNotFoundError(", ".join(tags))
209208

210209

0 commit comments

Comments
 (0)