Skip to content

Commit e9a067f

Browse files
authored
Fix #521: do not add brackets on issue labels by default (#559)
* Fix #521: add option to control brackets on issue labels * Add missing test for ValueError * Change default value to "no"
1 parent 3574a3a commit e9a067f

File tree

5 files changed

+93
-10
lines changed

5 files changed

+93
-10
lines changed

config/config.nonprod.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
description: Nonprod testing whiteboard tag (JBI Bin Project)
66
parameters:
77
jira_project_key: JB
8+
labels_brackets: both
89

910
- whiteboard_tag: flowstate
1011
allow_private: true
@@ -28,6 +29,7 @@
2829
- maybe_update_issue_resolution
2930
- maybe_update_issue_status
3031
- sync_whiteboard_labels
32+
labels_brackets: both
3133
status_map:
3234
ASSIGNED: In Progress
3335
FIXED: In Review
@@ -54,6 +56,7 @@
5456
- maybe_update_issue_resolution
5557
- maybe_update_issue_status
5658
- sync_whiteboard_labels
59+
labels_brackets: both
5760
status_map:
5861
ASSIGNED: To Do
5962
REOPENED: To Do
@@ -87,6 +90,7 @@
8790
- maybe_assign_jira_user
8891
- maybe_update_issue_status
8992
- sync_whiteboard_labels
93+
labels_brackets: both
9094
status_map:
9195
UNCONFIRMED: Backlog
9296
NEW: Backlog
@@ -128,6 +132,7 @@
128132
- sync_whiteboard_labels
129133
comment:
130134
- create_comment
135+
labels_brackets: both
131136
status_map:
132137
UNCONFIRMED: Backlog
133138
NEW: Backlog
@@ -167,6 +172,7 @@
167172
- sync_whiteboard_labels
168173
comment:
169174
- create_comment
175+
labels_brackets: both
170176
status_map:
171177
UNCONFIRMED: To Do
172178
NEW: To Do
@@ -207,6 +213,7 @@
207213
- maybe_update_issue_status
208214
comment:
209215
- create_comment
216+
labels_brackets: both
210217
status_map:
211218
UNCONFIRMED: Backlog
212219
NEW: Backlog
@@ -247,6 +254,7 @@
247254
- maybe_update_issue_status
248255
comment:
249256
- create_comment
257+
labels_brackets: both
250258
status_map:
251259
UNCONFIRMED: To Do
252260
NEW: To Do

config/config.prod.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
# module: jbi.actions.default
77
parameters:
88
jira_project_key: WEBEXT
9+
labels_brackets: both
910

1011
- whiteboard_tag: fidedi
1112
bugzilla_user_id: tbd
1213
description: Firefox Desktop Integration whiteboard tag
1314
parameters:
1415
jira_project_key: FIDEDI
16+
labels_brackets: both
1517

1618
- whiteboard_tag: fidefe
1719
bugzilla_user_id: 159069
@@ -33,7 +35,8 @@
3335
- maybe_assign_jira_user
3436
- maybe_update_issue_resolution
3537
- maybe_update_issue_status
36-
- sync_whiteboard_labels
38+
- sync_whiteboard_label
39+
labels_brackets: both
3740
status_map:
3841
ASSIGNED: In Progress
3942
FIXED: Closed
@@ -73,6 +76,7 @@
7376
description: Privacy & Security and Anti-Tracking Team whiteboard tag
7477
parameters:
7578
jira_project_key: FXATPS
79+
labels_brackets: both
7680

7781
- whiteboard_tag: fxcm
7882
bugzilla_user_id: 713707
@@ -95,6 +99,7 @@
9599
- maybe_update_issue_resolution
96100
- maybe_update_issue_status
97101
- sync_whiteboard_labels
102+
labels_brackets: both
98103
status_map:
99104
ASSIGNED: To Do
100105
REOPENED: To Do
@@ -128,6 +133,7 @@
128133
- maybe_assign_jira_user
129134
- maybe_update_issue_status
130135
- sync_whiteboard_labels
136+
labels_brackets: both
131137
status_map:
132138
UNCONFIRMED: Backlog
133139
NEW: Backlog
@@ -169,6 +175,7 @@
169175
- sync_whiteboard_labels
170176
comment:
171177
- create_comment
178+
labels_brackets: both
172179
status_map:
173180
UNCONFIRMED: Backlog
174181
NEW: Backlog
@@ -190,48 +197,56 @@
190197
description: Firefox Sync Team whiteboard tag
191198
parameters:
192199
jira_project_key: SYNC
200+
labels_brackets: both
193201

