2016-12-02 12:06:20 +01:00
|
|
|
# Webhooks for external integrations.
|
|
|
|
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
|
2017-10-31 04:25:48 +01:00
|
|
|
from zerver.decorator import api_key_only_webhook_view
|
|
|
|
from zerver.lib.request import REQ, has_request_variables
|
2017-11-16 00:43:10 +01:00
|
|
|
from zerver.lib.response import json_success
|
2018-03-16 22:53:50 +01:00
|
|
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
2017-05-02 01:00:50 +02:00
|
|
|
from zerver.models import UserProfile
|
2016-12-02 12:06:20 +01:00
|
|
|
|
2019-04-12 05:36:17 +02:00
|
|
|
TEMPLATE = """
|
|
|
|
{user} deployed version {head} of [{app}]({url}):
|
|
|
|
|
|
|
|
``` quote
|
|
|
|
{git_log}
|
|
|
|
```
|
|
|
|
""".strip()
|
|
|
|
|
2018-11-20 18:52:25 +01:00
|
|
|
@api_key_only_webhook_view("Heroku", notify_bot_owner_on_invalid_json=False)
|
2016-12-02 12:06:20 +01:00
|
|
|
@has_request_variables
|
2017-12-06 11:10:32 +01:00
|
|
|
def api_heroku_webhook(request: HttpRequest, user_profile: UserProfile,
|
2018-05-10 19:34:01 +02:00
|
|
|
head: str=REQ(), app: str=REQ(), user: str=REQ(),
|
|
|
|
url: str=REQ(), git_log: str=REQ()) -> HttpResponse:
|
2019-04-12 05:36:17 +02:00
|
|
|
content = TEMPLATE.format(user=user, head=head, app=app,
|
|
|
|
url=url, git_log=git_log)
|
2016-12-02 12:06:20 +01:00
|
|
|
|
2018-03-16 22:53:50 +01:00
|
|
|
check_send_webhook_message(request, user_profile, app, content)
|
2016-12-02 12:06:20 +01:00
|
|
|
return json_success()
|