Skip to content

Commit 0da6d79

Browse files
Split actions into reusable steps (fixes #213, fixes #77, embeds #233, #236, #253) (#232)
* Extract create and update issue * Remove client as action attributes * Remove useless code * Extract add comment * Remove indirection with comments for changes * Instantiate context in __call__ instead of each method * Remove usage of self in _update_issue() * Split default with status and assignee into smaller bits * Rename create_comment() * Remove class inheritance between default and default with status and assignee (ref #77) (#233) * Move helpers to jbi.services.jira and bugzilla * Move bugzilla out of jira module * Add type annotations * Update code comment about bug.comment * Chain operations instead of using nested conditions (with `:=` operators) (#236) * Rename ActionLogContext to ActionContext * Rename log_context to context * Remove := operator and chain operations * Remove the maybe_ from services.jira * Align signatures of action functions * Do not duplicate parameters between init and call * Runner now instantiates context * Pass actions contexts to action tests * Update actions docs * Remove redundant parameters * Adjust parameters between default.py and jira.py * Inherit JiraContext from Context * Remove useless and confusing condition * Replace repetitive calls with list of steps * Let the runner set the ActionContext operation * Reintroduce maybe_ for optional steps * Load default action steps from configuration (#253) * Move steps to jbi.actions.steps * Rename test_default to test_steps * Move test_default_with_assignee_and_status into test_steps * Load default action steps from configuration * Add tests for the default action behaviour * Rename groups of steps. create -> new, update -> existing * Remove default value config/config.prod.yaml Co-authored-by: bsieber-mozilla <[email protected]> * Move remapping of steps into helper * Remove useless pylint annotation * Adjust docstrings * Merge unspecified groups with default ones * Update secrets baseline Co-authored-by: bsieber-mozilla <[email protected]> Co-authored-by: bsieber-mozilla <[email protected]> Co-authored-by: bsieber-mozilla <[email protected]>
1 parent 7cfc5eb commit 0da6d79

21 files changed

+1337
-1027
lines changed

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@
122122
"filename": "README.md",
123123
"hashed_secret": "04e78d6e804f2b59e6cb282cb9ed2c7bfd8a9737",
124124
"is_verified": false,
125-
"line_number": 218
125+
"line_number": 242
126126
}
127127
]
128128
},
129-
"generated_at": "2022-08-30T10:02:55Z"
129+
"generated_at": "2022-09-28T11:04:17Z"
130130
}

README.md

Lines changed: 79 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -66,56 +66,24 @@ A bit more about the different fields...
6666
## Available Actions
6767