194202
- whiteboard_tag: disco
195203
bugzilla_user_id: 624105
196204
description: DISCO whiteboard tag
197205
parameters:
198206
jira_project_key: DISCO
207+
labels_brackets: both
199208

200209
- whiteboard_tag: mv3
201210
bugzilla_user_id: tbd
202211
description: MV3 whiteboard tag
203212
parameters:
204213
jira_project_key: WEBEXT
214+
labels_brackets: both
205215

206216
- whiteboard_tag: nimbus
207217
bugzilla_user_id: 624105
208218
description: Nimbus whiteboard tag
209219
parameters:
210220
jira_project_key: EXP
221+
labels_brackets: both
211222

212223
- whiteboard_tag: omc
213224
bugzilla_user_id: 711631
214225
description: Firefox Messaging System whiteboard tag
215226
parameters:
216227
jira_project_key: OMC
228+
labels_brackets: both
217229

218230
- whiteboard_tag: prodtest
219231
bugzilla_user_id: 644672
220232
description: Prod testing whiteboard tag (JBI Bin Project)
221233
parameters:
222234
jira_project_key: JB
235+
labels_brackets: both
223236

224237
- whiteboard_tag: proton
225238
bugzilla_user_id: tbd
226239
description: Proton whiteboard tag for Firefox Frontend
227240
parameters:
228241
jira_project_key: FIDEFE
242+
labels_brackets: both
229243

230244
- whiteboard_tag: relops
231245
bugzilla_user_id: tbd
232246
description: Release Operations Team Tag
233247
parameters:
234248
jira_project_key: RELOPS
249+
labels_brackets: both
235250

236251
- whiteboard_tag: remote-settings
237252
bugzilla_user_id: 576226
@@ -254,12 +269,14 @@
254269
- sync_whiteboard_labels
255270
comment:
256271
- create_comment
272+
labels_brackets: both
257273

258274
- whiteboard_tag: sng
259275
bugzilla_user_id: 696039
260276
description: Search Next Generation Team Tag
261277
parameters:
262278
jira_project_key: SNG
279+
labels_brackets: both
263280

264281
- whiteboard_tag: sp3
265282
bugzilla_user_id: 396948
@@ -284,6 +301,7 @@
284301
- sync_whiteboard_labels
285302
comment:
286303
- create_comment
304+
labels_brackets: both
287305
status_map:
288306
UNCONFIRMED: To Do
289307
NEW: To Do

docs/actions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ to the Bugzilla ticket on the Jira issue.
7272
- `jira_components` (optional)
7373
- list [str]
7474
- If defined, the created issues will be assigned the specified components.
75+
- `labels_brackets` (optional)
76+
- enum ["yes", "no", "both"]
77+
- Controls whether issue labels should have brackets or not in the `sync_whiteboard_labels` step (default: "no")
7578
- `status_map` (optional)
7679
- mapping [str, str]
7780
- If defined, map the Bugzilla bug status (or resolution) to Jira issue status
@@ -159,6 +162,7 @@ linked Jira issue status to "Closed". If the bug changes to a status not listed
159162
- `maybe_update_issue_resolution`
160163
- `maybe_update_issue_status`
161164
- `create_comment`
165+
- `sync_whiteboard_labels`
162166
- `maybe_update_components`: looks at the component that's set on the bug (if any) and any components added to the project configuration with the `jira_components` parameter (see above). If those components are available on the Jira side as well, they're added to the Jira issue
163167

164168
### Custom Actions

jbi/actions/steps.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,22 +260,30 @@ def maybe_update_components(context: ActionContext, **parameters):
260260
return context, (resp,)
261261

262262

263-
def _whiteboard_as_labels(whiteboard: Optional[str]) -> list[str]:
263+
def _whiteboard_as_labels(labels_brackets: str, whiteboard: Optional[str]) -> list[str]:
264264
"""Split the whiteboard string into a list of labels"""
265265
splitted = whiteboard.replace("[", "").split("]") if whiteboard else []
266266
stripped = [x.strip() for x in splitted if x not in ["", " "]]
267267
# Jira labels can't contain a " ", convert to "."
268268
nospace = [wb.replace(" ", ".") for wb in stripped]
269269
with_brackets = [f"[{wb}]" for wb in nospace]
270-
return ["bugzilla"] + nospace + with_brackets
270+
271+
if labels_brackets == "yes":
272+
labels = with_brackets
273+
elif labels_brackets == "both":
274+
labels = nospace + with_brackets
275+
else:
276+
labels = nospace
277+
278+
return ["bugzilla"] + labels
271279

