mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 10:30:03 -03:30
Posting webhook status now works
This commit is contained in:
parent
40b03eb6ef
commit
286da3a7eb
@ -570,19 +570,19 @@ class WebhookMixin(models.Model):
|
||||
return
|
||||
|
||||
service_header = {
|
||||
'github': 'Authorization',
|
||||
'gitlab': 'PRIVATE-TOKEN',
|
||||
'github': ('Authorization', 'token {}'),
|
||||
'gitlab': ('PRIVATE-TOKEN', '{}'),
|
||||
}
|
||||
service_statuses = {
|
||||
'github': {
|
||||
'new': 'pending',
|
||||
'pending': 'pending',
|
||||
'successful': 'success',
|
||||
'failed': 'failure',
|
||||
'canceled': 'failure', # Github doesn't have a 'canceled' status :(
|
||||
'error': 'error',
|
||||
},
|
||||
'gitlab': {
|
||||
'new': 'pending',
|
||||
'pending': 'pending',
|
||||
'running': 'running',
|
||||
'successful': 'success',
|
||||
'failed': 'failed',
|
||||
@ -601,8 +601,9 @@ class WebhookMixin(models.Model):
|
||||
'state': statuses[status],
|
||||
'context': 'ansible/awx' if license_type == 'open' else 'ansible/tower',
|
||||
}
|
||||
headers = {service_header[self.webhook_service]: self.webhook_credential.get_input('token')}
|
||||
response = requests.post(status_api, data=data, headers=headers)
|
||||
k, v = service_header[self.webhook_service]
|
||||
headers = {k: v.format(self.webhook_credential.get_input('token'))}
|
||||
response = requests.post(status_api, data=json.dumps(data), headers=headers)
|
||||
except Exception:
|
||||
logger.exception("Posting webhook status caused an error.")
|
||||
return
|
||||
@ -610,4 +611,5 @@ class WebhookMixin(models.Model):
|
||||
if response.status_code < 400:
|
||||
logger.debug("Webhook status update sent.")
|
||||
else:
|
||||
logger.debug("Posting webhook status failed, code: {}".format(response.status_code))
|
||||
logger.error("Posting webhook status failed, code: {}".format(response.status_code))
|
||||
logger.error(response.text)
|
||||
|
||||
@ -462,8 +462,6 @@ class JobNotificationMixin(object):
|
||||
return (notification_subject, notification_body)
|
||||
|
||||
def send_notification_templates(self, status):
|
||||
self.update_webhook_status(status)
|
||||
|
||||
from awx.main.tasks import send_notifications # avoid circular import
|
||||
if status not in ['running', 'succeeded', 'failed']:
|
||||
raise ValueError(_("status must be either running, succeeded or failed"))
|
||||
|
||||
@ -1206,6 +1206,8 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
||||
|
||||
def websocket_emit_status(self, status):
|
||||
connection.on_commit(lambda: self._websocket_emit_status(status))
|
||||
if hasattr(self, 'update_webhook_status'):
|
||||
connection.on_commit(lambda: self.update_webhook_status(status))
|
||||
|
||||
def notification_data(self):
|
||||
return dict(id=self.id,
|
||||
@ -1422,6 +1424,3 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
||||
|
||||
def is_isolated(self):
|
||||
return bool(self.controller_node)
|
||||
|
||||
def update_webhook_status(self, status):
|
||||
return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user