From 0edc17946dfe0583f2a17bf10459a2e1a76fa458 Mon Sep 17 00:00:00 2001 From: Vijendar Komalla Date: Wed, 11 May 2016 17:05:07 -0500 Subject: [PATCH] On PR close do not trigger app workflow Change-Id: I4fc56b0b2a941e57c988a81331bab0d2adb8a333 Closes-Bug: #1447771 --- solum/api/controllers/v1/trigger.py | 9 ++++++--- solum/tests/api/controllers/v1/test_trigger.py | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/solum/api/controllers/v1/trigger.py b/solum/api/controllers/v1/trigger.py index 6667bb86d..f17922e48 100644 --- a/solum/api/controllers/v1/trigger.py +++ b/solum/api/controllers/v1/trigger.py @@ -86,6 +86,7 @@ class TriggerController(rest.RestController): body = json.loads(pecan.request.body) if ('sender' in body and 'url' in body['sender'] and 'api.github.com' in body['sender']['url']): + action = body.get('action', None) if 'comment' in body: # Process a request for rebuilding commit_sha, collab_url = self._process_request(body) @@ -111,9 +112,11 @@ class TriggerController(rest.RestController): raise exception.BadRequest(reason=info_msg) try: - handler = app_handler.AppHandler(None) - handler.trigger_workflow(trigger_id, commit_sha, status_url, - collab_url, workflow=workflow) + # Trigger workflow only on PR create and on rebuild request + if action in ['created', 'opened', 'edited', 'reopened']: + handler = app_handler.AppHandler(None) + handler.trigger_workflow(trigger_id, commit_sha, status_url, + collab_url, workflow=workflow) except exception.ResourceNotFound as e: LOG.error("Incorrect trigger url.") raise e diff --git a/solum/tests/api/controllers/v1/test_trigger.py b/solum/tests/api/controllers/v1/test_trigger.py index cd45bbb11..4eb939dd7 100644 --- a/solum/tests/api/controllers/v1/test_trigger.py +++ b/solum/tests/api/controllers/v1/test_trigger.py @@ -112,6 +112,7 @@ class TestTriggerController(base.BaseTestCase): resp_mock, request_mock): status_url = 'https://api.github.com/repos/u/r/statuses/{sha}' body_dict = {'sender': {'url': 'https://api.github.com'}, + 'action': 'opened', 'pull_request': {'head': {'sha': 'asdf'}}, 'repository': {'statuses_url': status_url}} expected_st_url = 'https://api.github.com/repos/u/r/statuses/asdf' @@ -131,6 +132,7 @@ class TestTriggerController(base.BaseTestCase): collab_url = ('https://api.github.com/repos/u/r/' + 'collaborators{/collaborator}') body_dict = {'sender': {'url': 'https://api.github.com'}, + 'action': 'created', 'comment': {'commit_id': 'asdf', 'body': ' SOLUM retry tests ', 'user': {'login': 'u'}}, @@ -155,6 +157,7 @@ class TestTriggerController(base.BaseTestCase): collab_url = ('https://api.github.com/repos/u/r/' + 'collaborators{/collaborator}') body_dict = {'sender': {'url': 'https://api.github.com'}, + 'action': 'created', 'comment': {'commit_id': 'asdf', 'body': 'solum is awesome', 'user': {'login': 'u'}}, @@ -178,6 +181,7 @@ class TestTriggerController(base.BaseTestCase): collab_url = ('https://api.github.com/repos/u/r/' + 'collaborators{/collaborator}') body_dict = {'sender': {'url': 'https://api.github.com'}, + 'action': 'created', 'comment': {'commit_id': 'asdf', 'body': 'solum retry tests', 'user': {'login': 'u'}},