From 157fa555cdc414e813b3a33bee32fef07db6c9a8 Mon Sep 17 00:00:00 2001 From: sidpremkumar Date: Sep 24 2019 17:14:33 +0000 Subject: Add optional flag 'upstream_id' to allow users to search downstream via upstream id --- diff --git a/README.rst b/README.rst index e06a61a..8903719 100644 --- a/README.rst +++ b/README.rst @@ -47,6 +47,8 @@ JIRA issues:: CUSTOM_TRANSITION on upstream closure 'labels': ['tag1'..] :: Optional field to have custom set labels on all downstream issues created. 'github_markdown' :: If description syncing is turned on, this flag will convert Github markdown to plaintext. + 'upstream_id' :: This flag will add a comment indicating the upstream issue id when an issue is created, + allowing the user to search for the issue downstream via the upstream ID. Note: Overwrite set to True will ensure that upstream issue fields will clear downstream issue fields, overwrite set to False will never delete downstream issue fields only append. diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..69fe55e --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,19 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/docs/source/config-file.rst b/docs/source/config-file.rst index 19a12e5..6e5092d 100644 --- a/docs/source/config-file.rst +++ b/docs/source/config-file.rst @@ -91,6 +91,8 @@ getting a JIRA client and failure email will be sent anytime the service fails. * Optional field to have custom set labels on all downstream issues created. * :code:`github_markdown` * If description syncing is turned on, this flag will convert Github markdown to plaintext. This uses the pypandoc module. + * :code:`upstream_id` + * If selected this will add a comment to all newly created JIRA issue in the format 'UPSTREAM_PROJECT-#1' where the number indicates the issue ID. This allows users to search for the issue on JIRA via the issue number. .. note:: diff --git a/sync2jira/downstream.py b/sync2jira/downstream.py index 5af55c7..2388798 100644 --- a/sync2jira/downstream.py +++ b/sync2jira/downstream.py @@ -607,6 +607,12 @@ def _create_jira_issue(client, issue, config): if custom_field: downstream.update({custom_field: issue.downstream.get('qa-contact')}) + # Add upstream issue ID in comment if required + if 'upstream_id' in issue.downstream.get('updates', []): + comment = f"Creating issue for " \ + f"[{issue.upstream}-#{issue.upstream_id}|{issue.url}]" + client.add_comment(downstream, comment) + remote_link = dict(url=issue.url, title=remote_link_title) _attach_link(client, downstream, remote_link) diff --git a/sync2jira/intermediary.py b/sync2jira/intermediary.py index 3abbe81..6b9dcab 100644 --- a/sync2jira/intermediary.py +++ b/sync2jira/intermediary.py @@ -23,7 +23,7 @@ class Issue(object): def __init__(self, source, title, url, upstream, comments, config, tags, fixVersion, priority, content, - reporter, assignee, status, id, downstream=None): + reporter, assignee, status, id, upstream_id, downstream=None): self.source = source self._title = title self.url = url @@ -37,6 +37,7 @@ class Issue(object): self.assignee = assignee self.status = status self.id = str(id) + self.upstream_id = upstream_id if not downstream: self.downstream = config['sync2jira']['map'][self.source][upstream] else: @@ -84,7 +85,8 @@ class Issue(object): reporter=issue['user'], assignee=issue['assignee'], status=issue['status'], - id=issue['date_created'] + id=issue['date_created'], + upstream_id=issue['id'] ) @classmethod @@ -122,7 +124,8 @@ class Issue(object): reporter=issue['user'], assignee=issue['assignees'], status=issue['state'], - id=issue['id'] + id=issue['id'], + upstream_id=issue['number'] ) def __repr__(self): diff --git a/tests/test_intermediary.py b/tests/test_intermediary.py index 420769e..d27e98f 100644 --- a/tests/test_intermediary.py +++ b/tests/test_intermediary.py @@ -52,6 +52,7 @@ class TestIntermediary(unittest.TestCase): 'assignee': 'mock_assignee', 'status': 'mock_status', 'date_created': 'mock_date' + '' } # Call the function @@ -102,7 +103,8 @@ class TestIntermediary(unittest.TestCase): 'user': 'mock_reporter', 'assignees': 'mock_assignee', 'state': 'open', - 'date_created': 'mock_date' + 'date_created': 'mock_date', + 'number': '1', } # Call the function @@ -152,7 +154,8 @@ class TestIntermediary(unittest.TestCase): 'user': 'mock_reporter', 'assignees': 'mock_assignee', 'state': 'closed', - 'date_created': 'mock_date' + 'date_created': 'mock_date', + 'number': '1', } # Call the function