Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

Windows platform label to component in Jira #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions sync_issues_to_jira/sync_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def handle_issue_labeled(jira, event):
if _check_issue_label(new_label) is None:
return

if new_label.lower() == "windows: platform":
os.environ['JIRA_COMPONENT'] = 'windows platform'
_update_components_field(jira, {}, jira_issue)
return

if new_label not in labels:
labels.append(new_label)
jira_issue.update(fields={"labels": labels})
Expand Down Expand Up @@ -136,16 +141,6 @@ def handle_comment_deleted(jira, event):
jira_issue = _find_jira_issue(jira, event["issue"], True)
jira.add_comment(jira_issue.id, "@%s deleted [GitHub issue comment|%s]" % (gh_comment["user"]["login"], gh_comment["html_url"]))

def _check_issue_label(label):
"""
Ignore labels that start with "Status:" and "Resolution:". These labels are
mirrored from Jira issue and should not be mirrored back as labels
"""
ignore_prefix = ("status:", "resolution:")
if label.lower().startswith(ignore_prefix):
return None

return label

def _update_link_resolved(jira, gh_issue, jira_issue):
"""
Expand Down Expand Up @@ -250,6 +245,10 @@ def _create_jira_issue(jira, gh_issue):
if issuetype is None:
issuetype = os.environ.get('JIRA_ISSUE_TYPE', 'Task')

for l in gh_issue["labels"]:
if l["name"].lower() == "platform: windows":
os.environ['JIRA_COMPONENT'] = 'windows platform'

fields = {
"summary": _get_summary(gh_issue),
"project": os.environ['JIRA_PROJECT'],
Expand Down Expand Up @@ -458,4 +457,21 @@ def _get_jira_comment_body(gh_comment, body=None):

def _get_jira_label(gh_label):
""" Reformat a github API label item as something suitable for JIRA """
# ignore status, resolution and platform: windows labels
if _check_issue_label(gh_label["name"]) is None:
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At line 257 the GitHub labels get reformatted into JIRA labels like this:

"labels": [_get_jira_label(l) for l in gh_issue["labels"]],

... returning None here will cause some None values here, possible these are ignored but I think they might cause errors instead.

return gh_label["name"].replace(" ", "-")

def _check_issue_label(label):
"""
Ignore labels that start with "Status:" and "Resolution:". These labels are
mirrored from Jira issue and should not be mirrored back as labels
"""
ignore_prefix = ("status:", "resolution:")
if label.lower().startswith(ignore_prefix):
return None

if label.lower() == "platform: windows":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DRY principle (don't repeat yourself) tells us that any piece of information in a system should have a single source of truth.

In this case this "special" label is encoded in two places, here and on line 74.

What about putting a constant near the top of the file, like this:

# Some GitHub labels are mapped directly to JIRA components
GH_LABEL_TO_JIRA_COMPONENT = {
    "platform: windows": "windows platform"
}

and then can refer to this dict elsewhere, like if label.lower() in GH_LABEL_TO_JIRA_COMPONENT:

return None

return label
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, it's a little odd that this function returns a string or None but result is only ever used as Truthy/Falsy.