On PR close do not trigger app workflow

Change-Id: I4fc56b0b2a941e57c988a81331bab0d2adb8a333
Closes-Bug: #1447771
This commit is contained in:
Vijendar Komalla 2016-05-11 17:05:07 -05:00
parent 95c7567627
commit 0edc17946d
2 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -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'}},