2016-12-02 12:06:20 +01:00
|
|
|
# Webhooks for external integrations.
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
|
2020-08-20 00:32:15 +02:00
|
|
|
from zerver.decorator import webhook_view
|
2017-10-31 04:25:48 +01:00
|
|
|
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()
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-08-20 00:32:15 +02:00
|
|
|
@webhook_view("Heroku", notify_bot_owner_on_invalid_json=False)
|
2016-12-02 12:06:20 +01:00
|
|
|
@has_request_variables
|
2021-02-12 08:19:30 +01:00
|
|
|
def api_heroku_webhook(
|
|
|
|
request: HttpRequest,
|
|
|
|
user_profile: UserProfile,
|
|
|
|
head: str = REQ(),
|
|
|
|
app: str = REQ(),
|
|
|
|
user: str = REQ(),
|
|
|
|
url: str = REQ(),
|
|
|
|
git_log: str = REQ(),
|
|
|
|
) -> HttpResponse:
|
|
|
|
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()
|