2016-07-04 23:06:44 +02:00
|
|
|
# Webhooks for external integrations.
|
|
|
|
import re
|
2019-04-19 22:02:41 +02:00
|
|
|
import string
|
2020-01-14 22:06:24 +01:00
|
|
|
from functools import partial
|
2018-07-25 00:57:45 +02:00
|
|
|
from inspect import signature
|
2020-01-14 22:06:24 +01:00
|
|
|
from typing import Any, Dict, List, Optional
|
2017-11-16 00:43:10 +01:00
|
|
|
|
2016-07-04 23:06:44 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2017-11-16 00:43:10 +01:00
|
|
|
|
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
|
2019-02-02 23:53:55 +01:00
|
|
|
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,
|
|
|
|
validate_extract_webhook_http_header,
|
|
|
|
)
|
|
|
|
from zerver.lib.webhooks.git import (
|
|
|
|
TOPIC_WITH_BRANCH_TEMPLATE,
|
|
|
|
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE,
|
|
|
|
get_commits_comment_action_message,
|
|
|
|
get_force_push_commits_event_message,
|
|
|
|
get_issue_event_message,
|
|
|
|
get_pull_request_event_message,
|
|
|
|
get_push_commits_event_message,
|
|
|
|
get_push_tag_event_message,
|
|
|
|
get_remove_branch_event_message,
|
|
|
|
)
|
2017-05-02 01:00:50 +02:00
|
|
|
from zerver.models import UserProfile
|
2016-07-04 23:06:44 +02:00
|
|
|
|
2018-11-09 21:02:59 +01:00
|
|
|
BITBUCKET_TOPIC_TEMPLATE = '{repository_name}'
|
2016-07-23 21:10:58 +02:00
|
|
|
USER_PART = 'User {display_name}(login: {username})'
|
2016-07-04 23:06:44 +02:00
|
|
|
|
2016-07-23 21:10:58 +02:00
|
|
|
BITBUCKET_FORK_BODY = USER_PART + ' forked the repository into [{fork_name}]({fork_url}).'
|
2017-11-05 02:48:25 +01:00
|
|
|
BITBUCKET_COMMIT_STATUS_CHANGED_BODY = ('[System {key}]({system_url}) changed status of'
|
|
|
|
' {commit_info} to {status}.')
|
2018-04-25 01:36:03 +02:00
|
|
|
BITBUCKET_REPO_UPDATED_CHANGED = ('{actor} changed the {change} of the **{repo_name}**'
|
2019-04-19 22:02:41 +02:00
|
|
|
' repo from **{old}** to **{new}**')
|
|
|
|
BITBUCKET_REPO_UPDATED_ADDED = '{actor} changed the {change} of the **{repo_name}** repo to **{new}**'
|
2016-07-04 23:06:44 +02:00
|
|
|
|
|
|
|
PULL_REQUEST_SUPPORTED_ACTIONS = [
|
|
|
|
'approved',
|
|
|
|
'unapproved',
|
|
|
|
'created',
|
|
|
|
'updated',
|
|
|
|
'rejected',
|
2017-01-11 14:17:41 +01:00
|
|
|
'fulfilled',
|
2016-07-04 23:06:44 +02:00
|
|
|
'comment_created',
|
|
|
|
'comment_updated',
|
|
|
|
'comment_deleted',
|
|
|
|
]
|
|
|
|
|
|
|
|
@api_key_only_webhook_view('Bitbucket2')
|
|
|
|
@has_request_variables
|
2017-12-06 19:38:34 +01:00
|
|
|
def api_bitbucket2_webhook(request: HttpRequest, user_profile: UserProfile,
|
|
|
|
payload: Dict[str, Any]=REQ(argument_type='body'),
|
2018-07-25 00:57:45 +02:00
|
|
|
branches: Optional[str]=REQ(default=None),
|
|
|
|
user_specified_topic: Optional[str]=REQ("topic", default=None)) -> HttpResponse:
|
2017-08-24 17:31:04 +02:00
|
|
|
type = get_type(request, payload)
|
2018-07-25 00:57:45 +02:00
|
|
|
if type == 'push':
|
2017-11-27 01:03:52 +01:00
|
|
|
# ignore push events with no changes
|
|
|
|
if not payload['push']['changes']:
|
|
|
|
return json_success()
|
2017-08-24 17:31:04 +02:00
|
|
|
branch = get_branch_name_for_push_event(payload)
|
|
|
|
if branch and branches:
|
|
|
|
if branches.find(branch) == -1:
|
|
|
|
return json_success()
|
2018-07-25 00:57:45 +02:00
|
|
|
|
|
|
|
subject = get_subject_based_on_type(payload, type)
|
|
|
|
body_function = get_body_based_on_type(type)
|
|
|
|
if 'include_title' in signature(body_function).parameters:
|
|
|
|
body = body_function(
|
|
|
|
payload,
|
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
|
|
|
include_title=user_specified_topic is not None,
|
2018-07-25 00:57:45 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
body = body_function(payload)
|
|
|
|
|
|
|
|
if type != 'push':
|
2018-12-28 21:30:40 +01:00
|
|
|
check_send_webhook_message(request, user_profile, subject,
|
|
|
|
body, unquote_url_parameters=True)
|
2018-07-25 00:57:45 +02:00
|
|
|
else:
|
|
|
|
for b, s in zip(body, subject):
|
2018-12-28 21:30:40 +01:00
|
|
|
check_send_webhook_message(request, user_profile, s, b,
|
|
|
|
unquote_url_parameters=True)
|
2018-03-13 23:43:02 +01:00
|
|
|
|
2016-07-04 23:06:44 +02:00
|
|
|
return json_success()
|
|
|
|
|
2017-11-10 04:33:28 +01:00
|
|
|
def get_subject_for_branch_specified_events(payload: Dict[str, Any],
|
2018-05-11 01:43:34 +02:00
|
|
|
branch_name: Optional[str]=None) -> str:
|
2018-11-09 20:59:15 +01:00
|
|
|
return TOPIC_WITH_BRANCH_TEMPLATE.format(
|
2016-10-05 19:48:15 +02:00
|
|
|
repo=get_repository_name(payload['repository']),
|
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=get_branch_name_for_push_event(payload) if branch_name is None else branch_name,
|
2016-10-05 19:48:15 +02:00
|
|
|
)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_push_subjects(payload: Dict[str, Any]) -> List[str]:
|
2016-11-09 16:05:45 +01:00
|
|
|
subjects_list = []
|
|
|
|
for change in payload['push']['changes']:
|
|
|
|
potential_tag = (change['new'] or change['old'] or {}).get('type')
|
|
|
|
if potential_tag == 'tag':
|
|
|
|
subjects_list.append(str(get_subject(payload)))
|
|
|
|
else:
|
2016-11-11 13:32:41 +01:00
|
|
|
if change.get('new'):
|
|
|
|
branch_name = change['new']['name']
|
|
|
|
else:
|
|
|
|
branch_name = change['old']['name']
|
|
|
|
subjects_list.append(str(get_subject_for_branch_specified_events(payload, branch_name)))
|
2016-11-09 16:05:45 +01:00
|
|
|
return subjects_list
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_subject(payload: Dict[str, Any]) -> str:
|
2017-05-24 23:03:06 +02:00
|
|
|
assert(payload['repository'] is not None)
|
2018-11-09 21:02:59 +01:00
|
|
|
return BITBUCKET_TOPIC_TEMPLATE.format(repository_name=get_repository_name(payload['repository']))
|
2016-10-05 19:48:15 +02:00
|
|
|
|
2018-07-25 00:57:45 +02:00
|
|
|
def get_subject_based_on_type(payload: Dict[str, Any], type: str) -> Any:
|
2016-10-11 18:55:39 +02:00
|
|
|
if type.startswith('pull_request'):
|
2018-11-09 20:59:15 +01:00
|
|
|
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
2017-05-24 23:03:06 +02:00
|
|
|
repo=get_repository_name(payload['repository']),
|
2016-10-11 18:55:39 +02:00
|
|
|
type='PR',
|
|
|
|
id=payload['pullrequest']['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=payload['pullrequest']['title'],
|
2016-10-11 18:55:39 +02:00
|
|
|
)
|
2016-10-19 23:44:02 +02:00
|
|
|
if type.startswith('issue'):
|
2018-11-09 20:59:15 +01:00
|
|
|
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
2017-05-24 23:03:06 +02:00
|
|
|
repo=get_repository_name(payload['repository']),
|
2016-10-19 23:44:02 +02:00
|
|
|
type='Issue',
|
|
|
|
id=payload['issue']['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=payload['issue']['title'],
|
2016-10-19 23:44:02 +02:00
|
|
|
)
|
2018-07-25 00:57:45 +02:00
|
|
|
if type == 'push':
|
|
|
|
return get_push_subjects(payload)
|
2016-10-05 19:48:15 +02:00
|
|
|
return get_subject(payload)
|
2016-07-04 23:06:44 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_type(request: HttpRequest, payload: Dict[str, Any]) -> str:
|
2016-07-04 23:06:44 +02:00
|
|
|
if payload.get('push'):
|
|
|
|
return 'push'
|
|
|
|
elif payload.get('fork'):
|
|
|
|
return 'fork'
|
|
|
|
elif payload.get('comment') and payload.get('commit'):
|
|
|
|
return 'commit_comment'
|
|
|
|
elif payload.get('commit_status'):
|
|
|
|
return 'change_commit_status'
|
|
|
|
elif payload.get('issue'):
|
|
|
|
if payload.get('changes'):
|
|
|
|
return "issue_updated"
|
|
|
|
if payload.get('comment'):
|
|
|
|
return 'issue_commented'
|
|
|
|
return "issue_created"
|
|
|
|
elif payload.get('pullrequest'):
|
|
|
|
pull_request_template = 'pull_request_{}'
|
2018-04-24 20:54:13 +02:00
|
|
|
# Note that we only need the HTTP header to determine pullrequest events.
|
|
|
|
# We rely on the payload itself to determine the other ones.
|
|
|
|
event_key = validate_extract_webhook_http_header(request, "X_EVENT_KEY", "BitBucket")
|
2019-02-01 02:35:10 +01:00
|
|
|
assert event_key is not None
|
2016-07-04 23:06:44 +02:00
|
|
|
action = re.match('pullrequest:(?P<action>.*)$', event_key)
|
|
|
|
if action:
|
2018-04-24 20:54:13 +02:00
|
|
|
action_group = action.group('action')
|
|
|
|
if action_group in PULL_REQUEST_SUPPORTED_ACTIONS:
|
|
|
|
return pull_request_template.format(action_group)
|
|
|
|
else:
|
|
|
|
event_key = validate_extract_webhook_http_header(request, "X_EVENT_KEY", "BitBucket")
|
|
|
|
if event_key == 'repo:updated':
|
|
|
|
return event_key
|
|
|
|
|
2018-05-22 16:46:45 +02:00
|
|
|
raise UnexpectedWebhookEventType('BitBucket2', event_key)
|
2016-07-04 23:06:44 +02:00
|
|
|
|
2018-07-25 00:57:45 +02:00
|
|
|
def get_body_based_on_type(type: str) -> Any:
|
2017-08-08 01:48:17 +02:00
|
|
|
fn = GET_SINGLE_MESSAGE_BODY_DEPENDING_ON_TYPE_MAPPER.get(type)
|
|
|
|
return fn
|
2016-11-09 16:05:45 +01:00
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def get_push_bodies(payload: Dict[str, Any]) -> List[str]:
|
2016-11-09 16:05:45 +01:00
|
|
|
messages_list = []
|
|
|
|
for change in payload['push']['changes']:
|
|
|
|
potential_tag = (change['new'] or change['old'] or {}).get('type')
|
|
|
|
if potential_tag == 'tag':
|
|
|
|
messages_list.append(get_push_tag_body(payload, change))
|
2018-04-02 23:57:52 +02:00
|
|
|
# if change['new'] is None, that means a branch was deleted
|
|
|
|
elif change.get('new') is None:
|
2016-11-09 16:05:45 +01:00
|
|
|
messages_list.append(get_remove_branch_push_body(payload, change))
|
|
|
|
elif change.get('forced'):
|
|
|
|
messages_list.append(get_force_push_body(payload, change))
|
|
|
|
else:
|
|
|
|
messages_list.append(get_normal_push_body(payload, change))
|
|
|
|
return messages_list
|
2016-10-06 15:32:10 +02:00
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def get_remove_branch_push_body(payload: Dict[str, Any], change: Dict[str, Any]) -> str:
|
2016-10-06 16:14:51 +02:00
|
|
|
return get_remove_branch_event_message(
|
|
|
|
get_user_username(payload),
|
|
|
|
change['old']['name'],
|
|
|
|
)
|
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def get_force_push_body(payload: Dict[str, Any], change: Dict[str, Any]) -> str:
|
2016-10-06 15:32:10 +02:00
|
|
|
return get_force_push_commits_event_message(
|
|
|
|
get_user_username(payload),
|
|
|
|
change['links']['html']['href'],
|
|
|
|
change['new']['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
|
|
|
change['new']['target']['hash'],
|
2016-10-06 15:32:10 +02:00
|
|
|
)
|
2016-10-02 09:44:33 +02:00
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def get_commit_author_name(commit: Dict[str, Any]) -> str:
|
2017-05-24 23:03:06 +02:00
|
|
|
if commit['author'].get('user'):
|
|
|
|
return commit['author']['user'].get('username')
|
|
|
|
return commit['author']['raw'].split()[0]
|
2017-04-26 02:57:47 +02:00
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def get_normal_push_body(payload: Dict[str, Any], change: Dict[str, Any]) -> str:
|
2016-10-02 09:44:33 +02:00
|
|
|
commits_data = [{
|
2017-04-26 02:57:47 +02:00
|
|
|
'name': get_commit_author_name(commit),
|
2016-10-02 09:44:33 +02:00
|
|
|
'sha': commit.get('hash'),
|
|
|
|
'url': commit.get('links').get('html').get('href'),
|
|
|
|
'message': commit.get('message'),
|
|
|
|
} for commit in change['commits']]
|
|
|
|
|
|
|
|
return get_push_commits_event_message(
|
|
|
|
get_user_username(payload),
|
|
|
|
change['links']['html']['href'],
|
|
|
|
change['new']['name'],
|
2016-11-11 12:45:58 +01:00
|
|
|
commits_data,
|
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
|
|
|
is_truncated=change['truncated'],
|
2016-07-04 23:06:44 +02:00
|
|
|
)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_fork_body(payload: Dict[str, Any]) -> str:
|
2016-07-04 23:06:44 +02:00
|
|
|
return BITBUCKET_FORK_BODY.format(
|
|
|
|
display_name=get_user_display_name(payload),
|
|
|
|
username=get_user_username(payload),
|
2016-10-05 19:48:15 +02:00
|
|
|
fork_name=get_repository_full_name(payload['fork']),
|
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=get_repository_url(payload['fork']),
|
2016-07-04 23:06:44 +02:00
|
|
|
)
|
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def get_commit_comment_body(payload: Dict[str, Any]) -> str:
|
2017-05-24 23:03:06 +02:00
|
|
|
comment = payload['comment']
|
2020-04-09 21:51:58 +02:00
|
|
|
action = '[commented]({})'.format(comment['links']['html']['href'])
|
2016-10-27 21:43:15 +02:00
|
|
|
return get_commits_comment_action_message(
|
2016-10-21 20:08:26 +02:00
|
|
|
get_user_username(payload),
|
|
|
|
action,
|
|
|
|
comment['commit']['links']['html']['href'],
|
2016-10-27 21:43:15 +02:00
|
|
|
comment['commit']['hash'],
|
|
|
|
comment['content']['raw'],
|
2016-07-04 23:06:44 +02:00
|
|
|
)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_commit_status_changed_body(payload: Dict[str, Any]) -> str:
|
2018-09-22 22:38:52 +02:00
|
|
|
commit_api_url = payload['commit_status']['links']['commit']['href']
|
|
|
|
commit_id = commit_api_url.split('/')[-1]
|
|
|
|
|
2018-09-22 22:57:45 +02:00
|
|
|
commit_info = "[{short_commit_id}]({repo_url}/commits/{commit_id})".format(
|
|
|
|
repo_url=get_repository_url(payload['repository']),
|
|
|
|
short_commit_id=commit_id[:7],
|
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
|
|
|
commit_id=commit_id,
|
2018-09-22 22:38:52 +02:00
|
|
|
)
|
2016-07-04 23:06:44 +02:00
|
|
|
|
|
|
|
return BITBUCKET_COMMIT_STATUS_CHANGED_BODY.format(
|
|
|
|
key=payload['commit_status']['key'],
|
|
|
|
system_url=payload['commit_status']['url'],
|
|
|
|
commit_info=commit_info,
|
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
|
|
|
status=payload['commit_status']['state'],
|
2016-07-04 23:06:44 +02:00
|
|
|
)
|
|
|
|
|
2018-07-25 00:57:45 +02:00
|
|
|
def get_issue_commented_body(payload: Dict[str, Any],
|
|
|
|
include_title: Optional[bool]=False) -> str:
|
2016-10-26 20:47:12 +02:00
|
|
|
action = '[commented]({}) on'.format(payload['comment']['links']['html']['href'])
|
2018-07-25 00:57:45 +02:00
|
|
|
return get_issue_action_body(payload, action, include_title)
|
2016-10-21 20:08:26 +02:00
|
|
|
|
2018-07-25 00:57:45 +02:00
|
|
|
def get_issue_action_body(payload: Dict[str, Any], action: str,
|
|
|
|
include_title: Optional[bool]=False) -> str:
|
2016-10-19 23:44:02 +02:00
|
|
|
issue = payload['issue']
|
|
|
|
assignee = None
|
|
|
|
message = None
|
|
|
|
if action == 'created':
|
|
|
|
if issue['assignee']:
|
|
|
|
assignee = issue['assignee'].get('username')
|
|
|
|
message = issue['content']['raw']
|
|
|
|
|
|
|
|
return get_issue_event_message(
|
|
|
|
get_user_username(payload),
|
|
|
|
action,
|
|
|
|
issue['links']['html']['href'],
|
2016-10-26 21:13:00 +02:00
|
|
|
issue['id'],
|
2016-10-19 23:44:02 +02:00
|
|
|
message,
|
2018-07-25 00:57:45 +02:00
|
|
|
assignee,
|
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=issue['title'] if include_title else None,
|
2016-07-04 23:06:44 +02:00
|
|
|
)
|
|
|
|
|
2018-07-25 00:57:45 +02:00
|
|
|
def get_pull_request_action_body(payload: Dict[str, Any], action: str,
|
|
|
|
include_title: Optional[bool]=False) -> str:
|
2016-10-11 18:55:39 +02:00
|
|
|
pull_request = payload['pullrequest']
|
|
|
|
return get_pull_request_event_message(
|
|
|
|
get_user_username(payload),
|
|
|
|
action,
|
|
|
|
get_pull_request_url(pull_request),
|
2018-07-25 00:57:45 +02:00
|
|
|
pull_request.get('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=pull_request['title'] if include_title else None,
|
2016-10-11 18:55:39 +02:00
|
|
|
)
|
|
|
|
|
2018-07-25 00:57:45 +02:00
|
|
|
def get_pull_request_created_or_updated_body(payload: Dict[str, Any], action: str,
|
|
|
|
include_title: Optional[bool]=False) -> str:
|
2016-10-11 18:55:39 +02:00
|
|
|
pull_request = payload['pullrequest']
|
|
|
|
assignee = None
|
|
|
|
if pull_request.get('reviewers'):
|
2019-06-22 21:45:15 +02:00
|
|
|
assignee = pull_request.get('reviewers')[0]
|
|
|
|
# Certain payloads may not contain a username, so we
|
|
|
|
# return the user's display name or nickname instead.
|
|
|
|
assignee = (assignee.get('username') or assignee.get('display_name') or
|
|
|
|
assignee.get('nickname'))
|
2016-10-11 18:55:39 +02:00
|
|
|
|
|
|
|
return get_pull_request_event_message(
|
|
|
|
get_user_username(payload),
|
|
|
|
action,
|
|
|
|
get_pull_request_url(pull_request),
|
2016-10-26 21:13:00 +02:00
|
|
|
pull_request.get('id'),
|
2016-10-11 18:55:39 +02:00
|
|
|
target_branch=pull_request['source']['branch']['name'],
|
|
|
|
base_branch=pull_request['destination']['branch']['name'],
|
2016-10-19 15:57:57 +02:00
|
|
|
message=pull_request['description'],
|
2018-07-25 00:57:45 +02:00
|
|
|
assignee=assignee,
|
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=pull_request['title'] if include_title else None,
|
2016-07-04 23:06:44 +02:00
|
|
|
)
|
|
|
|
|
2018-07-25 00:57:45 +02:00
|
|
|
def get_pull_request_comment_created_action_body(
|
|
|
|
payload: Dict[str, Any],
|
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
|
|
|
include_title: Optional[bool]=False,
|
2018-07-25 00:57:45 +02:00
|
|
|
) -> str:
|
2016-10-21 20:08:26 +02:00
|
|
|
action = '[commented]({})'.format(payload['comment']['links']['html']['href'])
|
2018-07-25 00:57:45 +02:00
|
|
|
return get_pull_request_comment_action_body(payload, action, include_title)
|
2016-10-21 20:08:26 +02:00
|
|
|
|
2018-07-25 00:57:45 +02:00
|
|
|
def get_pull_request_deleted_or_updated_comment_action_body(
|
|
|
|
payload: Dict[str, Any], action: str,
|
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
|
|
|
include_title: Optional[bool]=False,
|
2018-07-25 00:57:45 +02:00
|
|
|
) -> str:
|
2016-11-03 17:37:20 +01:00
|
|
|
action = "{} a [comment]({})".format(action, payload['comment']['links']['html']['href'])
|
2018-07-25 00:57:45 +02:00
|
|
|
return get_pull_request_comment_action_body(payload, action, include_title)
|
2016-10-21 20:08:26 +02:00
|
|
|
|
2018-07-25 00:57:45 +02:00
|
|
|
def get_pull_request_comment_action_body(
|
|
|
|
payload: Dict[str, Any], action: str,
|
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
|
|
|
include_title: Optional[bool]=False,
|
2018-07-25 00:57:45 +02:00
|
|
|
) -> str:
|
2016-10-26 20:47:12 +02:00
|
|
|
action += ' on'
|
2016-10-21 20:08:26 +02:00
|
|
|
return get_pull_request_event_message(
|
|
|
|
get_user_username(payload),
|
|
|
|
action,
|
|
|
|
payload['pullrequest']['links']['html']['href'],
|
2016-10-26 21:13:00 +02:00
|
|
|
payload['pullrequest']['id'],
|
2018-07-25 00:57:45 +02:00
|
|
|
message=payload['comment']['content']['raw'],
|
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=payload['pullrequest']['title'] if include_title else None,
|
2016-07-04 23:06:44 +02:00
|
|
|
)
|
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def get_push_tag_body(payload: Dict[str, Any], change: Dict[str, Any]) -> str:
|
2020-04-08 01:59:03 +02:00
|
|
|
if change.get('new'):
|
2017-05-24 23:03:06 +02:00
|
|
|
tag = change['new']
|
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
|
|
|
action: Optional[str] = 'pushed'
|
2020-04-08 01:59:03 +02:00
|
|
|
elif change.get('old'):
|
2017-05-24 23:03:06 +02:00
|
|
|
tag = change['old']
|
2016-11-09 16:05:45 +01:00
|
|
|
action = 'removed'
|
2018-09-22 22:38:52 +02:00
|
|
|
|
2016-11-09 16:05:45 +01:00
|
|
|
return get_push_tag_event_message(
|
|
|
|
get_user_username(payload),
|
|
|
|
tag.get('name'),
|
2017-05-24 23:03:06 +02:00
|
|
|
tag_url=tag['links']['html'].get('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
|
|
|
action=action,
|
2016-11-09 16:05:45 +01:00
|
|
|
)
|
|
|
|
|
2019-04-19 22:02:41 +02:00
|
|
|
def append_punctuation(title: str, message: str) -> str:
|
|
|
|
if title[-1] not in string.punctuation:
|
2020-06-09 00:25:09 +02:00
|
|
|
message = f"{message}."
|
2019-04-19 22:02:41 +02:00
|
|
|
|
|
|
|
return message
|
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def get_repo_updated_body(payload: Dict[str, Any]) -> str:
|
2018-04-25 01:36:03 +02:00
|
|
|
changes = ['website', 'name', 'links', 'language', 'full_name', 'description']
|
|
|
|
body = ""
|
|
|
|
repo_name = payload['repository']['name']
|
|
|
|
actor = payload['actor']['username']
|
|
|
|
|
|
|
|
for change in changes:
|
|
|
|
new = payload['changes'][change]['new']
|
|
|
|
old = payload['changes'][change]['old']
|
|
|
|
if change == 'full_name':
|
|
|
|
change = 'full name'
|
|
|
|
if new and old:
|
|
|
|
message = BITBUCKET_REPO_UPDATED_CHANGED.format(
|
|
|
|
actor=actor, change=change, repo_name=repo_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
|
|
|
old=old, new=new,
|
2018-04-25 01:36:03 +02:00
|
|
|
)
|
2019-04-19 22:02:41 +02:00
|
|
|
message = append_punctuation(new, message) + '\n'
|
2018-04-25 01:36:03 +02:00
|
|
|
body += message
|
|
|
|
elif new and not old:
|
|
|
|
message = BITBUCKET_REPO_UPDATED_ADDED.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
|
|
|
actor=actor, change=change, repo_name=repo_name, new=new,
|
2018-04-25 01:36:03 +02:00
|
|
|
)
|
2019-04-19 22:02:41 +02:00
|
|
|
message = append_punctuation(new, message) + '\n'
|
2018-04-25 01:36:03 +02:00
|
|
|
body += message
|
|
|
|
|
|
|
|
return body
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_pull_request_url(pullrequest_payload: Dict[str, Any]) -> str:
|
2016-07-04 23:06:44 +02:00
|
|
|
return pullrequest_payload['links']['html']['href']
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_repository_url(repository_payload: Dict[str, Any]) -> str:
|
2016-07-04 23:06:44 +02:00
|
|
|
return repository_payload['links']['html']['href']
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_repository_name(repository_payload: Dict[str, Any]) -> str:
|
2016-10-05 19:48:15 +02:00
|
|
|
return repository_payload['name']
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_repository_full_name(repository_payload: Dict[str, Any]) -> str:
|
2016-07-04 23:06:44 +02:00
|
|
|
return repository_payload['full_name']
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_user_display_name(payload: Dict[str, Any]) -> str:
|
2016-07-04 23:06:44 +02:00
|
|
|
return payload['actor']['display_name']
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_user_username(payload: Dict[str, Any]) -> str:
|
2019-06-04 04:07:34 +02:00
|
|
|
actor = payload['actor']
|
|
|
|
# Certain payloads may not contain a username, so we can
|
|
|
|
# return the user's display name or nickname instead.
|
|
|
|
return actor.get('username') or actor.get('display_name') or actor.get('nickname')
|
2016-07-04 23:06:44 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_branch_name_for_push_event(payload: Dict[str, Any]) -> Optional[str]:
|
2016-10-06 16:14:51 +02:00
|
|
|
change = payload['push']['changes'][-1]
|
2017-04-05 02:52:31 +02:00
|
|
|
potential_tag = (change['new'] or change['old'] or {}).get('type')
|
|
|
|
if potential_tag == 'tag':
|
|
|
|
return None
|
2016-10-06 16:14:51 +02:00
|
|
|
else:
|
2017-04-05 02:52:31 +02:00
|
|
|
return (change['new'] or change['old']).get('name')
|
2016-10-05 19:48:15 +02:00
|
|
|
|
2016-11-09 16:05:45 +01:00
|
|
|
GET_SINGLE_MESSAGE_BODY_DEPENDING_ON_TYPE_MAPPER = {
|
2016-07-04 23:06:44 +02:00
|
|
|
'fork': get_fork_body,
|
|
|
|
'commit_comment': get_commit_comment_body,
|
|
|
|
'change_commit_status': get_commit_status_changed_body,
|
|
|
|
'issue_updated': partial(get_issue_action_body, action='updated'),
|
|
|
|
'issue_created': partial(get_issue_action_body, action='created'),
|
2016-10-21 20:08:26 +02:00
|
|
|
'issue_commented': get_issue_commented_body,
|
2016-10-11 18:55:39 +02:00
|
|
|
'pull_request_created': partial(get_pull_request_created_or_updated_body, action='created'),
|
|
|
|
'pull_request_updated': partial(get_pull_request_created_or_updated_body, action='updated'),
|
2016-07-04 23:06:44 +02:00
|
|
|
'pull_request_approved': partial(get_pull_request_action_body, action='approved'),
|
|
|
|
'pull_request_unapproved': partial(get_pull_request_action_body, action='unapproved'),
|
2017-01-11 14:17:41 +01:00
|
|
|
'pull_request_fulfilled': partial(get_pull_request_action_body, action='merged'),
|
2016-07-04 23:06:44 +02:00
|
|
|
'pull_request_rejected': partial(get_pull_request_action_body, action='rejected'),
|
2016-10-21 20:08:26 +02:00
|
|
|
'pull_request_comment_created': get_pull_request_comment_created_action_body,
|
2017-11-05 02:48:25 +01:00
|
|
|
'pull_request_comment_updated': partial(get_pull_request_deleted_or_updated_comment_action_body,
|
|
|
|
action='updated'),
|
|
|
|
'pull_request_comment_deleted': partial(get_pull_request_deleted_or_updated_comment_action_body,
|
2018-04-25 01:36:03 +02:00
|
|
|
action='deleted'),
|
2018-07-25 00:57:45 +02:00
|
|
|
'push': get_push_bodies,
|
2018-04-25 01:36:03 +02:00
|
|
|
'repo:updated': get_repo_updated_body,
|
2016-07-04 23:06:44 +02:00
|
|
|
}
|