mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 23:19:10 +00:00
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
# Webhooks for external integrations.
|
|
from typing import Any, Dict
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
from zerver.decorator import api_key_only_webhook_view
|
|
from zerver.lib.request import REQ, has_request_variables
|
|
from zerver.lib.response import json_success
|
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
|
from zerver.models import UserProfile
|
|
|
|
CIRCLECI_TOPIC_TEMPLATE = '{repository_name}'
|
|
CIRCLECI_MESSAGE_TEMPLATE = '[Build]({build_url}) triggered by {username} on {branch} branch {status}.'
|
|
|
|
FAILED_STATUS = 'failed'
|
|
|
|
@api_key_only_webhook_view('CircleCI')
|
|
@has_request_variables
|
|
def api_circleci_webhook(request: HttpRequest, user_profile: UserProfile,
|
|
payload: Dict[str, Any]=REQ(argument_type='body')) -> HttpResponse:
|
|
payload = payload['payload']
|
|
subject = get_subject(payload)
|
|
body = get_body(payload)
|
|
|
|
check_send_webhook_message(request, user_profile, subject, body)
|
|
return json_success()
|
|
|
|
def get_subject(payload: Dict[str, Any]) -> str:
|
|
return CIRCLECI_TOPIC_TEMPLATE.format(repository_name=payload['reponame'])
|
|
|
|
def get_body(payload: Dict[str, Any]) -> str:
|
|
data = {
|
|
'build_url': payload['build_url'],
|
|
'username': payload['username'],
|
|
'branch': payload['branch'],
|
|
'status': get_status(payload),
|
|
}
|
|
return CIRCLECI_MESSAGE_TEMPLATE.format(**data)
|
|
|
|
def get_status(payload: Dict[str, Any]) -> str:
|
|
status = payload['status']
|
|
previous = payload.get('previous', None)
|
|
if previous and previous['status'] == FAILED_STATUS and status == FAILED_STATUS:
|
|
return 'is still failing'
|
|
if status == 'success':
|
|
return 'succeeded'
|
|
return status
|