From c15a480e02a4a9781b9df3092d1c65f2e758a043 Mon Sep 17 00:00:00 2001 From: sidpremkumar Date: Jul 12 2019 14:10:28 +0000 Subject: Adding catch for PR comment --- diff --git a/sync2jira/upstream.py b/sync2jira/upstream.py index 3bf6ecc..3484cd6 100644 --- a/sync2jira/upstream.py +++ b/sync2jira/upstream.py @@ -65,6 +65,10 @@ def handle_github_message(msg, config): log.info("Actual %r %r != expected %r", key, actual, expected) return None + if 'pull_request' in msg['msg']['issue']: + log.info("%r is a pull request. Ignoring.", msg['msg']['issue'].get('html_url')) + return None + # Initialize Github object so we can get their full name (instead of their username) # And get comments if needed github_client = Github(config['sync2jira']['github_token']) diff --git a/tests/test_upstream.py b/tests/test_upstream.py index 593ef1e..4c2dd5b 100644 --- a/tests/test_upstream.py +++ b/tests/test_upstream.py @@ -393,6 +393,28 @@ class TestUpstream(unittest.TestCase): mock_github.assert_not_called() self.assertEqual(None, response) + @mock.patch(PATH + 'Github') + @mock.patch('sync2jira.intermediary.Issue.from_github') + def test_handle_github_message_pull_request(self, + mock_issue_from_github, + mock_github): + """ + This function tests 'handle_github_message' the issue is a pull request comment + """ + # Set up return values + self.mock_github_message['msg']['issue'] = {'pull_request': 'test'} + + # Call the function + response = u.handle_github_message( + msg=self.mock_github_message, + config=self.mock_config + ) + + # Assert that all calls were made correctly + mock_issue_from_github.assert_not_called() + mock_github.assert_not_called() + self.assertEqual(None, response) + @mock.patch('sync2jira.intermediary.Issue.from_github') def test_handle_github_message_bad_filter(self, mock_issue_from_github):