2019-05-07 02:42:30 +02:00
|
|
|
import string
|
2020-01-14 22:06:24 +01:00
|
|
|
from functools import partial
|
|
|
|
from inspect import signature
|
|
|
|
from typing import Any, Callable, Dict, List, Optional
|
2019-03-03 17:44:33 +01:00
|
|
|
|
|
|
|
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
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.webhooks.common import UnexpectedWebhookEventType, check_send_webhook_message
|
|
|
|
from zerver.lib.webhooks.git import (
|
|
|
|
CONTENT_MESSAGE_TEMPLATE,
|
|
|
|
TOPIC_WITH_BRANCH_TEMPLATE,
|
|
|
|
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE,
|
|
|
|
get_commits_comment_action_message,
|
|
|
|
get_create_branch_event_message,
|
|
|
|
get_pull_request_event_message,
|
|
|
|
get_push_tag_event_message,
|
|
|
|
get_remove_branch_event_message,
|
|
|
|
)
|
2020-01-14 22:06:24 +01:00
|
|
|
from zerver.models import UserProfile
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.webhooks.bitbucket2.view import (
|
|
|
|
BITBUCKET_FORK_BODY,
|
|
|
|
BITBUCKET_REPO_UPDATED_CHANGED,
|
|
|
|
BITBUCKET_TOPIC_TEMPLATE,
|
|
|
|
)
|
2019-03-03 17:44:33 +01:00
|
|
|
|
2019-03-25 05:13:47 +01:00
|
|
|
BRANCH_UPDATED_MESSAGE_TEMPLATE = "{user_name} pushed to branch {branch_name}. Head is now {head}."
|
2019-05-07 02:42:30 +02:00
|
|
|
PULL_REQUEST_MARKED_AS_NEEDS_WORK_TEMPLATE = "{user_name} marked [PR #{number}]({url}) as \"needs work\"."
|
|
|
|
PULL_REQUEST_MARKED_AS_NEEDS_WORK_TEMPLATE_WITH_TITLE = """
|
|
|
|
{user_name} marked [PR #{number} {title}]({url}) as \"needs work\".
|
|
|
|
""".strip()
|
|
|
|
PULL_REQUEST_REASSIGNED_TEMPLATE = "{user_name} reassigned [PR #{number}]({url}) to {assignees}."
|
|
|
|
PULL_REQUEST_REASSIGNED_TEMPLATE_WITH_TITLE = """
|
|
|
|
{user_name} reassigned [PR #{number} {title}]({url}) to {assignees}.
|
|
|
|
""".strip()
|
|
|
|
PULL_REQUEST_REASSIGNED_TO_NONE_TEMPLATE = "{user_name} removed all reviewers from [PR #{number}]({url})."
|
|
|
|
PULL_REQUEST_REASSIGNED_TO_NONE_TEMPLATE_WITH_TITLE = """
|
|
|
|
{user_name} removed all reviewers from [PR #{number} {title}]({url})
|
|
|
|
""".strip()
|
|
|
|
PULL_REQUEST_OPENED_OR_MODIFIED_TEMPLATE_WITH_REVIEWERS = """
|
|
|
|
{user_name} {action} [PR #{number}]({url}) from `{source}` to \
|
|
|
|
`{destination}` (assigned to {assignees} for review)
|
|
|
|
""".strip()
|
|
|
|
PULL_REQUEST_OPENED_OR_MODIFIED_TEMPLATE_WITH_REVIEWERS_WITH_TITLE = """
|
|
|
|
{user_name} {action} [PR #{number} {title}]({url}) from `{source}` to \
|
|
|
|
`{destination}` (assigned to {assignees} for review)
|
|
|
|
""".strip()
|
2019-03-03 17:44:33 +01:00
|
|
|
|
2019-07-24 14:46:06 +02:00
|
|
|
def fixture_to_headers(fixture_name: str) -> Dict[str, str]:
|
|
|
|
if fixture_name == "diagnostics_ping":
|
|
|
|
return {"HTTP_X_EVENT_KEY": "diagnostics:ping"}
|
|
|
|
return dict()
|
2019-07-04 18:59:22 +02:00
|
|
|
|
2019-03-26 15:04:09 +01:00
|
|
|
def get_user_name(payload: Dict[str, Any]) -> str:
|
|
|
|
user_name = "[{name}]({url})".format(name=payload["actor"]["name"],
|
|
|
|
url=payload["actor"]["links"]["self"][0]["href"])
|
|
|
|
return user_name
|
|
|
|
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
def ping_handler(payload: Dict[str, Any], include_title: Optional[str]=None,
|
2019-06-15 10:04:28 +02:00
|
|
|
) -> List[Dict[str, str]]:
|
|
|
|
if include_title:
|
|
|
|
subject = include_title
|
|
|
|
else:
|
|
|
|
subject = "Bitbucket Server Ping"
|
|
|
|
body = "Congratulations! The Bitbucket Server webhook was configured successfully!"
|
|
|
|
return [{"subject": subject, "body": body}]
|
|
|
|
|
2019-03-03 17:44:33 +01:00
|
|
|
def repo_comment_handler(payload: Dict[str, Any], action: str) -> List[Dict[str, str]]:
|
|
|
|
repo_name = payload["repository"]["name"]
|
|
|
|
subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
|
|
|
|
sha = payload["commit"]
|
|
|
|
commit_url = payload["repository"]["links"]["self"][0]["href"][:-6] # remove the "browse" at the end
|
2020-06-10 06:41:04 +02:00
|
|
|
commit_url += f"commits/{sha}"
|
2019-04-01 20:33:51 +02:00
|
|
|
message = payload["comment"]["text"]
|
|
|
|
if action == "deleted their comment":
|
2020-06-09 00:25:09 +02:00
|
|
|
message = f"~~{message}~~"
|
2019-03-25 05:13:47 +01:00
|
|
|
body = get_commits_comment_action_message(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
action=action,
|
|
|
|
commit_url=commit_url,
|
|
|
|
sha=sha,
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
message=message,
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
2019-03-03 17:44:33 +01:00
|
|
|
return [{"subject": subject, "body": body}]
|
|
|
|
|
|
|
|
def repo_forked_handler(payload: Dict[str, Any]) -> List[Dict[str, str]]:
|
|
|
|
repo_name = payload["repository"]["origin"]["name"]
|
|
|
|
subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
|
|
|
|
body = BITBUCKET_FORK_BODY.format(
|
|
|
|
display_name=payload["actor"]["displayName"],
|
2019-03-26 15:04:09 +01:00
|
|
|
username=get_user_name(payload),
|
2019-03-03 17:44:33 +01:00
|
|
|
fork_name=payload["repository"]["name"],
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
fork_url=payload["repository"]["links"]["self"][0]["href"],
|
2019-03-03 17:44:33 +01:00
|
|
|
)
|
|
|
|
return [{"subject": subject, "body": body}]
|
|
|
|
|
|
|
|
def repo_modified_handler(payload: Dict[str, Any]) -> List[Dict[str, str]]:
|
|
|
|
subject_new = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=payload["new"]["name"])
|
2019-05-07 02:42:30 +02:00
|
|
|
new_name = payload['new']['name']
|
2019-03-03 17:44:33 +01:00
|
|
|
body = BITBUCKET_REPO_UPDATED_CHANGED.format(
|
2019-03-26 15:04:09 +01:00
|
|
|
actor=get_user_name(payload),
|
2019-03-03 17:44:33 +01:00
|
|
|
change="name",
|
|
|
|
repo_name=payload["old"]["name"],
|
|
|
|
old=payload["old"]["name"],
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
new=new_name,
|
2019-03-03 17:44:33 +01:00
|
|
|
) # As of writing this, the only change we'd be notified about is a name change.
|
2019-05-07 02:42:30 +02:00
|
|
|
punctuation = '.' if new_name[-1] not in string.punctuation else ''
|
2020-06-09 00:25:09 +02:00
|
|
|
body = f"{body}{punctuation}"
|
2019-03-03 17:44:33 +01:00
|
|
|
return [{"subject": subject_new, "body": body}]
|
|
|
|
|
|
|
|
def repo_push_branch_data(payload: Dict[str, Any], change: Dict[str, Any]) -> Dict[str, str]:
|
|
|
|
event_type = change["type"]
|
|
|
|
repo_name = payload["repository"]["name"]
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name = get_user_name(payload)
|
2019-03-03 17:44:33 +01:00
|
|
|
branch_name = change["ref"]["displayId"]
|
|
|
|
branch_head = change["toHash"]
|
|
|
|
|
|
|
|
if event_type == "ADD":
|
2019-03-25 05:13:47 +01:00
|
|
|
body = get_create_branch_event_message(
|
|
|
|
user_name=user_name,
|
|
|
|
url=None,
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
branch_name=branch_name,
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
2019-03-03 17:44:33 +01:00
|
|
|
elif event_type == "UPDATE":
|
2019-03-25 05:13:47 +01:00
|
|
|
body = BRANCH_UPDATED_MESSAGE_TEMPLATE.format(
|
|
|
|
user_name=user_name,
|
|
|
|
branch_name=branch_name,
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
head=branch_head,
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
2019-03-03 17:44:33 +01:00
|
|
|
elif event_type == "DELETE":
|
|
|
|
body = get_remove_branch_event_message(user_name, branch_name)
|
|
|
|
else:
|
2020-06-10 06:41:04 +02:00
|
|
|
message = "{}.{}".format(payload["eventKey"], event_type) # nocoverage
|
2019-03-03 17:44:33 +01:00
|
|
|
raise UnexpectedWebhookEventType("BitBucket Server", message)
|
|
|
|
|
|
|
|
subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repo_name, branch=branch_name)
|
|
|
|
return {"subject": subject, "body": body}
|
|
|
|
|
|
|
|
def repo_push_tag_data(payload: Dict[str, Any], change: Dict[str, Any]) -> Dict[str, str]:
|
|
|
|
event_type = change["type"]
|
|
|
|
repo_name = payload["repository"]["name"]
|
|
|
|
tag_name = change["ref"]["displayId"]
|
|
|
|
|
|
|
|
if event_type == "ADD":
|
|
|
|
action = "pushed"
|
|
|
|
elif event_type == "DELETE":
|
|
|
|
action = "removed"
|
|
|
|
else:
|
2020-06-10 06:41:04 +02:00
|
|
|
message = "{}.{}".format(payload["eventKey"], event_type) # nocoverage
|
2019-03-03 17:44:33 +01:00
|
|
|
raise UnexpectedWebhookEventType("BitBucket Server", message)
|
|
|
|
|
|
|
|
subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
|
2019-03-26 15:04:09 +01:00
|
|
|
body = get_push_tag_event_message(get_user_name(payload), tag_name, action=action)
|
2019-03-03 17:44:33 +01:00
|
|
|
return {"subject": subject, "body": body}
|
|
|
|
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
def repo_push_handler(payload: Dict[str, Any], branches: Optional[str]=None,
|
2019-03-25 05:13:47 +01:00
|
|
|
) -> List[Dict[str, str]]:
|
2019-03-03 17:44:33 +01:00
|
|
|
data = []
|
|
|
|
for change in payload["changes"]:
|
|
|
|
event_target_type = change["ref"]["type"]
|
|
|
|
if event_target_type == "BRANCH":
|
|
|
|
branch = change["ref"]["displayId"]
|
|
|
|
if branches:
|
|
|
|
if branch not in branches:
|
|
|
|
continue
|
|
|
|
data.append(repo_push_branch_data(payload, change))
|
|
|
|
elif event_target_type == "TAG":
|
|
|
|
data.append(repo_push_tag_data(payload, change))
|
|
|
|
else:
|
2020-06-10 06:41:04 +02:00
|
|
|
message = "{}.{}".format(payload["eventKey"], event_target_type) # nocoverage
|
2019-03-03 17:44:33 +01:00
|
|
|
raise UnexpectedWebhookEventType("BitBucket Server", message)
|
|
|
|
return data
|
|
|
|
|
2019-03-25 05:13:47 +01:00
|
|
|
def get_assignees_string(pr: Dict[str, Any]) -> Optional[str]:
|
|
|
|
reviewers = []
|
|
|
|
for reviewer in pr["reviewers"]:
|
|
|
|
name = reviewer["user"]["name"]
|
|
|
|
link = reviewer["user"]["links"]["self"][0]["href"]
|
2020-06-10 06:41:04 +02:00
|
|
|
reviewers.append(f"[{name}]({link})")
|
2019-03-25 05:13:47 +01:00
|
|
|
if len(reviewers) == 0:
|
|
|
|
assignees = None
|
|
|
|
elif len(reviewers) == 1:
|
|
|
|
assignees = reviewers[0]
|
|
|
|
else:
|
|
|
|
assignees = ", ".join(reviewers[:-1]) + " and " + reviewers[-1]
|
|
|
|
return assignees
|
|
|
|
|
|
|
|
def get_pr_subject(repo: str, type: str, id: str, title: str) -> str:
|
|
|
|
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(repo=repo, type=type, id=id, title=title)
|
|
|
|
|
|
|
|
def get_simple_pr_body(payload: Dict[str, Any], action: str, include_title: Optional[bool]) -> str:
|
|
|
|
pr = payload["pullRequest"]
|
|
|
|
return get_pull_request_event_message(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
action=action,
|
|
|
|
url=pr["links"]["self"][0]["href"],
|
|
|
|
number=pr["id"],
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
title=pr["title"] if include_title else None,
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def get_pr_opened_or_modified_body(payload: Dict[str, Any], action: str,
|
|
|
|
include_title: Optional[bool]) -> str:
|
|
|
|
pr = payload["pullRequest"]
|
|
|
|
description = pr.get("description")
|
|
|
|
assignees_string = get_assignees_string(pr)
|
|
|
|
if assignees_string:
|
|
|
|
# Then use the custom message template for this particular integration so that we can
|
|
|
|
# specify the reviewers at the end of the message (but before the description/message).
|
2019-03-26 15:04:09 +01:00
|
|
|
parameters = {"user_name": get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
"action": action,
|
|
|
|
"url": pr["links"]["self"][0]["href"],
|
|
|
|
"number": pr["id"],
|
|
|
|
"source": pr["fromRef"]["displayId"],
|
|
|
|
"destination": pr["toRef"]["displayId"],
|
|
|
|
"message": description,
|
|
|
|
"assignees": assignees_string,
|
|
|
|
"title": pr["title"] if include_title else None}
|
|
|
|
if include_title:
|
|
|
|
body = PULL_REQUEST_OPENED_OR_MODIFIED_TEMPLATE_WITH_REVIEWERS_WITH_TITLE.format(
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
**parameters,
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
body = PULL_REQUEST_OPENED_OR_MODIFIED_TEMPLATE_WITH_REVIEWERS.format(**parameters)
|
2019-05-07 02:42:30 +02:00
|
|
|
punctuation = ':' if description else '.'
|
2020-06-09 00:25:09 +02:00
|
|
|
body = f"{body}{punctuation}"
|
2019-03-25 05:13:47 +01:00
|
|
|
if description:
|
|
|
|
body += '\n' + CONTENT_MESSAGE_TEMPLATE.format(message=description)
|
|
|
|
return body
|
|
|
|
return get_pull_request_event_message(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
action=action,
|
|
|
|
url=pr["links"]["self"][0]["href"],
|
|
|
|
number=pr["id"],
|
|
|
|
target_branch=pr["fromRef"]["displayId"],
|
|
|
|
base_branch=pr["toRef"]["displayId"],
|
|
|
|
message=pr.get("description"),
|
|
|
|
assignee=assignees_string if assignees_string else None,
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
title=pr["title"] if include_title else None,
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def get_pr_needs_work_body(payload: Dict[str, Any], include_title: Optional[bool]) -> str:
|
|
|
|
pr = payload["pullRequest"]
|
|
|
|
if not include_title:
|
|
|
|
return PULL_REQUEST_MARKED_AS_NEEDS_WORK_TEMPLATE.format(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
number=pr["id"],
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
url=pr["links"]["self"][0]["href"],
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
|
|
|
return PULL_REQUEST_MARKED_AS_NEEDS_WORK_TEMPLATE_WITH_TITLE.format(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
number=pr["id"],
|
|
|
|
url=pr["links"]["self"][0]["href"],
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
title=pr["title"],
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def get_pr_reassigned_body(payload: Dict[str, Any], include_title: Optional[bool]) -> str:
|
|
|
|
pr = payload["pullRequest"]
|
|
|
|
assignees_string = get_assignees_string(pr)
|
|
|
|
if not assignees_string:
|
|
|
|
if not include_title:
|
|
|
|
return PULL_REQUEST_REASSIGNED_TO_NONE_TEMPLATE.format(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
number=pr["id"],
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
url=pr["links"]["self"][0]["href"],
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
2019-05-07 02:42:30 +02:00
|
|
|
punctuation = '.' if pr['title'][-1] not in string.punctuation else ''
|
|
|
|
message = PULL_REQUEST_REASSIGNED_TO_NONE_TEMPLATE_WITH_TITLE.format(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
number=pr["id"],
|
|
|
|
url=pr["links"]["self"][0]["href"],
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
title=pr["title"],
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
2020-06-09 00:25:09 +02:00
|
|
|
message = f"{message}{punctuation}"
|
2019-05-07 02:42:30 +02:00
|
|
|
return message
|
2019-03-25 05:13:47 +01:00
|
|
|
if not include_title:
|
|
|
|
return PULL_REQUEST_REASSIGNED_TEMPLATE.format(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
number=pr["id"],
|
|
|
|
url=pr["links"]["self"][0]["href"],
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
assignees=assignees_string,
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
|
|
|
return PULL_REQUEST_REASSIGNED_TEMPLATE_WITH_TITLE.format(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
number=pr["id"],
|
|
|
|
url=pr["links"]["self"][0]["href"],
|
|
|
|
assignees=assignees_string,
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
title=pr["title"],
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def pr_handler(payload: Dict[str, Any], action: str,
|
2020-06-13 01:57:21 +02:00
|
|
|
include_title: bool=False) -> List[Dict[str, str]]:
|
2019-03-25 05:13:47 +01:00
|
|
|
pr = payload["pullRequest"]
|
|
|
|
subject = get_pr_subject(pr["toRef"]["repository"]["name"], type="PR", id=pr["id"],
|
|
|
|
title=pr["title"])
|
|
|
|
if action in ["opened", "modified"]:
|
|
|
|
body = get_pr_opened_or_modified_body(payload, action, include_title)
|
|
|
|
elif action == "needs_work":
|
|
|
|
body = get_pr_needs_work_body(payload, include_title)
|
|
|
|
elif action == "reviewers_updated":
|
|
|
|
body = get_pr_reassigned_body(payload, include_title)
|
|
|
|
else:
|
|
|
|
body = get_simple_pr_body(payload, action, include_title)
|
|
|
|
|
|
|
|
return [{"subject": subject, "body": body}]
|
|
|
|
|
|
|
|
def pr_comment_handler(payload: Dict[str, Any], action: str,
|
2020-06-13 01:57:21 +02:00
|
|
|
include_title: bool=False) -> List[Dict[str, str]]:
|
2019-03-25 05:13:47 +01:00
|
|
|
pr = payload["pullRequest"]
|
|
|
|
subject = get_pr_subject(pr["toRef"]["repository"]["name"], type="PR", id=pr["id"],
|
|
|
|
title=pr["title"])
|
|
|
|
message = payload["comment"]["text"]
|
2019-04-01 20:33:51 +02:00
|
|
|
if action == "deleted their comment on":
|
2020-06-09 00:25:09 +02:00
|
|
|
message = f"~~{message}~~"
|
2019-03-25 05:13:47 +01:00
|
|
|
body = get_pull_request_event_message(
|
2019-03-26 15:04:09 +01:00
|
|
|
user_name=get_user_name(payload),
|
2019-03-25 05:13:47 +01:00
|
|
|
action=action,
|
|
|
|
url=pr["links"]["self"][0]["href"],
|
|
|
|
number=pr["id"],
|
|
|
|
message=message,
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
title=pr["title"] if include_title else None,
|
2019-03-25 05:13:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
return [{"subject": subject, "body": body}]
|
|
|
|
|
2019-03-03 17:44:33 +01:00
|
|
|
EVENT_HANDLER_MAP = {
|
2019-06-15 10:04:28 +02:00
|
|
|
"diagnostics:ping": ping_handler,
|
2019-03-03 17:44:33 +01:00
|
|
|
"repo:comment:added": partial(repo_comment_handler, action="commented"),
|
|
|
|
"repo:comment:edited": partial(repo_comment_handler, action="edited their comment"),
|
|
|
|
"repo:comment:deleted": partial(repo_comment_handler, action="deleted their comment"),
|
|
|
|
"repo:forked": repo_forked_handler,
|
|
|
|
"repo:modified": repo_modified_handler,
|
|
|
|
"repo:refs_changed": repo_push_handler,
|
2019-03-25 05:13:47 +01:00
|
|
|
"pr:comment:added": partial(pr_comment_handler, action="commented on"),
|
|
|
|
"pr:comment:edited": partial(pr_comment_handler, action="edited their comment on"),
|
|
|
|
"pr:comment:deleted": partial(pr_comment_handler, action="deleted their comment on"),
|
|
|
|
"pr:declined": partial(pr_handler, action="declined"),
|
|
|
|
"pr:deleted": partial(pr_handler, action="deleted"),
|
|
|
|
"pr:merged": partial(pr_handler, action="merged"),
|
|
|
|
"pr:modified": partial(pr_handler, action="modified"),
|
|
|
|
"pr:opened": partial(pr_handler, action="opened"),
|
|
|
|
"pr:reviewer:approved": partial(pr_handler, action="approved"),
|
|
|
|
"pr:reviewer:needs_work": partial(pr_handler, action="needs_work"),
|
|
|
|
"pr:reviewer:updated": partial(pr_handler, action="reviewers_updated"),
|
|
|
|
"pr:reviewer:unapproved": partial(pr_handler, action="unapproved"),
|
2019-03-03 17:44:33 +01:00
|
|
|
} # type Dict[str, Optional[Callable[..., List[Dict[str, str]]]]]
|
|
|
|
|
|
|
|
def get_event_handler(eventkey: str) -> Callable[..., List[Dict[str, str]]]:
|
2020-08-11 01:47:44 +02:00
|
|
|
# The main reason for this function existence is because of mypy
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
handler: Any = EVENT_HANDLER_MAP.get(eventkey)
|
2019-03-03 17:44:33 +01:00
|
|
|
if handler is None:
|
|
|
|
raise UnexpectedWebhookEventType("BitBucket Server", eventkey)
|
|
|
|
return handler
|
|
|
|
|
|
|
|
@api_key_only_webhook_view("Bitbucket3")
|
|
|
|
@has_request_variables
|
|
|
|
def api_bitbucket3_webhook(request: HttpRequest, user_profile: UserProfile,
|
|
|
|
payload: Dict[str, Any]=REQ(argument_type="body"),
|
|
|
|
branches: Optional[str]=REQ(default=None),
|
python: Use trailing commas consistently.
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>
2020-04-10 05:23:40 +02:00
|
|
|
user_specified_topic: Optional[str]=REQ("topic", default=None),
|
2019-03-03 17:44:33 +01:00
|
|
|
) -> HttpResponse:
|
2019-06-15 10:04:28 +02:00
|
|
|
try:
|
|
|
|
eventkey = payload["eventKey"]
|
|
|
|
except KeyError:
|
|
|
|
eventkey = request.META["HTTP_X_EVENT_KEY"]
|
2019-03-03 17:44:33 +01:00
|
|
|
handler = get_event_handler(eventkey)
|
|
|
|
|
|
|
|
if "branches" in signature(handler).parameters:
|
|
|
|
data = handler(payload, branches)
|
2019-03-25 05:13:47 +01:00
|
|
|
elif "include_title" in signature(handler).parameters:
|
|
|
|
data = handler(payload, include_title=user_specified_topic)
|
2019-03-03 17:44:33 +01:00
|
|
|
else:
|
|
|
|
data = handler(payload)
|
|
|
|
for element in data:
|
|
|
|
check_send_webhook_message(request, user_profile, element["subject"],
|
|
|
|
element["body"], unquote_url_parameters=True)
|
|
|
|
|
|
|
|
return json_success()
|