2017-01-28 18:42:59 +01:00
|
|
|
# vim:fenc=utf-8
|
2019-11-18 21:07:30 +01:00
|
|
|
from typing import Any, Callable, Dict, Optional
|
2017-11-16 00:43:10 +01:00
|
|
|
|
|
|
|
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
|
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,
|
|
|
|
get_http_headers_from_filename,
|
|
|
|
validate_extract_webhook_http_header,
|
|
|
|
)
|
|
|
|
from zerver.lib.webhooks.git import (
|
|
|
|
TOPIC_WITH_BRANCH_TEMPLATE,
|
|
|
|
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE,
|
|
|
|
TOPIC_WITH_RELEASE_TEMPLATE,
|
|
|
|
get_create_branch_event_message,
|
|
|
|
get_issue_event_message,
|
|
|
|
get_pull_request_event_message,
|
|
|
|
get_push_commits_event_message,
|
|
|
|
get_release_event_message,
|
|
|
|
)
|
2017-10-31 04:25:48 +01:00
|
|
|
from zerver.models import UserProfile
|
2017-01-28 18:42:59 +01:00
|
|
|
|
2019-07-04 20:48:51 +02:00
|
|
|
fixture_to_headers = get_http_headers_from_filename("HTTP_X_GOGS_EVENT")
|
|
|
|
|
2019-11-18 03:41:13 +01:00
|
|
|
def get_issue_url(repo_url: str, issue_nr: int) -> str:
|
2020-06-09 00:25:09 +02:00
|
|
|
return f"{repo_url}/issues/{issue_nr}"
|
2019-11-18 03:41:13 +01:00
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def format_push_event(payload: Dict[str, Any]) -> str:
|
2017-01-28 18:42:59 +01:00
|
|
|
|
|
|
|
for commit in payload['commits']:
|
|
|
|
commit['sha'] = commit['id']
|
2017-04-26 02:57:47 +02:00
|
|
|
commit['name'] = (commit['author']['username'] or
|
|
|
|
commit['author']['name'].split()[0])
|
2017-01-28 18:42:59 +01:00
|
|
|
|
|
|
|
data = {
|
|
|
|
'user_name': payload['sender']['username'],
|
|
|
|
'compare_url': payload['compare_url'],
|
|
|
|
'branch_name': payload['ref'].replace('refs/heads/', ''),
|
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
|
|
|
'commits_data': payload['commits'],
|
2017-01-28 18:42:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return get_push_commits_event_message(**data)
|
|
|
|
|
2018-05-11 01:43:34 +02:00
|
|
|
def format_new_branch_event(payload: Dict[str, Any]) -> str:
|
2017-01-28 18:42:59 +01:00
|
|
|
|
|
|
|
branch_name = payload['ref']
|
|
|
|
url = '{}/src/{}'.format(payload['repository']['html_url'], branch_name)
|
|
|
|
|
|
|
|
data = {
|
|
|
|
'user_name': payload['sender']['username'],
|
|
|
|
'url': url,
|
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,
|
2017-01-28 18:42:59 +01:00
|
|
|
}
|
|
|
|
return get_create_branch_event_message(**data)
|
|
|
|
|
2018-07-23 20:14:24 +02:00
|
|
|
def format_pull_request_event(payload: Dict[str, Any],
|
|
|
|
include_title: Optional[bool]=False) -> str:
|
2017-01-28 18:42:59 +01:00
|
|
|
|
|
|
|
data = {
|
|
|
|
'user_name': payload['pull_request']['user']['username'],
|
|
|
|
'action': payload['action'],
|
|
|
|
'url': payload['pull_request']['html_url'],
|
|
|
|
'number': payload['pull_request']['number'],
|
|
|
|
'target_branch': payload['pull_request']['head_branch'],
|
|
|
|
'base_branch': payload['pull_request']['base_branch'],
|
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['pull_request']['title'] if include_title else None,
|
2017-01-28 18:42:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if payload['pull_request']['merged']:
|
|
|
|
data['user_name'] = payload['pull_request']['merged_by']['username']
|
|
|
|
data['action'] = 'merged'
|
|
|
|
|
|
|
|
return get_pull_request_event_message(**data)
|
|
|
|
|
2019-11-18 03:41:13 +01:00
|
|
|
def format_issues_event(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str:
|
|
|
|
issue_nr = payload['issue']['number']
|
|
|
|
assignee = payload['issue']['assignee']
|
|
|
|
return get_issue_event_message(
|
|
|
|
payload['sender']['login'],
|
|
|
|
payload['action'],
|
|
|
|
get_issue_url(payload['repository']['html_url'], issue_nr),
|
|
|
|
issue_nr,
|
|
|
|
payload['issue']['body'],
|
|
|
|
assignee=assignee['login'] if assignee 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=payload['issue']['title'] if include_title else None,
|
2019-11-18 03:41:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def format_issue_comment_event(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str:
|
|
|
|
action = payload['action']
|
|
|
|
comment = payload['comment']
|
|
|
|
issue = payload['issue']
|
|
|
|
|
|
|
|
if action == 'created':
|
|
|
|
action = '[commented]'
|
|
|
|
else:
|
2020-06-09 00:25:09 +02:00
|
|
|
action = f'{action} a [comment]'
|
2019-11-18 03:41:13 +01:00
|
|
|
action += '({}) on'.format(comment['html_url'])
|
|
|
|
|
|
|
|
return get_issue_event_message(
|
|
|
|
payload['sender']['login'],
|
|
|
|
action,
|
|
|
|
get_issue_url(payload['repository']['html_url'], issue['number']),
|
|
|
|
issue['number'],
|
|
|
|
comment['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
|
|
|
title=issue['title'] if include_title else None,
|
2019-11-18 03:41:13 +01:00
|
|
|
)
|
|
|
|
|
2020-05-11 08:58:53 +02:00
|
|
|
def format_release_event(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str:
|
|
|
|
data = {
|
|
|
|
'user_name': payload['release']['author']['username'],
|
|
|
|
'action': payload['action'],
|
|
|
|
'tagname': payload['release']['tag_name'],
|
|
|
|
'release_name': payload['release']['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
|
|
|
'url': payload['repository']['html_url'],
|
2020-05-11 08:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return get_release_event_message(**data)
|
|
|
|
|
2017-01-28 18:42:59 +01:00
|
|
|
@api_key_only_webhook_view('Gogs')
|
|
|
|
@has_request_variables
|
2017-12-18 15:08:41 +01:00
|
|
|
def api_gogs_webhook(request: HttpRequest, user_profile: UserProfile,
|
|
|
|
payload: Dict[str, Any]=REQ(argument_type='body'),
|
2018-07-23 20:14:24 +02:00
|
|
|
branches: Optional[str]=REQ(default=None),
|
|
|
|
user_specified_topic: Optional[str]=REQ("topic", default=None)) -> HttpResponse:
|
2019-11-18 21:07:30 +01:00
|
|
|
return gogs_webhook_main("Gogs", "X_GOGS_EVENT", format_pull_request_event,
|
|
|
|
request, user_profile, payload, branches, user_specified_topic)
|
|
|
|
|
|
|
|
def gogs_webhook_main(integration_name: str, http_header_name: str,
|
|
|
|
format_pull_request_event: Callable[..., Any],
|
|
|
|
request: HttpRequest, user_profile: UserProfile,
|
|
|
|
payload: Dict[str, Any],
|
|
|
|
branches: Optional[str],
|
|
|
|
user_specified_topic: Optional[str]) -> HttpResponse:
|
2017-01-28 18:42:59 +01:00
|
|
|
repo = payload['repository']['name']
|
2019-11-18 21:07:30 +01:00
|
|
|
event = validate_extract_webhook_http_header(request, http_header_name, integration_name)
|
2017-08-24 17:31:04 +02:00
|
|
|
if event == 'push':
|
|
|
|
branch = payload['ref'].replace('refs/heads/', '')
|
2019-11-18 03:41:13 +01:00
|
|
|
if branches is not None and branch not in branches.split(','):
|
2017-08-24 17:31:04 +02:00
|
|
|
return json_success()
|
|
|
|
body = format_push_event(payload)
|
2018-11-09 20:59:15 +01:00
|
|
|
topic = TOPIC_WITH_BRANCH_TEMPLATE.format(
|
2017-08-24 17:31:04 +02:00
|
|
|
repo=repo,
|
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=branch,
|
2017-08-24 17:31:04 +02:00
|
|
|
)
|
|
|
|
elif event == 'create':
|
|
|
|
body = format_new_branch_event(payload)
|
2018-11-09 20:59:15 +01:00
|
|
|
topic = TOPIC_WITH_BRANCH_TEMPLATE.format(
|
2017-08-24 17:31:04 +02:00
|
|
|
repo=repo,
|
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=payload['ref'],
|
2017-08-24 17:31:04 +02:00
|
|
|
)
|
|
|
|
elif event == 'pull_request':
|
2018-07-23 20:14:24 +02:00
|
|
|
body = format_pull_request_event(
|
|
|
|
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-23 20:14:24 +02:00
|
|
|
)
|
2018-11-09 20:59:15 +01:00
|
|
|
topic = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
2017-08-24 17:31:04 +02:00
|
|
|
repo=repo,
|
|
|
|
type='PR',
|
|
|
|
id=payload['pull_request']['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['pull_request']['title'],
|
2017-08-24 17:31:04 +02:00
|
|
|
)
|
2019-11-18 03:41:13 +01:00
|
|
|
elif event == 'issues':
|
|
|
|
body = format_issues_event(
|
|
|
|
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,
|
2019-11-18 03:41:13 +01:00
|
|
|
)
|
|
|
|
topic = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
|
|
|
repo=repo,
|
|
|
|
type='Issue',
|
|
|
|
id=payload['issue']['number'],
|
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'],
|
2019-11-18 03:41:13 +01:00
|
|
|
)
|
|
|
|
elif event == 'issue_comment':
|
|
|
|
body = format_issue_comment_event(
|
|
|
|
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,
|
2019-11-18 03:41:13 +01:00
|
|
|
)
|
|
|
|
topic = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
|
|
|
repo=repo,
|
|
|
|
type='Issue',
|
|
|
|
id=payload['issue']['number'],
|
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'],
|
2019-11-18 03:41:13 +01:00
|
|
|
)
|
2020-05-11 08:58:53 +02:00
|
|
|
elif event == 'release':
|
|
|
|
body = format_release_event(
|
|
|
|
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,
|
2020-05-11 08:58:53 +02:00
|
|
|
)
|
|
|
|
topic = TOPIC_WITH_RELEASE_TEMPLATE.format(
|
|
|
|
repo=repo,
|
|
|
|
tag=payload['release']['tag_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
|
|
|
title=payload['release']['name'],
|
2020-05-11 08:58:53 +02:00
|
|
|
)
|
|
|
|
|
2017-08-24 17:31:04 +02:00
|
|
|
else:
|
2018-05-22 16:46:45 +02:00
|
|
|
raise UnexpectedWebhookEventType('Gogs', event)
|
2017-01-28 18:42:59 +01:00
|
|
|
|
2018-03-16 22:53:50 +01:00
|
|
|
check_send_webhook_message(request, user_profile, topic, body)
|
2017-01-28 18:42:59 +01:00
|
|
|
return json_success()
|