From 84d153862610dab5acac361293cb0865d2b90a14 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Aug 17 2016 07:53:24 +0000 Subject: [PATCH 1/2] Fix tests --- diff --git a/tests/test_downstream.py b/tests/test_downstream.py index 8a30eeb..a5a7c14 100644 --- a/tests/test_downstream.py +++ b/tests/test_downstream.py @@ -32,7 +32,6 @@ class TestDownstream(unittest.TestCase): # Make sure we called search issues really only once client.return_value.search_issues.assert_called_once_with( 'key=value AND resolution is null', - maxResults=500, ) @mock.patch('jira.client.JIRA') @@ -40,6 +39,7 @@ class TestDownstream(unittest.TestCase): config = self.config.copy() target1 = "target1" client.return_value.create_issue = mock.MagicMock(return_value=target1) + class MockIssue(object): downstream = { 'project': 'awesome', @@ -52,8 +52,9 @@ class TestDownstream(unittest.TestCase): result = d.create_jira_issue(MockIssue(), config) eq_(result, target1) client.return_value.create_issue.assert_called_with( - project='awesome', - component='alsoawesome', + components=[{'name': 'alsoawesome'}], + issuetype={'name': 'Bug'}, + project={'key': 'awesome'}, description='http://threebean.org', summary='A title, a title...', ) From 84fbe7725524687b7ccada92a348782a86f37743 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Aug 17 2016 08:56:53 +0000 Subject: [PATCH 2/2] Add external issue url if jira field is configured Jira can define a bunch of custom fields. If the config specifies name of the field, the sync should put the upstream issue URL into it. --- diff --git a/sync2jira/downstream.py b/sync2jira/downstream.py index b85528f..a60fbc7 100644 --- a/sync2jira/downstream.py +++ b/sync2jira/downstream.py @@ -56,6 +56,11 @@ def create_jira_issue(issue, config): kwargs['project'] = dict(key=issue.downstream['project']) if issue.downstream['component']: kwargs['components'] = [dict(name=issue.downstream['component'])] # TODO - make this a list in the config + + external_url_field = config['sync2jira'].get('jira_opts', {}).get('external_url_field') + if external_url_field: + kwargs[external_url_field] = issue.url + return client.create_issue(**kwargs) diff --git a/tests/test_downstream.py b/tests/test_downstream.py index a5a7c14..0e15d5a 100644 --- a/tests/test_downstream.py +++ b/tests/test_downstream.py @@ -58,3 +58,30 @@ class TestDownstream(unittest.TestCase): description='http://threebean.org', summary='A title, a title...', ) + + @mock.patch('jira.client.JIRA') + def test_create_jira_issue_with_custom_url(self, client): + config = self.config.copy() + target1 = "target1" + client.return_value.create_issue = mock.MagicMock(return_value=target1) + + class MockIssue(object): + downstream = { + 'project': 'awesome', + 'component': 'alsoawesome', + } + title = 'A title, a title...' + url = 'http://threebean.org' + + config['sync2jira']['testing'] = False + config['sync2jira']['jira_opts'] = dict(external_url_field='customfield_10400') + result = d.create_jira_issue(MockIssue(), config) + eq_(result, target1) + client.return_value.create_issue.assert_called_with( + components=[{'name': 'alsoawesome'}], + issuetype={'name': 'Bug'}, + project={'key': 'awesome'}, + description='http://threebean.org', + summary='A title, a title...', + customfield_10400='http://threebean.org', + )