Skip to content

Commit 743ea8d

Browse files
authored
Fix #517: decouple labels from create_issue and update_issue steps (#527)
* Remove option from create_issue code * Move labels sync to its own step * Rename update_issue to update_issue_summary
1 parent 04821cf commit 743ea8d

File tree

8 files changed

+130
-101
lines changed

8 files changed

+130
-101
lines changed

config/config.nonprod.yaml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
- maybe_assign_jira_user
2222
- maybe_update_issue_resolution
2323
- maybe_update_issue_status
24+
- sync_whiteboard_labels
2425
existing:
25-
- update_issue
26+
- update_issue_summary
2627
- maybe_assign_jira_user
2728
- maybe_update_issue_resolution
2829
- maybe_update_issue_status
30+
- sync_whiteboard_labels
2931
status_map:
3032
ASSIGNED: In Progress
3133
FIXED: In Review
@@ -45,11 +47,13 @@
4547
- maybe_assign_jira_user
4648
- maybe_update_issue_resolution
4749
- maybe_update_issue_status
50+
- sync_whiteboard_labels
4851
existing:
49-
- update_issue
52+
- update_issue_summary
5053
- maybe_assign_jira_user
5154
- maybe_update_issue_resolution
5255
- maybe_update_issue_status
56+
- sync_whiteboard_labels
5357
status_map:
5458
ASSIGNED: To Do
5559
REOPENED: To Do
@@ -77,10 +81,12 @@
7781
- add_link_to_jira
7882
- maybe_assign_jira_user
7983
- maybe_update_issue_status
84+
- sync_whiteboard_labels
8085
existing:
81-
- update_issue
86+
- update_issue_summary
8287
- maybe_assign_jira_user
8388
- maybe_update_issue_status
89+
- sync_whiteboard_labels
8490
status_map:
8591
UNCONFIRMED: Backlog
8692
NEW: Backlog
@@ -111,11 +117,13 @@
111117
- maybe_assign_jira_user
112118
- maybe_update_issue_resolution
113119
- maybe_update_issue_status
120+
- sync_whiteboard_labels
114121
existing:
115-
- update_issue
122+
- update_issue_summary
116123
- maybe_assign_jira_user
117124
- maybe_update_issue_resolution
118125
- maybe_update_issue_status
126+
- sync_whiteboard_labels
119127
comment:
120128
- create_comment
121129
status_map:
@@ -148,11 +156,13 @@
148156
- maybe_assign_jira_user
149157
- maybe_update_issue_resolution
150158
- maybe_update_issue_status
159+
- sync_whiteboard_labels
151160
existing:
152-
- update_issue
161+
- update_issue_summary
153162
- maybe_assign_jira_user
154163
- maybe_update_issue_resolution
155164
- maybe_update_issue_status
165+
- sync_whiteboard_labels
156166
comment:
157167
- create_comment
158168
status_map:
@@ -189,7 +199,7 @@
189199
- maybe_update_issue_resolution
190200
- maybe_update_issue_status
191201
existing:
192-
- update_issue
202+
- update_issue_summary
193203
- maybe_assign_jira_user
194204
- maybe_update_issue_resolution
195205
- maybe_update_issue_status
@@ -210,7 +220,6 @@
210220
WORKSFORME: Done
211221
INCOMPLETE: Done
212222
MOVED: Done
213-
sync_whiteboard_labels: false
214223

215224
- whiteboard_tag: dataquality
216225
bugzilla_user_id: tbd
@@ -230,7 +239,7 @@
230239
- maybe_update_issue_resolution
231240
- maybe_update_issue_status
232241
existing:
233-
- update_issue
242+
- update_issue_summary
234243
- maybe_assign_jira_user
235244
- maybe_update_issue_resolution
236245
- maybe_update_issue_status
@@ -251,4 +260,3 @@
251260
WORKSFORME: Done
252261
INCOMPLETE: Done
253262
MOVED: Done
254-
sync_whiteboard_labels: false