6868
### Default
69-
The `jbi.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.
69+
The `jbi.actions.default` action will take the list of steps to be executed when
70+
the Webhook is received from configuration.
71+
When none is specified, it will create or update the Jira issue, publish comments when
72+
assignee, status, or resolution are changed, or when a comment is posted on the Bugzilla ticket.
7173

72-
**Parameters**
73-
74-
- `jira_project_key`
75-
- string
76-
- The Jira project identifier
77-
- `sync_whiteboard_labels`
78-
- boolean
79-
- Whether to sync the Bugzilla status whiteboard labels to Jira. Defaults to `true`.
80-
81-
Example configuration:
82-
```yaml
83-
whiteboard_tag: example
84-
85-
description: example configuration
86-
module: jbi.actions.default
87-
parameters:
88-
jira_project_key: EXMPL
89-
```
90-
91-
Example configuration that disables setting labels in Jira:
92-
```yaml
93-
whiteboard_tag: example
94-
95-
description: example configuration
96-
module: jbi.actions.default
97-
parameters:
98-
jira_project_key: EXMPL
99-
sync_whiteboard_labels: false
100-
```
101-
102-
### Default with assignee and status action
103-
The `jbi.actions.default_with_assignee_and_status` action adds some additional
104-
features on top of the default.
105-
106-
It will attempt to assign the Jira issue the same person as the bug is assigned to. This relies on
107-
the user using the same email address in both Bugzilla and Jira. If the user does not exist in Jira
108-
then the assignee is cleared from the Jira issue. The Jira account that JBI uses requires the "Browse
109-
users and groups" global permission in order to set the assignee.
110-
111-
If configured, the action supports setting the Jira issues's status when the Bugzilla status and resolution change.
74+
It will also set the Jira issue URL in the Bugzilla bug `see_also` field, and add a link
75+
to the Bugzilla ticket on the Jira issue.
11276

11377
**Parameters**
11478

11579
- `jira_project_key`
11680
- string
11781
- The Jira project identifier
118-
- `sync_whiteboard_labels`
82+
- `steps`
83+
- mapping [str, list[str]]
84+
- If defined, the specified steps are executed. The group of steps listed under `new` are executed when a Bugzilla event occurs on a ticket that is unknown to Jira. The steps under `existing`, when the Bugzilla ticket is already linked to a Jira issue. The steps under `comment` when a comment is posted on a linked Bugzilla ticket.
85+
If one of these groups is not specified, the default steps will be used.
86+
- `sync_whiteboard_labels` (optional)
11987
- boolean
12088
- Whether to sync the Bugzilla status whiteboard labels to Jira. Defaults to `true`.
12189
- `status_map` (optional)
@@ -125,32 +93,88 @@ If configured, the action supports setting the Jira issues's status when the Bug
12593
- mapping [str, str]
12694
- If defined, map the Bugzilla bug resolution to Jira issue resolution
12795

128-
Example configuration:
96+
Minimal configuration:
12997
```yaml
13098
whiteboard_tag: example
13199
132-
description: example configuration
133-
enabled: true
134-
module: jbi.actions.default_with_assignee_and_status
100+
description: minimal configuration
135101
parameters:
136102
jira_project_key: EXMPL
137-
status_map:
138-
NEW: "In Progress"
139-
FIXED: "Closed"
140-
resolution_map:
141-
FIXED: "Done"
142-
DUPLICATE: "Duplicate"
143-
WONTFIX: "Won't Do"
103+
```
104+
105+
Full configuration, that will set assignee, change the Jira issue status and resolution.
106+
107+
```yaml
108+
- whiteboard_tag: fidefe
109+
110+
description: full configuration
111+
enabled: true
112+
module: jbi.actions.default
113+
parameters:
114+
jira_project_key: FIDEFE
115+
steps:
116+
new:
117+
- create_issue
118+
- maybe_delete_duplicate
119+
- add_link_to_bugzilla
120+
- add_link_to_jira
121+
- maybe_assign_jira_user
122+
- maybe_update_issue_resolution
123+
- maybe_update_issue_status
124+
existing:
125+
- update_issue
126+
- add_jira_comments_for_changes
127+
- maybe_assign_jira_user
128+
- maybe_update_issue_resolution
129+
- maybe_update_issue_status
130+
comment:
131+
- create_comment
132+
status_map:
133+
ASSIGNED: In Progress
134+
FIXED: Closed
135+
WONTFIX: Closed
136+
DUPLICATE: Closed
137+
INVALID: Closed
138+
INCOMPLETE: Closed
139+
WORKSFORME: Closed
140+
REOPENED: In Progress
141+
resolution_map:
142+
FIXED: Done
143+
DUPLICATE: Duplicate
144+
WONTFIX: "Won't Do"
144145
```
145146

146147
In this case if the bug changes to the NEW status the action will attempt to set the linked Jira
147148
issue status to "In Progress". If the bug changes to RESOLVED FIXED it will attempt to set the
148149
linked Jira issue status to "Closed". If the bug changes to a status not listed in `status_map` then
149150
no change will be made to the Jira issue.
151+
### Available Steps
152+
153+
- `create_issue`
154+
- `maybe_delete_duplicate`
155+
- `add_link_to_bugzilla`
156+
- `add_link_to_jira`
157+
- `maybe_assign_jira_user`:
158+
It will attempt to assign the Jira issue the same person as the bug is assigned to. This relies on
159+
the user using the same email address in both Bugzilla and Jira. If the user does not exist in Jira
160+
then the assignee is cleared from the Jira issue. The Jira account that JBI uses requires the "Browse
161+
users and groups" global permission in order to set the assignee.
162+
- `maybe_update_issue_resolution`:
163+
If the Bugzilla ticket resolution field is specified in the `resolution_map` parameter, it will set the
164+
Jira issue resolution.
165+
- `maybe_update_issue_status`:
166+
If the Bugzilla ticket status field is specified in the `status_map` parameter, it will set the
167+
Jira issue status.
168+
- `update_issue`
169+
- `add_jira_comments_for_changes`
170+
- `maybe_assign_jira_user`
171+
- `maybe_update_issue_resolution`
172+
- `maybe_update_issue_status`
173+
- `create_comment`
150174

151175
### Custom Actions
152-
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.](jbi/actions/README.md)
153176

177+
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.](jbi/actions/README.md)
154178

155179
## Diagram Overview
156180

config/config.nonprod.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,22 @@
1212
1313
description: Flowstate whiteboard tag
1414
enabled: true
15-
module: jbi.actions.default_with_assignee_and_status
1615
parameters:
1716
jira_project_key: MR2
17+
steps:
18+
new:
19+
- create_issue
20+
- maybe_delete_duplicate
21+
- add_link_to_bugzilla
22+
- add_link_to_jira
23+
- maybe_assign_jira_user
24+
- maybe_update_issue_resolution
25+
- maybe_update_issue_status
26+
existing:
27+
- update_issue
28+
- maybe_assign_jira_user
29+
- maybe_update_issue_resolution
30+
- maybe_update_issue_status
1831
status_map:
1932
ASSIGNED: In Progress
2033
FIXED: In Review

config/config.prod.yaml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,22 @@
1919
2020
description: Firefox Front End whiteboard tag
2121
enabled: true
22-
module: jbi.actions.default_with_assignee_and_status
2322
parameters:
2423
jira_project_key: FIDEFE
24+
steps:
25+
new:
26+
- create_issue
27+
- maybe_delete_duplicate
28+
- add_link_to_bugzilla
29+
- add_link_to_jira
30+
- maybe_assign_jira_user
31+
- maybe_update_issue_resolution
32+
- maybe_update_issue_status
33+
existing:
34+
- update_issue
35+
- maybe_assign_jira_user
36+
- maybe_update_issue_resolution
37+
- maybe_update_issue_status
2538
status_map:
2639
ASSIGNED: In Progress
2740
FIXED: Closed
@@ -40,9 +53,22 @@
4053
4154
description: Flowstate whiteboard tag
4255
enabled: true
43-
module: jbi.actions.default_with_assignee_and_status
4456
parameters:
4557
jira_project_key: MR2
58+
steps:
59+
new:
60+
- create_issue
61+
- maybe_delete_duplicate
62+
- add_link_to_bugzilla
63+
- add_link_to_jira
64+
- maybe_assign_jira_user
65+
- maybe_update_issue_resolution
66+
- maybe_update_issue_status
67+
existing:
68+
- update_issue,
69+
- maybe_assign_jira_user
70+
- maybe_update_issue_resolution
71+
- maybe_update_issue_status
4672
sync_whiteboard_labels: false
4773
status_map:
4874
ASSIGNED: In Progress

jbi/actions/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ Let's create a `new_action`!
1212

1313
```python
1414
from jbi import ActionResult, Operation
15-
from jbi.models import BugzillaBug, BugzillaWebhookEvent
15+
from jbi.models import ActionContext
1616

