mirror of https://github.com/zulip/zulip.git
webhooks: Replace SUBJECT_WITH_* with TOPIC_WITH_*.
This commit is contained in:
parent
ced4d81856
commit
ea98a44db3
|
@ -47,7 +47,6 @@ FILES_WITH_LEGACY_SUBJECT = {
|
|||
'zerver/lib/onboarding.py',
|
||||
'zerver/lib/stream_topic.py',
|
||||
'zerver/lib/url_encoding.py',
|
||||
'zerver/lib/webhooks/git.py',
|
||||
}
|
||||
|
||||
def custom_check_file(fn, identifier, rules, color, skip_rules=None, max_length=None):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Optional, Any, Dict, List, Tuple
|
||||
from collections import defaultdict
|
||||
SUBJECT_WITH_BRANCH_TEMPLATE = '{repo} / {branch}'
|
||||
SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE = '{repo} / {type} #{id} {title}'
|
||||
TOPIC_WITH_BRANCH_TEMPLATE = '{repo} / {branch}'
|
||||
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE = '{repo} / {type} #{id} {title}'
|
||||
|
||||
EMPTY_SHA = '0000000000000000000000000000000000000000'
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from zerver.lib.request import REQ, has_request_variables
|
|||
from zerver.lib.response import json_success
|
||||
from zerver.lib.validator import check_dict
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
from zerver.lib.webhooks.git import SUBJECT_WITH_BRANCH_TEMPLATE, \
|
||||
from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \
|
||||
get_push_commits_event_message
|
||||
from zerver.models import UserProfile, get_client
|
||||
|
||||
|
@ -43,7 +43,7 @@ def api_bitbucket_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
if branches is not None and branches.find(branch) == -1:
|
||||
return json_success()
|
||||
content = get_push_commits_event_message(payload['user'], None, branch, commits)
|
||||
subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=repository['name'], branch=branch)
|
||||
subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repository['name'], branch=branch)
|
||||
|
||||
check_send_webhook_message(request, user_profile, subject, content)
|
||||
return json_success()
|
||||
|
|
|
@ -12,8 +12,8 @@ from zerver.lib.request import REQ, has_request_variables
|
|||
from zerver.lib.response import json_error, json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message, \
|
||||
validate_extract_webhook_http_header, UnexpectedWebhookEventType
|
||||
from zerver.lib.webhooks.git import SUBJECT_WITH_BRANCH_TEMPLATE, \
|
||||
SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \
|
||||
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, \
|
||||
|
@ -78,7 +78,7 @@ def api_bitbucket2_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
|
||||
def get_subject_for_branch_specified_events(payload: Dict[str, Any],
|
||||
branch_name: Optional[str]=None) -> str:
|
||||
return SUBJECT_WITH_BRANCH_TEMPLATE.format(
|
||||
return TOPIC_WITH_BRANCH_TEMPLATE.format(
|
||||
repo=get_repository_name(payload['repository']),
|
||||
branch=get_branch_name_for_push_event(payload) if branch_name is None else branch_name
|
||||
)
|
||||
|
@ -103,14 +103,14 @@ def get_subject(payload: Dict[str, Any]) -> str:
|
|||
|
||||
def get_subject_based_on_type(payload: Dict[str, Any], type: str) -> Any:
|
||||
if type.startswith('pull_request'):
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repository_name(payload['repository']),
|
||||
type='PR',
|
||||
id=payload['pullrequest']['id'],
|
||||
title=payload['pullrequest']['title']
|
||||
)
|
||||
if type.startswith('issue'):
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repository_name(payload['repository']),
|
||||
type='Issue',
|
||||
id=payload['issue']['id'],
|
||||
|
|
|
@ -12,7 +12,7 @@ from zerver.lib.response import json_success
|
|||
from zerver.lib.webhooks.common import check_send_webhook_message, \
|
||||
validate_extract_webhook_http_header, UnexpectedWebhookEventType
|
||||
from zerver.lib.webhooks.git import CONTENT_MESSAGE_TEMPLATE, \
|
||||
SUBJECT_WITH_BRANCH_TEMPLATE, SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \
|
||||
TOPIC_WITH_BRANCH_TEMPLATE, TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \
|
||||
get_commits_comment_action_message, get_issue_event_message, \
|
||||
get_pull_request_event_message, get_push_commits_event_message, \
|
||||
get_push_tag_event_message, get_setup_webhook_message
|
||||
|
@ -359,14 +359,14 @@ def is_commit_push_event(payload: Dict[str, Any]) -> bool:
|
|||
|
||||
def get_subject_based_on_type(payload: Dict[str, Any], event: str) -> str:
|
||||
if 'pull_request' in event:
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repository_name(payload),
|
||||
type='PR',
|
||||
id=payload['pull_request']['number'],
|
||||
title=payload['pull_request']['title']
|
||||
)
|
||||
elif event.startswith('issue'):
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repository_name(payload),
|
||||
type='Issue',
|
||||
id=payload['issue']['number'],
|
||||
|
@ -380,12 +380,12 @@ def get_subject_based_on_type(payload: Dict[str, Any], event: str) -> str:
|
|||
elif event == 'membership':
|
||||
return u"{} organization".format(payload['organization']['login'])
|
||||
elif event == 'push_commits':
|
||||
return SUBJECT_WITH_BRANCH_TEMPLATE.format(
|
||||
return TOPIC_WITH_BRANCH_TEMPLATE.format(
|
||||
repo=get_repository_name(payload),
|
||||
branch=get_branch_name_from_ref(payload['ref'])
|
||||
)
|
||||
elif event == 'gollum':
|
||||
return SUBJECT_WITH_BRANCH_TEMPLATE.format(
|
||||
return TOPIC_WITH_BRANCH_TEMPLATE.format(
|
||||
repo=get_repository_name(payload),
|
||||
branch='Wiki Pages'
|
||||
)
|
||||
|
|
|
@ -11,8 +11,8 @@ from zerver.decorator import authenticated_api_view, \
|
|||
from zerver.lib.request import REQ, has_request_variables, JsonableError
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.validator import check_dict
|
||||
from zerver.lib.webhooks.git import SUBJECT_WITH_BRANCH_TEMPLATE, \
|
||||
SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \
|
||||
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_remove_branch_event_message
|
||||
|
@ -103,7 +103,7 @@ def get_pull_request_or_issue_assignee(object_payload: Mapping[str, Any]) -> Opt
|
|||
def get_pull_request_or_issue_subject(repository: Mapping[str, Any],
|
||||
payload_object: Mapping[str, Any],
|
||||
type: str) -> str:
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=repository['name'],
|
||||
type=type,
|
||||
id=payload_object['number'],
|
||||
|
@ -292,7 +292,7 @@ def build_message_from_gitlog(user_profile: UserProfile, name: str, ref: str,
|
|||
created: Optional[str]=None, deleted: Optional[bool]=False
|
||||
) -> Tuple[str, str]:
|
||||
short_ref = re.sub(r'^refs/heads/', '', ref)
|
||||
subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)
|
||||
subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)
|
||||
|
||||
if re.match(r'^0+$', after):
|
||||
content = get_remove_branch_event_message(pusher, short_ref)
|
||||
|
|
|
@ -11,7 +11,7 @@ from zerver.lib.response import json_success
|
|||
from zerver.lib.webhooks.common import check_send_webhook_message, \
|
||||
validate_extract_webhook_http_header, UnexpectedWebhookEventType
|
||||
from zerver.lib.webhooks.git import EMPTY_SHA, \
|
||||
SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \
|
||||
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \
|
||||
get_commits_comment_action_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
|
||||
|
@ -323,28 +323,28 @@ def get_subject_based_on_event(event: str, payload: Dict[str, Any]) -> str:
|
|||
get_repo_name(payload),
|
||||
payload['object_attributes'].get('ref').replace('refs/heads/', ''))
|
||||
elif event.startswith('Merge Request Hook'):
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repo_name(payload),
|
||||
type='MR',
|
||||
id=payload['object_attributes'].get('iid'),
|
||||
title=payload['object_attributes'].get('title')
|
||||
)
|
||||
elif event.startswith('Issue Hook'):
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repo_name(payload),
|
||||
type='Issue',
|
||||
id=payload['object_attributes'].get('iid'),
|
||||
title=payload['object_attributes'].get('title')
|
||||
)
|
||||
elif event == 'Note Hook Issue':
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repo_name(payload),
|
||||
type='Issue',
|
||||
id=payload['issue'].get('iid'),
|
||||
title=payload['issue'].get('title')
|
||||
)
|
||||
elif event == 'Note Hook MergeRequest':
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repo_name(payload),
|
||||
type='MR',
|
||||
id=payload['merge_request'].get('iid'),
|
||||
|
@ -352,7 +352,7 @@ def get_subject_based_on_event(event: str, payload: Dict[str, Any]) -> str:
|
|||
)
|
||||
|
||||
elif event == 'Note Hook Snippet':
|
||||
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=get_repo_name(payload),
|
||||
type='Snippet',
|
||||
id=payload['snippet'].get('id'),
|
||||
|
|
|
@ -10,8 +10,8 @@ from zerver.lib.request import REQ, has_request_variables
|
|||
from zerver.lib.response import json_error, json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message, \
|
||||
validate_extract_webhook_http_header, UnexpectedWebhookEventType
|
||||
from zerver.lib.webhooks.git import SUBJECT_WITH_BRANCH_TEMPLATE, \
|
||||
SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_create_branch_event_message, \
|
||||
from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \
|
||||
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_create_branch_event_message, \
|
||||
get_pull_request_event_message, get_push_commits_event_message
|
||||
from zerver.models import UserProfile
|
||||
|
||||
|
@ -76,13 +76,13 @@ def api_gogs_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
if branches is not None and branches.find(branch) == -1:
|
||||
return json_success()
|
||||
body = format_push_event(payload)
|
||||
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
|
||||
topic = TOPIC_WITH_BRANCH_TEMPLATE.format(
|
||||
repo=repo,
|
||||
branch=branch
|
||||
)
|
||||
elif event == 'create':
|
||||
body = format_new_branch_event(payload)
|
||||
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
|
||||
topic = TOPIC_WITH_BRANCH_TEMPLATE.format(
|
||||
repo=repo,
|
||||
branch=payload['ref']
|
||||
)
|
||||
|
@ -91,7 +91,7 @@ def api_gogs_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
payload,
|
||||
include_title=user_specified_topic is not None
|
||||
)
|
||||
topic = SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
topic = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
|
||||
repo=repo,
|
||||
type='PR',
|
||||
id=payload['pull_request']['id'],
|
||||
|
|
Loading…
Reference in New Issue