config/config.prod.yaml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
- maybe_assign_jira_user
2828
- maybe_update_issue_resolution
2929
- maybe_update_issue_status
30+
- sync_whiteboard_labels
3031
existing:
31-
- update_issue
32+
- update_issue_summary
3233
- maybe_assign_jira_user
3334
- maybe_update_issue_resolution
3435
- maybe_update_issue_status
36+
- sync_whiteboard_labels
3537
status_map:
3638
ASSIGNED: In Progress
3739
FIXED: Closed
@@ -57,11 +59,10 @@
5759
- maybe_update_issue_resolution
5860
- maybe_update_issue_status
5961
existing:
60-
- update_issue
62+
- update_issue_summary
6163
- maybe_assign_jira_user
6264
- maybe_update_issue_resolution
6365
- maybe_update_issue_status
64-
sync_whiteboard_labels: false
6566
status_map:
6667
ASSIGNED: In Progress
6768
FIXED: In Review
@@ -87,11 +88,13 @@
8788
- maybe_assign_jira_user
8889
- maybe_update_issue_resolution
8990
- maybe_update_issue_status
91+
- sync_whiteboard_labels
9092
existing:
91-
- update_issue
93+
- update_issue_summary
9294
- maybe_assign_jira_user
9395
- maybe_update_issue_resolution
9496
- maybe_update_issue_status
97+
- sync_whiteboard_labels
9598
status_map:
9699
ASSIGNED: To Do
97100
REOPENED: To Do
@@ -119,10 +122,12 @@
119122
- add_link_to_jira
120123
- maybe_assign_jira_user
121124
- maybe_update_issue_status
125+
- sync_whiteboard_labels
122126
existing:
123-
- update_issue
127+
- update_issue_summary
124128
- maybe_assign_jira_user
125129
- maybe_update_issue_status
130+
- sync_whiteboard_labels
126131
status_map:
127132
UNCONFIRMED: Backlog
128133
NEW: Backlog
@@ -153,11 +158,13 @@
153158
- maybe_assign_jira_user
154159
- maybe_update_issue_resolution
155160
- maybe_update_issue_status
161+
- sync_whiteboard_labels
156162
existing:
157-
- update_issue
163+
- update_issue_summary
158164
- maybe_assign_jira_user
159165
- maybe_update_issue_resolution
160166
- maybe_update_issue_status
167+
- sync_whiteboard_labels
161168
comment:
162169
- create_comment
163170
status_map:
@@ -232,9 +239,11 @@
232239
- maybe_update_components
233240
- add_link_to_bugzilla
234241
- add_link_to_jira
242+
- sync_whiteboard_labels
235243
existing:
236-
- update_issue
244+
- update_issue_summary
237245
- add_jira_comments_for_changes
246+
- sync_whiteboard_labels
238247
comment:
239248
- create_comment
240249

@@ -258,11 +267,13 @@
258267
- maybe_assign_jira_user
259268
- maybe_update_issue_resolution
260269
- maybe_update_issue_status
270+
- sync_whiteboard_labels
261271
existing:
262-
- update_issue
272+
- update_issue_summary
263273
- maybe_assign_jira_user
264274
- maybe_update_issue_resolution
265275
- maybe_update_issue_status
276+
- sync_whiteboard_labels
266277
comment:
267278
- create_comment
268279
status_map:
@@ -299,7 +310,7 @@
299310
- maybe_update_issue_resolution
300311
- maybe_update_issue_status
301312
existing:
302-
- update_issue
313+
- update_issue_summary
303314
- maybe_assign_jira_user
304315
- maybe_update_issue_resolution
305316
- maybe_update_issue_status
@@ -320,7 +331,6 @@
320331
WORKSFORME: Done
321332
INCOMPLETE: Done
322333
MOVED: Done
323-
sync_whiteboard_labels: false
324334

325335

326336
- whiteboard_tag: dataquality
@@ -341,7 +351,7 @@
341351
- maybe_update_issue_resolution
342352
- maybe_update_issue_status
343353
existing:
344-
- update_issue
354+
- update_issue_summary
345355
- maybe_assign_jira_user
346356
- maybe_update_issue_resolution
347357
- maybe_update_issue_status
@@ -362,4 +372,3 @@
362372
WORKSFORME: Done
363373
INCOMPLETE: Done
364374
MOVED: Done
365-
sync_whiteboard_labels: false

docs/actions.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ 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-
- `sync_whiteboard_labels` (optional)
76-
- boolean
77-
- Whether to sync the Bugzilla status whiteboard labels to Jira. Defaults to `true`.
7875
- `status_map` (optional)
7976
- mapping [str, str]
8077
- If defined, map the Bugzilla bug status (or resolution) to Jira issue status

