This repository was archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Windows platform label to component in Jira #8
Open
tom-borcin
wants to merge
5
commits into
master
Choose a base branch
from
feature/label_to_component
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f3a352f
Windows platform label to component in Jira
tom-borcin f2864cf
forgot to exit function after setting component
tom-borcin ecbf1ae
set windows platform component when creating jira issue
tom-borcin cc721f4
fixed calling lower() on a dict
tom-borcin e5bfd3a
fixed calling lower() on a dict part 2
tom-borcin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}) | ||
|
@@ -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): | ||
""" | ||
|
@@ -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'], | ||
|
@@ -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 | ||
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": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return None | ||
|
||
return label | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
... returning None here will cause some None values here, possible these are ignored but I think they might cause errors instead.