1717
JIRA_REQUIRED_PERMISSIONS = {"CREATE_ISSUES"}
1818

1919
def init(jira_project_key, optional_param=42):
2020

21-
def execute(bug: BugzillaBug, event: BugzillaWebhookEvent) -> ActionResult:
21+
def execute(context: ActionContext) -> ActionResult:
2222
print(f"{optional_param}, going to {jira_project_key}!")
2323
return True, {"result": 42}
2424

@@ -27,11 +27,11 @@ Let's create a `new_action`!
2727

2828
1. In the above example the `jira_project_key` parameter is required
2929
1. `optional_param`, which has a default value, is not required to run this action
30-
1. `init()` returns a `__call__`able object that the system calls with the Bugzilla bug and WebHook event objects
30+
1. `init()` returns a `__call__`able object that the system calls with the `ActionContext` object
3131
1. The returned `ActionResult` features a boolean to indicate whether something was performed or not, along with a `Dict` (used as a response to the WebHook endpoint).
3232

33-
1. Use the `bug` and `event` information to perform the desired processing!
34-
1. List the required Jira permissions to be set on projects that will use this action in the `JIRA_REQUIRED_PERMISSIONS` constant. The list of built-in permissions is [available on Atlanssian API docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-permission-schemes/#built-in-permissions).
33+
1. Use the `context.bug`, `context.event`, `context.jira` information to perform the desired processing!
34+
1. List the required Jira permissions to be set on projects that will use this action in the `JIRA_REQUIRED_PERMISSIONS` constant. The list of built-in permissions is [available on Atlassian API docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-permission-schemes/#built-in-permissions).
3535
1. Use the available service calls from `jbi/services` (or make new ones)
3636
1. Update the `README.md` to document your action
3737
1. Now the action `jbi.actions.my_team_actions` can be used in the YAML configuration, under the `module` key.

0 commit comments

Comments
 (0)