jbi/actions/default.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
"maybe_delete_duplicate",
3232
"add_link_to_bugzilla",
3333
"add_link_to_jira",
34+
"sync_whiteboard_labels",
3435
],
3536
"existing": [
36-
"update_issue",
37+
"update_issue_summary",
38+
"sync_whiteboard_labels",
3739
"add_jira_comments_for_changes",
3840
],
3941
"comment": [

jbi/actions/steps.py

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import logging
88

9+
from requests import exceptions as requests_exceptions
10+
911
from jbi import Operation
1012
from jbi.models import ActionContext
1113
from jbi.services import bugzilla, jira
@@ -30,19 +32,14 @@ def create_comment(context: ActionContext, **parameters):
3032

3133
def create_issue(context: ActionContext, **parameters):
3234
"""Create the Jira issue with the first comment as the description."""
33-
sync_whiteboard_labels: bool = parameters.get("sync_whiteboard_labels", True)
3435
bug = context.bug
3536

3637
# In the payload of a bug creation, the `comment` field is `null`.
3738
# We fetch the list of comments to use the first one as the Jira issue description.
3839
comment_list = bugzilla.get_client().get_comments(bug.id)
3940
description = comment_list[0].text if comment_list else ""
4041

41-
jira_create_response = jira.create_jira_issue(
42-
context,
43-
description,
44-
sync_whiteboard_labels=sync_whiteboard_labels,
45-
)
42+
jira_create_response = jira.create_jira_issue(context, description)
4643
issue_key = jira_create_response.get("key")
4744

4845
context = context.update(jira=context.jira.update(issue=issue_key))
@@ -74,13 +71,25 @@ def maybe_delete_duplicate(context: ActionContext, **parameters):
7471
return context, ()
7572

7673

77-
def update_issue(context: ActionContext, **parameters):
78-
"""Update the Jira issue's summary and labels if the linked bug is modified."""
79-
sync_whiteboard_labels: bool = parameters.get("sync_whiteboard_labels", True)
80-
81-
resp = jira.update_jira_issue(context, sync_whiteboard_labels)
74+
def update_issue_summary(context: ActionContext, **parameters):
75+
"""Update the Jira issue's summary if the linked bug is modified."""
8276

83-
return context, (resp,)
77+
bug = context.bug
78+
issue_key = context.jira.issue
79+
logger.debug(
80+
"Update summary of Jira issue %s for Bug %s",
81+
issue_key,
82+
bug.id,
83+
extra=context.dict(),
84+
)
85+
truncated_summary = (bug.summary or "")[: jira.JIRA_DESCRIPTION_CHAR_LIMIT]
86+
fields: dict[str, str] = {
87+
"summary": truncated_summary,
88+
}
89+
jira_response_update = jira.get_client().update_issue_field(
90+
key=issue_key, fields=fields
91+
)
92+
return context, (jira_response_update,)
8493

8594

8695
def add_jira_comments_for_changes(context: ActionContext, **parameters):
@@ -233,3 +242,27 @@ def maybe_update_components(context: ActionContext, **parameters):
233242
key=context.jira.issue, fields={"components": jira_components}
234243
)
235244
return context, (resp,)
245+
246+
247+
def sync_whiteboard_labels(context: ActionContext, **parameters):
248+
"""
249+
Set whiteboard tags as labels on the Jira issue
250+
"""
251+
try:
252+
# Note: fetch existing first, see mozilla/jira-bugzilla-integration#393
253+
resp = jira.get_client().update_issue_field(
254+
key=context.jira.issue, fields={"labels": context.bug.get_jira_labels()}
255+
)
256+
except requests_exceptions.HTTPError as exc:
257+
if exc.response.status_code != 400:
258+
raise
259+
# If `labels` is not a valid field in this project, then warn developers
260+
# and ignore the error.
261+
logger.error(
262+
f"Could not set labels on issue {context.jira.issue}: %s",
263+
str(exc),
264+
extra=context.dict(),
265+
)
266+
return context, ()
267+
268+
return context, (resp,)

jbi/services/jira.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,8 @@ class JiraCreateError(Exception):
221221
def create_jira_issue(
222222
context: ActionContext,
223223
description: str,
224-
sync_whiteboard_labels: bool,
225224
):
226-
"""Create a Jira issue with the specified fields and return its key."""
225+
"""Create a Jira issue with basic fields in the project and return its key."""
227226
bug = context.bug
228227
logger.debug(
229228
"Create new Jira issue for Bug %s",
@@ -236,8 +235,6 @@ def create_jira_issue(
236235
"description": description[:JIRA_DESCRIPTION_CHAR_LIMIT],
237236
"project": {"key": context.jira.project},
238237
}
239-
if sync_whiteboard_labels:
240-
fields["labels"] = bug.get_jira_labels()
241238

242239
client = get_client()
243240

@@ -258,26 +255,6 @@ def create_jira_issue(
258255
return jira_response_create
259256

260257

261-
def update_jira_issue(context: ActionContext, sync_whiteboard_labels):
262-
"""Update the fields of an existing Jira issue"""
263-
bug = context.bug
264-
issue_key = context.jira.issue
265-
logger.debug(
266-
"Update fields of Jira issue %s for Bug %s",
267-
issue_key,
268-
bug.id,
269-
extra=context.dict(),
270-
)
271-
fields: dict[str, Any] = {
272-
"summary": bug.summary,
273-
}
274-
if sync_whiteboard_labels:
275-
fields["labels"] = bug.get_jira_labels()
276-
277-
jira_response_update = get_client().update_issue_field(key=issue_key, fields=fields)
278-
return jira_response_update
279-
280-
281258
def add_jira_comment(context: ActionContext):
282259
"""Publish a comment on the specified Jira issue"""
283260
context = context.update(operation=Operation.COMMENT)

0 commit comments

Comments
 (0)