Skip to content

Commit c323026

Browse files
authored
Allow disabling syncing whiteboard fields to Jira. Fixes #201 (#206)
* Allow changing or disabling the field used to store status whiteboard labels. Fixes #201 * Disable label syncing for flowstate.
1 parent e852d9f commit c323026

File tree

6 files changed

+64
-13
lines changed

6 files changed

+64
-13
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": 194
125+
"line_number": 211
126126
}
127127
]
128128
},
129-
"generated_at": "2022-07-28T11:58:31Z"
129+
"generated_at": "2022-08-17T08:30:43Z"
130130
}

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ It will also set the Jira issue URL in the Bugzilla bug `see_also` field.
7474
- `jira_project_key`
7575
- string
7676
- The Jira project identifier
77+
- `sync_whiteboard_labels`
78+
- boolean
79+
- Whether to sync the Bugzilla status whiteboard labels to Jira. Defaults to `true`.
7780

7881
Example configuration:
7982
```yaml
@@ -85,6 +88,17 @@ Example configuration:
8588
jira_project_key: EXMPL
8689
```
8790

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+
88102
### Default with assignee and status action
89103
The `jbi.actions.default_with_assignee_and_status` action adds some additional
90104
features on top of the default.
@@ -101,6 +115,9 @@ If configured, the action supports setting the Jira issues's status when the Bug
101115
- `jira_project_key`
102116
- string
103117
- The Jira project identifier
118+
- `sync_whiteboard_labels`
119+
- boolean
120+
- Whether to sync the Bugzilla status whiteboard labels to Jira. Defaults to `true`.
104121
- `status_map` (optional)
105122
- mapping [str, str]
106123
- If defined, map the Bugzilla bug status to Jira issue status

config/config.prod.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
module: jbi.actions.default_with_assignee_and_status
4141
parameters:
4242
jira_project_key: MR2
43+
sync_whiteboard_labels: false
4344
status_map:
4445
ASSIGNED: In Progress
4546
FIXED: In Review

jbi/actions/default.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""
22
Default action is listed below.
33
`init` is required; and requires at minimum the `jira_project_key` parameter.
4+
The `label_field` parameter configures which Jira field is used to store the
5+
labels generated from the Bugzilla status whiteboard.
46
57
`init` should return a __call__able
68
"""
79
import logging
10+
from typing import Any
811

912
from jbi import ActionResult, Operation
1013
from jbi.environment import get_settings
@@ -25,9 +28,13 @@
2528
}
2629

2730

28-
def init(jira_project_key, **kwargs):
31+
def init(jira_project_key, sync_whiteboard_labels=True, **kwargs):
2932
"""Function that takes required and optional params and returns a callable object"""
30-
return DefaultExecutor(jira_project_key=jira_project_key, **kwargs)
33+
return DefaultExecutor(
34+
jira_project_key=jira_project_key,
35+
sync_whiteboard_labels=sync_whiteboard_labels,
36+
**kwargs,
37+
)
3138

3239

3340
class DefaultExecutor:
@@ -36,6 +43,7 @@ class DefaultExecutor:
3643
def __init__(self, jira_project_key, **kwargs):
3744
"""Initialize DefaultExecutor Object"""
3845
self.jira_project_key = jira_project_key
46+
self.sync_whiteboard_labels = kwargs.get("sync_whiteboard_labels", True)
3947

4048
self.bugzilla_client = get_bugzilla()
4149
self.jira_client = get_jira()
@@ -100,6 +108,17 @@ def comment_create_or_noop(self, payload: BugzillaWebhookRequest) -> ActionResul
100108
)
101109
return True, {"jira_response": jira_response}
102110

111+
def jira_fields(self, bug_obj: BugzillaBug):
112+
"""Extract bug info as jira issue dictionary"""
113+
fields: dict[str, Any] = {
114+
"summary": bug_obj.summary,
115+
}
116+
117+
if self.sync_whiteboard_labels:
118+
fields["labels"] = bug_obj.get_jira_labels()
119+
120+
return fields
121+
103122
def jira_comments_for_update(
104123
self,
105124
payload: BugzillaWebhookRequest,
@@ -143,7 +162,7 @@ def bug_create_or_update(
143162
},
144163
)
145164
jira_response_update = self.jira_client.update_issue_field(
146-
key=linked_issue_key, fields=bug_obj.map_as_jira_issue()
165+
key=linked_issue_key, fields=self.jira_fields(bug_obj)
147166
)
148167

149168
comments = self.jira_comments_for_update(payload)
@@ -193,7 +212,7 @@ def create_and_link_issue( # pylint: disable=too-many-locals
193212
]
194213

195214
fields = {
196-
**bug_obj.map_as_jira_issue(), # type: ignore
215+
**self.jira_fields(bug_obj), # type: ignore
197216
"issuetype": {"name": bug_obj.issue_type()},
198217
"description": description,
199218
"project": {"key": self.jira_project_key},

jbi/models.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,6 @@ def issue_type(self) -> str:
266266
type_map: dict = {"enhancement": "Task", "task": "Task", "defect": "Bug"}
267267
return type_map.get(self.type, "Task")
268268

269-
def map_as_jira_issue(self) -> dict:
270-
"""Extract bug info as jira issue dictionary"""
271-
return {
272-
"summary": self.summary,
273-
"labels": self.get_jira_labels(),
274-
}
275-
276269
def extract_from_see_also(self):
277270
"""Extract Jira Issue Key from see_also if jira url present"""
278271
if not self.see_also and len(self.see_also) > 0:

tests/unit/actions/test_default.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,24 @@ def test_jira_returns_an_error(
202202
callable_object(payload=webhook_create_example)
203203

204204
assert str(exc_info.value) == "response contains error: {'errors': ['Boom']}"
205+
206+
207+
def test_disabled_label_field(
208+
webhook_create_example: BugzillaWebhookRequest, mocked_jira, mocked_bugzilla
209+
):
210+
mocked_bugzilla.getbug.return_value = webhook_create_example.bug
211+
mocked_bugzilla.get_comments.return_value = {
212+
"bugs": {"654321": {"comments": [{"text": "Initial comment"}]}}
213+
}
214+
callable_object = default.init(jira_project_key="JBI", sync_whiteboard_labels=False)
215+
216+
callable_object(payload=webhook_create_example)
217+
218+
mocked_jira.create_issue.assert_called_once_with(
219+
fields={
220+
"summary": "JBI Test",
221+
"issuetype": {"name": "Bug"},
222+
"description": "Initial comment",
223+
"project": {"key": "JBI"},
224+
},
225+
)

0 commit comments

Comments
 (0)