From c76c531b7aac11151932a1756f32830acbe9f183 Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Tue, 17 Sep 2019 17:23:57 -0400 Subject: [PATCH] Provide a payload for the webhook status post-back --- awx/main/models/mixins.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/awx/main/models/mixins.py b/awx/main/models/mixins.py index 58b772b425..e1f1707ffb 100644 --- a/awx/main/models/mixins.py +++ b/awx/main/models/mixins.py @@ -573,9 +573,35 @@ class WebhookMixin(models.Model): 'github': 'Authorization', 'gitlab': 'PRIVATE-TOKEN', } + service_statuses = { + 'github': { + 'new': 'pending', + 'successful': 'success', + 'failed': 'failure', + 'canceled': 'failure', + 'error': 'error', + }, + 'gitlab': { + 'new': 'pending', + 'running': 'running', + 'successful': 'success', + 'failed': 'failed', + 'error': 'failed', + 'canceled': 'canceled', + }, + } + + statuses = service_statuses[self.webhook_service] + if status not in statuses: + logger.debug("Skipping webhook job status change: '{}'".format(status)) + return try: + data = { + 'state': statuses[status], + 'context': 'tower', + } headers = {service_header[self.webhook_service]: self.webhook_credential.get_input('token')} - response = requests.post(status_api, headers=headers) + response = requests.post(status_api, data=data, headers=headers) except Exception: logger.exception("Posting webhook status caused an error.") return