272280

273-
def _build_labels_update(added, removed=None):
274-
after = _whiteboard_as_labels(added)
281+
def _build_labels_update(labels_brackets, added, removed=None):
282+
after = _whiteboard_as_labels(labels_brackets, added)
275283
# We don't bother detecting if label was already there.
276284
updates = [{"add": label} for label in after]
277285
if removed:
278-
before = _whiteboard_as_labels(removed)
286+
before = _whiteboard_as_labels(labels_brackets, removed)
279287
deleted = sorted(set(before).difference(set(after))) # sorted for unit testing
280288
updates.extend([{"remove": label} for label in deleted])
281289
return updates
@@ -285,18 +293,29 @@ def sync_whiteboard_labels(context: ActionContext, **parameters):
285293
"""
286294
Set whiteboard tags as labels on the Jira issue
287295
"""
296+
labels_brackets = parameters.get("labels_brackets", "no")
297+
if labels_brackets not in ("yes", "no", "both"):
298+
raise ValueError(
299+
f"Invalid value {labels_brackets} for 'labels_brackets' parameter."
300+
)
288301

289302
# On update of whiteboard field, add/remove corresponding labels
290303
if context.event.changes:
291304
changes_by_field = {change.field: change for change in context.event.changes}
292305
if change := changes_by_field.get("whiteboard"):
293-
updates = _build_labels_update(added=change.added, removed=change.removed)
306+
updates = _build_labels_update(
307+
added=change.added,
308+
removed=change.removed,
309+
labels_brackets=labels_brackets,
310+
)
294311
else:
295312
# Whiteboard field not changed, ignore.
296313
return context, ()
297314
else:
298315
# On creation, just add them all.
299-
updates = _build_labels_update(added=context.bug.whiteboard)
316+
updates = _build_labels_update(
317+
added=context.bug.whiteboard, labels_brackets=labels_brackets
318+
)
300319

301320
try:
302321
resp = jira.get_client().update_issue(

tests/unit/actions/test_steps.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,29 @@ def test_sync_whiteboard_labels(context_create_example: ActionContext, mocked_ji
569569
)
570570
callable_object(context=context_create_example)
571571

572+
mocked_jira.update_issue.assert_called_once_with(
573+
issue_key=context_create_example.jira.issue,
574+
update={
575+
"update": {
576+
"labels": [
577+
{"add": "bugzilla"},
578+
{"add": "devtest"},
579+
]
580+
}
581+
},
582+
)
583+
584+
585+
def test_sync_whiteboard_labels_with_brackets(
586+
context_create_example: ActionContext, mocked_jira
587+
):
588+
callable_object = default.init(
589+
jira_project_key=context_create_example.jira.project,
590+
steps={"new": ["sync_whiteboard_labels"]},
591+
labels_brackets="both",
592+
)
593+
callable_object(context=context_create_example)
594+
572595
mocked_jira.update_issue.assert_called_once_with(
573596
issue_key=context_create_example.jira.issue,
574597
update={
@@ -583,6 +606,19 @@ def test_sync_whiteboard_labels(context_create_example: ActionContext, mocked_ji
583606
)
584607

585608

609+
def test_sync_whiteboard_labels_misconfigured_brackets(
610+
context_create_example: ActionContext,
611+
):
612+
callable_object = default.init(
613+
jira_project_key=context_create_example.jira.project,
614+
steps={"new": ["sync_whiteboard_labels"]},
615+
labels_brackets=42,
616+
)
617+
with pytest.raises(ValueError) as exc_info:
618+
callable_object(context=context_create_example)
619+
assert str(exc_info.value) == "Invalid value 42 for 'labels_brackets' parameter."
620+
621+
586622
def test_sync_whiteboard_labels_update(
587623
context_update_example: ActionContext, mocked_jira
588624
):
@@ -607,8 +643,6 @@ def test_sync_whiteboard_labels_update(
607643
"labels": [
608644
{"add": "bugzilla"},
609645
{"add": "remotesettings"},
610-
{"add": "[remotesettings]"},
611-
{"remove": "[server]"},
612646
{"remove": "server"},
613647
]
614648
}

0 commit comments

Comments
 (0)