Fix problems with posting to Gitlab's API

This commit is contained in:
Jeff Bradberry
2019-09-20 14:59:35 -04:00
parent e91462d085
commit b415c31b4f
2 changed files with 10 additions and 4 deletions

View File

@@ -225,7 +225,7 @@ class GitlabWebhookReceiver(WebhookReceiverBase):
return return
parsed = urllib.parse.urlparse(repo_url) parsed = urllib.parse.urlparse(repo_url)
return "{}://{}/projects/{}/repository/commits/{}/statuses".format( return "{}://{}/api/v4/projects/{}/statuses/{}".format(
parsed.scheme, parsed.netloc, project['id'], self.get_event_ref()) parsed.scheme, parsed.netloc, project['id'], self.get_event_ref())
def get_signature(self): def get_signature(self):

View File

@@ -601,7 +601,10 @@ class WebhookMixin(models.Model):
'context': 'ansible/awx' if license_type == 'open' else 'ansible/tower', 'context': 'ansible/awx' if license_type == 'open' else 'ansible/tower',
} }
k, v = service_header[self.webhook_service] k, v = service_header[self.webhook_service]
headers = {k: v.format(self.webhook_credential.get_input('token'))} headers = {
k: v.format(self.webhook_credential.get_input('token')),
'Content-Type': 'application/json'
}
response = requests.post(status_api, data=json.dumps(data), headers=headers) response = requests.post(status_api, data=json.dumps(data), headers=headers)
except Exception: except Exception:
logger.exception("Posting webhook status caused an error.") logger.exception("Posting webhook status caused an error.")
@@ -610,5 +613,8 @@ class WebhookMixin(models.Model):
if response.status_code < 400: if response.status_code < 400:
logger.debug("Webhook status update sent.") logger.debug("Webhook status update sent.")
else: else:
logger.error("Posting webhook status failed, code: {}".format(response.status_code)) logger.error(
logger.error(response.text) "Posting webhook status failed, code: {}\n"
"{}\n"
"Payload sent: {}".format(response.status_code, response.text, json.dumps(data))
)