Skip to content

Commit

Permalink
Merge pull request #239 from release-engineering/fix-string-storypoints
Browse files Browse the repository at this point in the history
Workaround for FedMsg storypoint (str) values
  • Loading branch information
webbnh authored Nov 27, 2024
2 parents 1aa6e2b + bd8a03b commit 6860436
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
33 changes: 24 additions & 9 deletions sync2jira/downstream_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,14 @@ def _update_github_project_fields(client, existing, issue,
for name, values in github_project_fields.items():
fieldvalue = getattr(issue, name)
if name == 'storypoints':
if not isinstance(fieldvalue, int):
# FIXME: The intermediate issue _should_ have either a number
# or None for this value, but the code isn't complete yet; so,
# until that is addressed, cover for it here.
try:
fieldvalue = int(fieldvalue)
except (TypeError, ValueError):
continue
try:
jirafieldname = default_jira_fields['storypoints']
except KeyError:
Expand All @@ -987,20 +995,27 @@ def _update_github_project_fields(client, existing, issue,
try:
existing.update({jirafieldname: fieldvalue})
except JIRAError as err:
# Add a comment to indicate there was an issue
client.add_comment(existing, f"Error updating GitHub project storypoints field: {err}")
# Note the failure in a comment to the downstream issue
client.add_comment(
existing,
"Error updating GitHub project storypoints field ({}: {}): {}".format(
jirafieldname, fieldvalue, err))
elif name == 'priority':
jira_priority = values.get('options', {}).get(fieldvalue)
if not jira_priority:
continue
try:
jirafieldname = default_jira_fields['priority']
except KeyError:
jirafieldname = 'priority'
jira_priority = values.get('options', {}).get(fieldvalue)
if jira_priority:
try:
existing.update({jirafieldname: {'name': jira_priority}})
except JIRAError as err:
# Add a comment to indicate there was an issue
client.add_comment(existing, f"Error updating GitHub project priority field: {err}")
try:
existing.update({jirafieldname: {'name': jira_priority}})
except JIRAError as err:
# Note the failure in a comment to the downstream issue
client.add_comment(
existing,
"Error updating GitHub project priority field ({}: {}): {}".format(
jirafieldname, jira_priority, err))


def _update_tags(updates, existing, issue):
Expand Down
37 changes: 37 additions & 0 deletions tests/test_downstream_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,19 @@ def test_update_github_project_fields_storypoints(self, mock_client):
github_project_fields, self.mock_config)
self.mock_downstream.update.assert_called_with({'customfield_12310243': 2})

@mock.patch('jira.client.JIRA')
def test_update_github_project_fields_storypoints_bad(self, mock_client):
"""This function tests `_update_github_project_fields` with
a bad (non-numeric) story points value.
"""
github_project_fields = {"storypoints": {"gh_field": "Estimate"}}
for bad_sp in [None, '', 'bad_value']:
self.mock_issue.storypoints = bad_sp
d._update_github_project_fields(
mock_client, self.mock_downstream, self.mock_issue,
github_project_fields, self.mock_config)
self.mock_downstream.update.assert_not_called()
mock_client.add_comment.assert_not_called()

@mock.patch('jira.client.JIRA')
def test_update_github_project_fields_priority(self, mock_client):
Expand All @@ -1709,3 +1722,27 @@ def test_update_github_project_fields_priority(self, mock_client):
d._update_github_project_fields(mock_client, self.mock_downstream, self.mock_issue,
github_project_fields, self.mock_config)
self.mock_downstream.update.assert_called_with({'priority': {'name': 'Critical'}})

@mock.patch('jira.client.JIRA')
def test_update_github_project_fields_priority_bad(self, mock_client):
"""This function tests `_update_github_project_fields` with
a bad priority value.
"""
github_project_fields = {
"priority": {
"gh_field": "Priority",
"options": {
"P0": "Blocker",
"P1": "Critical",
"P2": "Major",
"P3": "Minor",
"P4": "Optional",
"P5": "Trivial"
}}}
for bad_pv in [None, '', 'bad_value']:
self.mock_issue.priority = bad_pv
d._update_github_project_fields(
mock_client, self.mock_downstream, self.mock_issue,
github_project_fields, self.mock_config)
self.mock_downstream.update.assert_not_called()
mock_client.add_comment.assert_not_called()

0 comments on commit 6860436

Please sign in to comment.