From f3a352fee78badc02718048d670d42f9babe02b4 Mon Sep 17 00:00:00 2001 From: Tomas Borcin Date: Thu, 1 Apr 2021 13:57:01 +0200 Subject: [PATCH 1/5] Windows platform label to component in Jira --- sync_issues_to_jira/sync_issue.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sync_issues_to_jira/sync_issue.py b/sync_issues_to_jira/sync_issue.py index a851cef..d1c6e0e 100755 --- a/sync_issues_to_jira/sync_issue.py +++ b/sync_issues_to_jira/sync_issue.py @@ -71,6 +71,10 @@ 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) + if new_label not in labels: labels.append(new_label) jira_issue.update(fields={"labels": labels}) From f2864cf79e7977f729dac38a69eb77a0d7b12f8c Mon Sep 17 00:00:00 2001 From: Tomas Borcin Date: Thu, 1 Apr 2021 14:03:46 +0200 Subject: [PATCH 2/5] forgot to exit function after setting component --- sync_issues_to_jira/sync_issue.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sync_issues_to_jira/sync_issue.py b/sync_issues_to_jira/sync_issue.py index d1c6e0e..c86186c 100755 --- a/sync_issues_to_jira/sync_issue.py +++ b/sync_issues_to_jira/sync_issue.py @@ -74,6 +74,7 @@ def handle_issue_labeled(jira, event): 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) From ecbf1aefba0a3a0d97a5c7022621b911dd72747a Mon Sep 17 00:00:00 2001 From: Tomas Borcin Date: Thu, 1 Apr 2021 14:30:32 +0200 Subject: [PATCH 3/5] set windows platform component when creating jira issue --- sync_issues_to_jira/sync_issue.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/sync_issues_to_jira/sync_issue.py b/sync_issues_to_jira/sync_issue.py index c86186c..5da1b4d 100755 --- a/sync_issues_to_jira/sync_issue.py +++ b/sync_issues_to_jira/sync_issue.py @@ -141,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): """ @@ -255,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.lower() == "platform: windows": + os.environ['JIRA_COMPONENT'] = 'windows platform' + fields = { "summary": _get_summary(gh_issue), "project": os.environ['JIRA_PROJECT'], @@ -463,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) is None: + return 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": + return None + + return label \ No newline at end of file From cc721f464003bdad72feae0888d3bcd304dfacb4 Mon Sep 17 00:00:00 2001 From: Tomas Borcin Date: Thu, 1 Apr 2021 14:54:09 +0200 Subject: [PATCH 4/5] fixed calling lower() on a dict --- sync_issues_to_jira/sync_issue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync_issues_to_jira/sync_issue.py b/sync_issues_to_jira/sync_issue.py index 5da1b4d..e7deee7 100755 --- a/sync_issues_to_jira/sync_issue.py +++ b/sync_issues_to_jira/sync_issue.py @@ -246,7 +246,7 @@ def _create_jira_issue(jira, gh_issue): issuetype = os.environ.get('JIRA_ISSUE_TYPE', 'Task') for l in gh_issue["labels"]: - if l.lower() == "platform: windows": + if l["name"].lower() == "platform: windows": os.environ['JIRA_COMPONENT'] = 'windows platform' fields = { From e5bfd3a207f00395d1cf416caca09b3358efaa43 Mon Sep 17 00:00:00 2001 From: Tomas Borcin Date: Thu, 1 Apr 2021 15:23:17 +0200 Subject: [PATCH 5/5] fixed calling lower() on a dict part 2 --- sync_issues_to_jira/sync_issue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync_issues_to_jira/sync_issue.py b/sync_issues_to_jira/sync_issue.py index e7deee7..653bd08 100755 --- a/sync_issues_to_jira/sync_issue.py +++ b/sync_issues_to_jira/sync_issue.py @@ -458,7 +458,7 @@ 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) is None: + if _check_issue_label(gh_label["name"]) is None: return return gh_label["name"].replace(" ", "-")