From a40d207f8bf07b2fbc62d0e07aa73a298d314ab4 Mon Sep 17 00:00:00 2001 From: sidpremkumar Date: Oct 07 2019 16:10:51 +0000 Subject: [PATCH 1/2] Add epic link support --- diff --git a/sync2jira/downstream.py b/sync2jira/downstream.py index 2388798..2a56563 100644 --- a/sync2jira/downstream.py +++ b/sync2jira/downstream.py @@ -596,16 +596,23 @@ def _create_jira_issue(client, issue, config): log.info(" Creating issue.") downstream = client.create_issue(**kwargs) - # Add QA field if present - if issue.downstream.get('qa-contact', None): + # Add Epic link or QA field if present + if issue.downstream.get('epic-link', None) or \ + issue.downstream.get('qa-contact', None): # Fetch all fields all_fields = client.fields() # Make a map from field name -> field id name_map = {field['name']: field['id'] for field in all_fields} - # Try to get and update the custom field - custom_field = name_map.get('QA Contact', None) - if custom_field: - downstream.update({custom_field: issue.downstream.get('qa-contact')}) + if issue.downstream.get('epic-link', None): + # Try to get and update the custom field + custom_field = name_map.get('Epic Link', None) + if custom_field: + downstream.update({custom_field: issue.downstream.get('epic-link')}) + if issue.downstream.get('qa-contact', None): + # Try to get and update the custom field + custom_field = name_map.get('QA Contact', None) + 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', []): diff --git a/sync2jira/main.py b/sync2jira/main.py index f1d09eb..ec00743 100644 --- a/sync2jira/main.py +++ b/sync2jira/main.py @@ -163,7 +163,7 @@ def initialize(config): try: d.sync_with_jira(issue, config) except Exception: - log.error("Failed on %r", issue) + log.error(" Failed on %r", issue) raise log.info(" Done with pagure initialization.") @@ -172,7 +172,7 @@ def initialize(config): try: d.sync_with_jira(issue, config) except Exception: - log.error("Failed on %r", issue) + log.error(" Failed on %r", issue) raise log.info(" Done with github initialization.") diff --git a/tests/test_downstream.py b/tests/test_downstream.py index 972846a..c572f81 100644 --- a/tests/test_downstream.py +++ b/tests/test_downstream.py @@ -48,6 +48,8 @@ class TestDownstream(unittest.TestCase): 'project': 'mock_project', 'custom_fields': {'somecustumfield': 'somecustumvalue'}, 'type': 'Fix', + 'qa-contact': 'dummy@dummy.com', + 'epic_link': 'DUMMY-1234', 'updates': [ 'comments', {'tags': {'overwrite': False}}, @@ -334,6 +336,10 @@ class TestDownstream(unittest.TestCase): """ # Set up return values mock_client.create_issue.return_value = self.mock_downstream + mock_client.fields.return_value = [ + {'name': 'Epic Link', 'id': 'customfield_1'}, + {'name': 'QA Contact', 'id': 'customfield_2'}, + ] # Call the function response = d._create_jira_issue( @@ -363,6 +369,7 @@ class TestDownstream(unittest.TestCase): self.mock_issue, mock_client ) + self.mock_downstream.update.assert_any_call({'customfield_1': 'DUMMY-1234'}) self.assertEqual(response, self.mock_downstream) @mock.patch(PATH + '_update_jira_issue') From b22ef34ee04f7cd236368b56ae7dce01efd56a49 Mon Sep 17 00:00:00 2001 From: sidpremkumar Date: Oct 09 2019 15:52:03 +0000 Subject: [PATCH 2/2] Add docs for qa-contact and epic-link --- diff --git a/README.rst b/README.rst index 8903719..32b502d 100644 --- a/README.rst +++ b/README.rst @@ -28,7 +28,8 @@ Each project is accompanied by an 'updates' array as seen below:: 'Demo_project': {'project': 'PROJECT', 'component': 'COMP', 'updates': [...], 'owner': 'project_owner_username', 'default_status': 'start_status_for_issue' - 'labels: ['tag1'..]}, + 'labels: ['tag1'..], 'qa-contact': 'some@some.com', + 'epic-link': 'FACTORY-1234'}, The following can be added to the updates array to specify what to sync with downstream diff --git a/docs/source/config-file.rst b/docs/source/config-file.rst index 6e5092d..d012b53 100644 --- a/docs/source/config-file.rst +++ b/docs/source/config-file.rst @@ -70,7 +70,20 @@ getting a JIRA client and failure email will be sent anytime the service fails. }, }, -* You can add your projects here. The 'project' field is associated with downstream JIRA projects, and 'component' with downstream components. +* You can add the following to your project configuration: + + * :code:`'project'` + * Downstream project to sync with + * :code:`'component'` + * Downstream component to sync with + * :code:`'owner'` + * Optional (Recommended): Alerts the owner of an issue if there are duplicate issues present + * :code:`'qa-contact'` + * Optional: Automatically add a QA contact field when issues are created + * :code:`'epic-link'` + * Optional: Pass the downstream key to automatically create an epic-link when issues are created + +* You can add your projects here. The 'project' field is associated with downstream JIRA projects, and 'component' with downstream components You can add the following to the updates array: * :code:`'comments'` diff --git a/tests/test_downstream.py b/tests/test_downstream.py index c572f81..550d05e 100644 --- a/tests/test_downstream.py +++ b/tests/test_downstream.py @@ -49,7 +49,7 @@ class TestDownstream(unittest.TestCase): 'custom_fields': {'somecustumfield': 'somecustumvalue'}, 'type': 'Fix', 'qa-contact': 'dummy@dummy.com', - 'epic_link': 'DUMMY-1234', + 'epic-link': 'DUMMY-1234', 'updates': [ 'comments', {'tags': {'overwrite': False}}, @@ -370,6 +370,7 @@ class TestDownstream(unittest.TestCase): mock_client ) self.mock_downstream.update.assert_any_call({'customfield_1': 'DUMMY-1234'}) + self.mock_downstream.update.assert_any_call({'customfield_2': 'dummy@dummy.com'}) self.assertEqual(response, self.mock_downstream) @mock.patch(PATH + '_update_jira_issue')