integrations: Replace use of 'subject' to 'topic'.

Fixes #25974
This commit is contained in:
abdullahm1 2023-07-12 16:37:08 +05:00 committed by Tim Abbott
parent 7036b0d466
commit a0fb4feebf
39 changed files with 167 additions and 169 deletions

View File

@ -19,13 +19,13 @@ def api_airbrake_webhook(
user_profile: UserProfile,
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
subject = get_subject(payload)
topic = get_topic(payload)
body = get_body(payload)
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)
def get_subject(payload: WildValue) -> str:
def get_topic(payload: WildValue) -> str:
return AIRBRAKE_TOPIC_TEMPLATE.format(
project_name=payload["error"]["project"]["name"].tame(check_string)
)

View File

@ -29,9 +29,9 @@ def api_ansibletower_webhook(
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
body = get_body(payload)
subject = payload["name"].tame(check_string)
topic = payload["name"].tame(check_string)
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)

View File

@ -24,13 +24,13 @@ def api_appveyor_webhook(
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
body = get_body_for_http_request(payload)
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
event_data = payload["eventData"]
return APPVEYOR_TOPIC_TEMPLATE.format(project_name=event_data["projectName"].tame(check_string))

View File

@ -49,7 +49,7 @@ def api_basecamp_webhook(
if event not in SUPPORT_EVENTS:
raise UnsupportedWebhookEventTypeError(event)
subject = get_project_name(payload)
topic = get_project_name(payload)
if event.startswith("document_"):
body = get_document_body(event, payload)
event = "document"
@ -74,7 +74,7 @@ def api_basecamp_webhook(
else:
raise UnsupportedWebhookEventTypeError(event)
check_send_webhook_message(request, user_profile, subject, body, event)
check_send_webhook_message(request, user_profile, topic, body, event)
return json_success(request)
@ -90,11 +90,11 @@ def get_event_creator(payload: WildValue) -> str:
return payload["creator"]["name"].tame(check_string)
def get_subject_url(payload: WildValue) -> str:
def get_topic_url(payload: WildValue) -> str:
return payload["recording"]["app_url"].tame(check_string)
def get_subject_title(payload: WildValue) -> str:
def get_topic_title(payload: WildValue) -> str:
return payload["recording"]["title"].tame(check_string)
@ -128,7 +128,7 @@ def get_questions_answer_body(event: str, payload: WildValue) -> str:
return template.format(
user_name=get_event_creator(payload),
verb=verb,
answer_url=get_subject_url(payload),
answer_url=get_topic_url(payload),
question_title=title,
question_url=question["app_url"].tame(check_string),
)
@ -142,7 +142,7 @@ def get_comment_body(event: str, payload: WildValue) -> str:
return template.format(
user_name=get_event_creator(payload),
verb=verb,
answer_url=get_subject_url(payload),
answer_url=get_topic_url(payload),
task_title=task["title"].tame(check_string),
task_url=task["app_url"].tame(check_string),
)
@ -166,12 +166,12 @@ def get_todo_body(event: str, payload: WildValue) -> str:
def get_generic_body(event: str, payload: WildValue, prefix: str, template: str) -> str:
verb = get_verb(event, prefix)
title = get_subject_title(payload)
title = get_topic_title(payload)
template = add_punctuation_if_necessary(template, title)
return template.format(
user_name=get_event_creator(payload),
verb=verb,
title=get_subject_title(payload),
url=get_subject_url(payload),
title=get_topic_title(payload),
url=get_topic_url(payload),
)

View File

@ -27,12 +27,12 @@ def build_message_from_gitlog(
deleted: bool = False,
) -> Tuple[str, str]:
short_ref = re.sub(r"^refs/heads/", "", ref)
subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)
topic = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)
commits_data = _transform_commits_list_to_common_format(commits)
content = get_push_commits_event_message(pusher, url, short_ref, commits_data, deleted=deleted)
return subject, content
return topic, content
def _transform_commits_list_to_common_format(commits: WildValue) -> List[Dict[str, str]]:
@ -70,7 +70,7 @@ def api_beanstalk_webhook(
if branches is not None and branches.find(payload["branch"].tame(check_string)) == -1:
return json_success(request)
subject, content = build_message_from_gitlog(
topic, content = build_message_from_gitlog(
user_profile,
payload["repository"]["name"].tame(check_string),
payload["ref"].tame(check_string),
@ -86,8 +86,8 @@ def api_beanstalk_webhook(
revision = payload["revision"].tame(check_int)
(short_commit_msg, _, _) = payload["message"].tame(check_string).partition("\n")
subject = f"svn r{revision}"
topic = f"svn r{revision}"
content = f"{author} pushed [revision {revision}]({url}):\n\n> {short_commit_msg}"
check_send_webhook_message(request, user_profile, subject, content)
check_send_webhook_message(request, user_profile, topic, content)
return json_success(request)

View File

@ -40,7 +40,7 @@ def api_bitbucket_webhook(
if len(commits) == 0:
# Bitbucket doesn't give us enough information to really give
# a useful message :/
subject = repository["name"].tame(check_string)
topic = repository["name"].tame(check_string)
content = "{} [force pushed]({}).".format(
payload.get("user", "Someone").tame(check_string),
payload["canon_url"].tame(check_string) + repository["absolute_url"].tame(check_string),
@ -52,9 +52,9 @@ def api_bitbucket_webhook(
committer = payload.get("user", "Someone").tame(check_string)
content = get_push_commits_event_message(committer, None, branch, commits)
subject = TOPIC_WITH_BRANCH_TEMPLATE.format(
topic = TOPIC_WITH_BRANCH_TEMPLATE.format(
repo=repository["name"].tame(check_string), branch=branch
)
check_send_webhook_message(request, user_profile, subject, content, unquote_url_parameters=True)
check_send_webhook_message(request, user_profile, topic, content, unquote_url_parameters=True)
return json_success(request)

View File

@ -93,15 +93,15 @@ def api_bitbucket2_webhook(
if branch and branches and branches.find(branch) == -1:
return json_success(request)
subjects = get_push_subjects(payload)
topics = get_push_topics(payload)
bodies = get_push_bodies(request, payload)
for b, s in zip(bodies, subjects):
for b, t in zip(bodies, topics):
check_send_webhook_message(
request, user_profile, s, b, type, unquote_url_parameters=True
request, user_profile, t, b, type, unquote_url_parameters=True
)
else:
subject = get_subject_based_on_type(payload, type)
topic = get_topic_based_on_type(payload, type)
body_function = get_body_based_on_type(type)
body = body_function(
request,
@ -110,13 +110,13 @@ def api_bitbucket2_webhook(
)
check_send_webhook_message(
request, user_profile, subject, body, type, unquote_url_parameters=True
request, user_profile, topic, body, type, unquote_url_parameters=True
)
return json_success(request)
def get_subject_for_branch_specified_events(
def get_topic_for_branch_specified_events(
payload: WildValue, branch_name: Optional[str] = None
) -> str:
return TOPIC_WITH_BRANCH_TEMPLATE.format(
@ -125,28 +125,28 @@ def get_subject_for_branch_specified_events(
)
def get_push_subjects(payload: WildValue) -> List[str]:
subjects_list = []
def get_push_topics(payload: WildValue) -> List[str]:
topics_list = []
for change in payload["push"]["changes"]:
potential_tag = (change["new"] or change["old"])["type"].tame(check_string)
if potential_tag == "tag":
subjects_list.append(get_subject(payload))
topics_list.append(get_topic(payload))
else:
if change.get("new"):
branch_name = change["new"]["name"].tame(check_string)
else:
branch_name = change["old"]["name"].tame(check_string)
subjects_list.append(get_subject_for_branch_specified_events(payload, branch_name))
return subjects_list
topics_list.append(get_topic_for_branch_specified_events(payload, branch_name))
return topics_list
def get_subject(payload: WildValue) -> str:
def get_topic(payload: WildValue) -> str:
return BITBUCKET_TOPIC_TEMPLATE.format(
repository_name=get_repository_name(payload["repository"])
)
def get_subject_based_on_type(payload: WildValue, type: str) -> str:
def get_topic_based_on_type(payload: WildValue, type: str) -> str:
if type.startswith("pull_request"):
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repository_name(payload["repository"]),
@ -162,7 +162,7 @@ def get_subject_based_on_type(payload: WildValue, type: str) -> str:
title=payload["issue"]["title"].tame(check_string),
)
assert type != "push"
return get_subject(payload)
return get_topic(payload)
def get_type(request: HttpRequest, payload: WildValue) -> str:

View File

@ -75,11 +75,11 @@ def ping_handler(
include_title: Optional[str],
) -> List[Dict[str, str]]:
if include_title:
subject = include_title
topic = include_title
else:
subject = "Bitbucket Server Ping"
topic = "Bitbucket Server Ping"
body = "Congratulations! The Bitbucket Server webhook was configured successfully!"
return [{"subject": subject, "body": body}]
return [{"topic": topic, "body": body}]
def repo_comment_handler(
@ -89,7 +89,7 @@ def repo_comment_handler(
include_title: Optional[str],
) -> List[Dict[str, str]]:
repo_name = payload["repository"]["name"].tame(check_string)
subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
topic = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
sha = payload["commit"].tame(check_string)
commit_url = payload["repository"]["links"]["self"][0]["href"].tame(check_string)[
: -len("browse")
@ -105,7 +105,7 @@ def repo_comment_handler(
sha=sha,
message=message,
)
return [{"subject": subject, "body": body}]
return [{"topic": topic, "body": body}]
def repo_forked_handler(
@ -114,14 +114,14 @@ def repo_forked_handler(
include_title: Optional[str],
) -> List[Dict[str, str]]:
repo_name = payload["repository"]["origin"]["name"].tame(check_string)
subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
topic = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
body = BITBUCKET_FORK_BODY.format(
display_name=payload["actor"]["displayName"].tame(check_string),
username=get_user_name(payload),
fork_name=payload["repository"]["name"].tame(check_string),
fork_url=payload["repository"]["links"]["self"][0]["href"].tame(check_string),
)
return [{"subject": subject, "body": body}]
return [{"topic": topic, "body": body}]
def repo_modified_handler(
@ -129,7 +129,7 @@ def repo_modified_handler(
branches: Optional[str],
include_title: Optional[str],
) -> List[Dict[str, str]]:
subject_new = BITBUCKET_TOPIC_TEMPLATE.format(
topic_new = BITBUCKET_TOPIC_TEMPLATE.format(
repository_name=payload["new"]["name"].tame(check_string)
)
new_name = payload["new"]["name"].tame(check_string)
@ -142,7 +142,7 @@ def repo_modified_handler(
) # As of writing this, the only change we'd be notified about is a name change.
punctuation = "." if new_name[-1] not in string.punctuation else ""
body = f"{body}{punctuation}"
return [{"subject": subject_new, "body": body}]
return [{"topic": topic_new, "body": body}]
def repo_push_branch_data(payload: WildValue, change: WildValue) -> Dict[str, str]:
@ -170,8 +170,8 @@ def repo_push_branch_data(payload: WildValue, change: WildValue) -> Dict[str, st
message = "{}.{}".format(payload["eventKey"].tame(check_string), event_type) # nocoverage
raise UnsupportedWebhookEventTypeError(message)
subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repo_name, branch=branch_name)
return {"subject": subject, "body": body}
topic = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repo_name, branch=branch_name)
return {"topic": topic, "body": body}
def repo_push_tag_data(payload: WildValue, change: WildValue) -> Dict[str, str]:
@ -187,9 +187,9 @@ def repo_push_tag_data(payload: WildValue, change: WildValue) -> Dict[str, str]:
message = "{}.{}".format(payload["eventKey"].tame(check_string), event_type) # nocoverage
raise UnsupportedWebhookEventTypeError(message)
subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
topic = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
body = get_push_tag_event_message(get_user_name(payload), tag_name, action=action)
return {"subject": subject, "body": body}
return {"topic": topic, "body": body}
def repo_push_handler(
@ -230,7 +230,7 @@ def get_assignees_string(pr: WildValue) -> Optional[str]:
return assignees
def get_pr_subject(repo: str, type: str, id: int, title: str) -> str:
def get_pr_topic(repo: str, type: str, id: int, title: str) -> str:
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(repo=repo, type=type, id=id, title=title)
@ -341,7 +341,7 @@ def pr_handler(
include_title: Optional[str],
) -> List[Dict[str, str]]:
pr = payload["pullRequest"]
subject = get_pr_subject(
topic = get_pr_topic(
pr["toRef"]["repository"]["name"].tame(check_string),
type="PR",
id=pr["id"].tame(check_int),
@ -358,7 +358,7 @@ def pr_handler(
else:
body = get_simple_pr_body(payload, action, include_title)
return [{"subject": subject, "body": body}]
return [{"topic": topic, "body": body}]
def pr_comment_handler(
@ -368,7 +368,7 @@ def pr_comment_handler(
include_title: Optional[str],
) -> List[Dict[str, str]]:
pr = payload["pullRequest"]
subject = get_pr_subject(
topic = get_pr_topic(
pr["toRef"]["repository"]["name"].tame(check_string),
type="PR",
id=pr["id"].tame(check_int),
@ -386,7 +386,7 @@ def pr_comment_handler(
title=pr["title"].tame(check_string) if include_title else None,
)
return [{"subject": subject, "body": body}]
return [{"topic": topic, "body": body}]
class EventHandler(Protocol):
@ -447,7 +447,7 @@ def api_bitbucket3_webhook(
check_send_webhook_message(
request,
user_profile,
element["subject"],
element["topic"],
element["body"],
eventkey,
unquote_url_parameters=True,

View File

@ -67,12 +67,12 @@ def api_circleci_webhook(
type = payload["type"].tame(check_string)
if type == "ping":
# Ping events don't have full payloads, so our normal codepath won't work
subject = "Test event"
topic = "Test event"
body = "Webhook '{name}' test event successful.".format(
name=payload["webhook"]["name"].tame(check_string)
)
else:
subject = get_subject(payload)
topic = get_topic(payload)
body = get_body(payload)
# We currently don't support projects using VCS providers other than GitHub,
@ -86,14 +86,14 @@ def api_circleci_webhook(
check_send_webhook_message(
request,
user_profile,
subject,
topic,
body,
payload["type"].tame(check_string),
)
return json_success(request)
def get_subject(payload: WildValue) -> str:
def get_topic(payload: WildValue) -> str:
return payload["project"]["name"].tame(check_string)

View File

@ -29,14 +29,14 @@ def api_codeship_webhook(
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
payload = payload["build"]
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
body = get_body_for_http_request(payload)
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
return CODESHIP_TOPIC_TEMPLATE.format(
project_name=payload["project_name"].tame(check_string),
)

View File

@ -26,11 +26,11 @@ def api_crashlytics_webhook(
) -> HttpResponse:
event = payload["event"]
if event == VERIFICATION_EVENT:
subject = CRASHLYTICS_SETUP_TOPIC_TEMPLATE
topic = CRASHLYTICS_SETUP_TOPIC_TEMPLATE
body = CRASHLYTICS_SETUP_MESSAGE_TEMPLATE
else:
issue_body = payload["payload"]
subject = CRASHLYTICS_TOPIC_TEMPLATE.format(
topic = CRASHLYTICS_TOPIC_TEMPLATE.format(
display_id=issue_body["display_id"].tame(check_int),
title=issue_body["title"].tame(check_string),
)
@ -39,5 +39,5 @@ def api_crashlytics_webhook(
url=issue_body["url"].tame(check_string),
)
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)

View File

@ -18,13 +18,13 @@ def api_errbit_webhook(
user_profile: UserProfile,
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
subject = get_subject(payload)
topic = get_topic(payload)
body = get_body(payload)
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)
def get_subject(payload: WildValue) -> str:
def get_topic(payload: WildValue) -> str:
project = payload["problem"]["app_name"].tame(check_string)
project += " / " + payload["problem"]["environment"].tame(check_string)
return ERRBIT_TOPIC_TEMPLATE.format(project_name=project)

View File

@ -139,7 +139,7 @@ def api_freshdesk_webhook(
) -> HttpResponse:
ticket = payload["freshdesk_webhook"]
subject = (
topic = (
f"#{ticket['ticket_id'].tame(check_string)}: {ticket['ticket_subject'].tame(check_string)}"
)
event_info = parse_freshdesk_event(ticket["triggered_event"].tame(check_string))
@ -154,5 +154,5 @@ def api_freshdesk_webhook(
# Not an event we know handle; do nothing.
return json_success(request)
check_send_webhook_message(request, user_profile, subject, content)
check_send_webhook_message(request, user_profile, topic, content)
return json_success(request)

View File

@ -28,7 +28,7 @@ def api_freshping_webhook(
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
body = get_body_for_http_request(payload)
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
check_state_name = payload["webhook_event_data"]["check_state_name"].tame(check_string)
if check_state_name not in CHECK_STATE_NAME_TO_EVENT_TYPE:
raise UnsupportedWebhookEventTypeError(check_state_name)
@ -36,22 +36,22 @@ def api_freshping_webhook(
check_send_webhook_message(
request,
user_profile,
subject,
topic,
body,
CHECK_STATE_NAME_TO_EVENT_TYPE[check_state_name],
)
return json_success(request)
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
webhook_event_data = payload["webhook_event_data"]
if webhook_event_data["application_name"].tame(check_string) == "Webhook test":
subject = FRESHPING_TOPIC_TEMPLATE_TEST
topic = FRESHPING_TOPIC_TEMPLATE_TEST
else:
subject = FRESHPING_TOPIC_TEMPLATE.format(
topic = FRESHPING_TOPIC_TEMPLATE.format(
check_name=webhook_event_data["check_name"].tame(check_string)
)
return subject
return topic
def get_body_for_http_request(payload: WildValue) -> str:

View File

@ -87,7 +87,7 @@ def api_freshstatus_webhook(
) -> HttpResponse:
try:
body = get_body_for_http_request(payload)
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
except ValidationError:
message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format(
bot_name=user_profile.full_name,
@ -98,7 +98,7 @@ def api_freshstatus_webhook(
raise JsonableError(_("Invalid payload"))
check_send_webhook_message(
request, user_profile, subject, body, payload["event_data"]["event_type"].tame(check_string)
request, user_profile, topic, body, payload["event_data"]["event_type"].tame(check_string)
)
return json_success(request)
@ -117,7 +117,7 @@ def get_services_content(services_data: List[Dict[str, str]]) -> str:
return services_content.rstrip()
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
event_data = payload["event_data"]
if (
event_data["event_type"].tame(check_string) == "INCIDENT_OPEN"

View File

@ -142,10 +142,10 @@ def api_gci_webhook(
event = get_event(payload)
if event is not None:
body = get_body_based_on_event(event)(payload)
subject = GCI_TOPIC_TEMPLATE.format(
topic = GCI_TOPIC_TEMPLATE.format(
student_name=payload["task_claimed_by"].tame(check_string),
)
check_send_webhook_message(request, user_profile, subject, body, event)
check_send_webhook_message(request, user_profile, topic, body, event)
return json_success(request)

View File

@ -683,7 +683,7 @@ def is_merge_queue_push_event(payload: WildValue) -> bool:
return payload["ref"].tame(check_string).startswith("refs/heads/gh-readonly-queue/")
def get_subject_based_on_type(payload: WildValue, event: str) -> str:
def get_topic_based_on_type(payload: WildValue, event: str) -> str:
if "pull_request" in event:
return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repository_name(payload),
@ -831,7 +831,7 @@ def api_github_webhook(
# for events that are valid but not yet handled by us.
# See IGNORED_EVENTS, for example.
return json_success(request)
subject = get_subject_based_on_type(payload, event)
topic = get_topic_based_on_type(payload, event)
body_function = EVENT_FUNCTION_MAPPER[event]
@ -842,7 +842,7 @@ def api_github_webhook(
)
body = body_function(helper)
check_send_webhook_message(request, user_profile, subject, body, event)
check_send_webhook_message(request, user_profile, topic, body, event)
return json_success(request)

View File

@ -436,7 +436,7 @@ def api_gitlab_webhook(
project_url = f"[{get_repo_name(payload)}]({get_project_homepage(payload)})"
body = f"[{project_url}] {body}"
topic = get_subject_based_on_event(event, payload, use_merge_request_title)
topic = get_topic_based_on_event(event, payload, use_merge_request_title)
check_send_webhook_message(request, user_profile, topic, body, event)
return json_success(request)
@ -445,9 +445,7 @@ def get_body_based_on_event(event: str) -> EventFunction:
return EVENT_FUNCTION_MAPPER[event]
def get_subject_based_on_event(
event: str, payload: WildValue, use_merge_request_title: bool
) -> str:
def get_topic_based_on_event(event: str, payload: WildValue, use_merge_request_title: bool) -> str:
if event == "Push Hook":
return f"{get_repo_name(payload)} / {get_branch_name(payload)}"
elif event == "Job Hook" or event == "Build Hook":

View File

@ -166,7 +166,7 @@ def get_issue_title(payload: WildValue) -> str:
return get_in(payload, ["issue", "fields", "summary"]).tame(check_string)
def get_issue_subject(payload: WildValue) -> str:
def get_issue_topic(payload: WildValue) -> str:
return f"{get_issue_id(payload)}: {get_issue_title(payload)}"
@ -370,10 +370,10 @@ def api_jira_webhook(
if content_func is None:
raise UnsupportedWebhookEventTypeError(event)
subject = get_issue_subject(payload)
topic = get_issue_topic(payload)
content: str = content_func(payload, user_profile)
check_send_webhook_message(
request, user_profile, subject, content, event, unquote_url_parameters=True
request, user_profile, topic, content, event, unquote_url_parameters=True
)
return json_success(request)

View File

@ -24,13 +24,13 @@ def api_json_webhook(
payload: Dict[str, Any] = REQ(argument_type="body"),
) -> HttpResponse:
body = get_body_for_http_request(payload)
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)
def get_subject_for_http_request(payload: Dict[str, Any]) -> str:
def get_topic_for_http_request(payload: Dict[str, Any]) -> str:
return "JSON"

View File

@ -61,15 +61,15 @@ def api_lidarr_webhook(
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
body = get_body_for_http_request(payload)
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
check_send_webhook_message(
request, user_profile, subject, body, payload["eventType"].tame(check_string)
request, user_profile, topic, body, payload["eventType"].tame(check_string)
)
return json_success(request)
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
if payload["eventType"].tame(check_string) == "Test":
topic = LIDARR_TOPIC_TEMPLATE_TEST
else:

View File

@ -115,14 +115,14 @@ def api_opbeat_webhook(
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
"""
This uses the subject name from opbeat to make the subject,
This uses the subject name from opbeat to make the topic,
and the summary from Opbeat as the message body, with
details about the object mentioned.
"""
message_subject = payload["title"].tame(check_string)
topic = payload["title"].tame(check_string)
message = format_object(payload, "base", "")
check_send_webhook_message(request, user_profile, message_subject, message)
check_send_webhook_message(request, user_profile, topic, message)
return json_success(request)

View File

@ -226,10 +226,10 @@ def send_formatted_pagerduty(
else:
template = INCIDENT_WITH_ASSIGNEE
subject = "Incident {incident_num_title}".format(**format_dict)
topic = "Incident {incident_num_title}".format(**format_dict)
body = template.format(**format_dict)
assert isinstance(format_dict["action"], str)
check_send_webhook_message(request, user_profile, subject, body, format_dict["action"])
check_send_webhook_message(request, user_profile, topic, body, format_dict["action"])
@webhook_view("PagerDuty", all_event_types=ALL_EVENT_TYPES)

View File

@ -48,16 +48,16 @@ def api_pingdom_webhook(
check_type = get_check_type(payload)
if check_type in SUPPORTED_CHECK_TYPES:
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
body = get_body_for_http_request(payload)
else:
raise UnsupportedWebhookEventTypeError(check_type)
check_send_webhook_message(request, user_profile, subject, body, check_type)
check_send_webhook_message(request, user_profile, topic, body, check_type)
return json_success(request)
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
return PINGDOM_TOPIC_TEMPLATE.format(name=payload["check_name"].tame(check_string))

View File

@ -46,10 +46,10 @@ def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> T
more_info = f" [(view)]({url})."
if event_type == "story_update":
subject = name
topic = name
content = description + more_info
elif event_type == "note_create":
subject = "Comment added"
topic = "Comment added"
content = description + more_info
elif event_type == "story_create":
issue_desc = get_text(["stories", "story", "description"])
@ -58,9 +58,9 @@ def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> T
estimate = get_text(["stories", "story", "estimate"])
if estimate != "":
estimate = f" worth {estimate} story points"
subject = name
topic = name
content = f"{description} ({issue_status} {issue_type}{estimate}):\n\n~~~ quote\n{issue_desc}\n~~~\n\n{more_info}"
return subject, content, f"{event_type}_v3"
return topic, content, f"{event_type}_v3"
UNSUPPORTED_EVENT_TYPES = [
@ -107,7 +107,7 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> T
changes = payload.get("changes", [])
content = ""
subject = f"#{story_id}: {story_name}"
topic = f"#{story_id}: {story_name}"
def extract_comment(change: Dict[str, Any]) -> Optional[str]:
if change.get("kind") == "comment":
@ -172,21 +172,21 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> T
else:
raise UnsupportedWebhookEventTypeError(event_type)
return subject, content, f"{event_type}_v5"
return topic, content, f"{event_type}_v5"
@webhook_view("Pivotal", all_event_types=ALL_EVENT_TYPES)
@has_request_variables
def api_pivotal_webhook(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
subject = content = None
topic = content = None
try:
subject, content, event_type = api_pivotal_webhook_v3(request, user_profile)
topic, content, event_type = api_pivotal_webhook_v3(request, user_profile)
except Exception:
# Attempt to parse v5 JSON payload
subject, content, event_type = api_pivotal_webhook_v5(request, user_profile)
topic, content, event_type = api_pivotal_webhook_v5(request, user_profile)
if not content:
raise JsonableError(_("Unable to handle Pivotal payload"))
check_send_webhook_message(request, user_profile, subject, content, event_type)
check_send_webhook_message(request, user_profile, topic, content, event_type)
return json_success(request)

View File

@ -52,15 +52,15 @@ def api_radarr_webhook(
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
body = get_body_for_http_request(payload)
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
check_send_webhook_message(
request, user_profile, subject, body, payload["eventType"].tame(check_string)
request, user_profile, topic, body, payload["eventType"].tame(check_string)
)
return json_success(request)
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
event_type = payload["eventType"].tame(check_string)
if event_type == "Test":
return RADARR_TOPIC_TEMPLATE_TEST

View File

@ -18,10 +18,10 @@ def api_rundeck_webhook(
user_profile: UserProfile,
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
subject = get_topic(payload)
topic = get_topic(payload)
body = get_body(payload)
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)

View File

@ -101,12 +101,12 @@ def api_semaphore_webhook(
content, project_name, branch_name, event = (
semaphore_classic(payload) if "event" in payload else semaphore_2(payload)
)
subject = (
topic = (
TOPIC_TEMPLATE.format(project=project_name, branch=branch_name)
if branch_name
else project_name
)
check_send_webhook_message(request, user_profile, subject, content, event)
check_send_webhook_message(request, user_profile, topic, content, event)
return json_success(request)

View File

@ -95,7 +95,7 @@ def convert_lines_to_traceback_string(lines: Optional[List[str]]) -> str:
def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
"""Handle either an exception type event or a message type event payload."""
subject = event["title"]
topic = event["title"]
platform_name = event["platform"]
syntax_highlight_as = syntax_highlight_as_map.get(platform_name, "")
if syntax_highlight_as == "": # nocoverage
@ -110,7 +110,7 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
if ["sample_event", "yes"] not in tags:
raise UnsupportedWebhookEventTypeError("Raven SDK")
context = {
"title": subject,
"title": topic,
"level": event["level"],
"web_link": event["web_url"],
"datetime": event["datetime"].split(".")[0].replace("T", " "),
@ -157,11 +157,11 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
)
body = EXCEPTION_EVENT_TEMPLATE_WITH_TRACEBACK.format(**context)
return (subject, body)
return (topic, body)
context.update(filename=filename) # nocoverage
body = EXCEPTION_EVENT_TEMPLATE.format(**context) # nocoverage
return (subject, body) # nocoverage
return (topic, body) # nocoverage
elif "logentry" in event:
# The event was triggered by a sentry.capture_message() call
@ -171,14 +171,14 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
else:
raise UnsupportedWebhookEventTypeError("unknown-event type")
return (subject, body)
return (topic, body)
def handle_issue_payload(
action: str, issue: Dict[str, Any], actor: Dict[str, Any]
) -> Tuple[str, str]:
"""Handle either an issue type event."""
subject = issue["title"]
topic = issue["title"]
datetime = issue["lastSeen"].split(".")[0].replace("T", " ")
if issue["assignedTo"]:
@ -191,7 +191,7 @@ def handle_issue_payload(
if action == "created":
context = {
"title": subject,
"title": topic,
"level": issue["level"],
"datetime": datetime,
"assignee": assignee,
@ -200,14 +200,14 @@ def handle_issue_payload(
elif action == "resolved":
context = {
"title": subject,
"title": topic,
"actor": actor["name"],
}
body = ISSUE_RESOLVED_MESSAGE_TEMPLATE.format(**context)
elif action == "assigned":
context = {
"title": subject,
"title": topic,
"assignee": assignee,
"actor": actor["name"],
}
@ -215,7 +215,7 @@ def handle_issue_payload(
elif action == "ignored":
context = {
"title": subject,
"title": topic,
"actor": actor["name"],
}
body = ISSUE_IGNORED_MESSAGE_TEMPLATE.format(**context)
@ -223,17 +223,17 @@ def handle_issue_payload(
else:
raise UnsupportedWebhookEventTypeError("unknown-issue-action type")
return (subject, body)
return (topic, body)
def handle_deprecated_payload(payload: Dict[str, Any]) -> Tuple[str, str]:
subject = "{}".format(payload.get("project_name"))
topic = "{}".format(payload.get("project_name"))
body = DEPRECATED_EXCEPTION_MESSAGE_TEMPLATE.format(
level=payload["level"].upper(),
url=payload.get("url"),
message=payload.get("message"),
)
return (subject, body)
return (topic, body)
def transform_webhook_payload(payload: Dict[str, Any]) -> Optional[Dict[str, Any]]:
@ -274,13 +274,13 @@ def api_sentry_webhook(
# We currently support two types of payloads: events and issues.
if data:
if "event" in data:
subject, body = handle_event_payload(data["event"])
topic, body = handle_event_payload(data["event"])
elif "issue" in data:
subject, body = handle_issue_payload(payload["action"], data["issue"], payload["actor"])
topic, body = handle_issue_payload(payload["action"], data["issue"], payload["actor"])
else:
raise UnsupportedWebhookEventTypeError(str(list(data.keys())))
else:
subject, body = handle_deprecated_payload(payload)
topic, body = handle_deprecated_payload(payload)
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)

View File

@ -28,13 +28,13 @@ def api_slack_webhook(
raise JsonableError(_("Error: channels_map_to_topics parameter other than 0 or 1"))
if channels_map_to_topics == VALID_OPTIONS["SHOULD_BE_MAPPED"]:
subject = f"channel: {channel_name}"
topic = f"channel: {channel_name}"
else:
stream = channel_name
subject = _("Message from Slack")
topic = _("Message from Slack")
content = ZULIP_MESSAGE_TEMPLATE.format(message_sender=user_name, text=text)
client = RequestNotes.get_notes(request).client
assert client is not None
check_send_stream_message(user_profile, client, stream, subject, content)
check_send_stream_message(user_profile, client, stream, topic, content)
return json_success(request)

View File

@ -46,15 +46,15 @@ def api_sonarr_webhook(
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
body = get_body_for_http_request(payload)
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
check_send_webhook_message(
request, user_profile, subject, body, payload["eventType"].tame(check_string)
request, user_profile, topic, body, payload["eventType"].tame(check_string)
)
return json_success(request)
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
event_type = payload["eventType"].tame(check_string)
if event_type != "Test" and event_type != "Health":
topic = SONARR_TOPIC_TEMPLATE.format(

View File

@ -25,7 +25,7 @@ def api_transifex_webhook(
translated: Optional[int] = REQ(json_validator=check_int, default=None),
reviewed: Optional[int] = REQ(json_validator=check_int, default=None),
) -> HttpResponse:
subject = f"{project} in {language}"
topic = f"{project} in {language}"
if translated:
event = "translated"
body = f"Resource {resource} fully translated."
@ -34,5 +34,5 @@ def api_transifex_webhook(
body = f"Resource {resource} fully reviewed."
else:
raise UnsupportedWebhookEventTypeError("Unknown Event Type")
check_send_webhook_message(request, user_profile, subject, body, event)
check_send_webhook_message(request, user_profile, topic, body, event)
return json_success(request)

View File

@ -24,17 +24,17 @@ def api_trello_webhook(
payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
action_type = payload["action"]["type"].tame(check_string)
message = get_subject_and_body(payload, action_type)
message = get_topic_and_body(payload, action_type)
if message is None:
return json_success(request)
else:
subject, body = message
topic, body = message
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)
def get_subject_and_body(payload: WildValue, action_type: str) -> Optional[Tuple[str, str]]:
def get_topic_and_body(payload: WildValue, action_type: str) -> Optional[Tuple[str, str]]:
if action_type in SUPPORTED_CARD_ACTIONS:
return process_card_action(payload, action_type)
if action_type in IGNORED_CARD_ACTIONS:

View File

@ -30,7 +30,7 @@ def process_board_action(
) -> Optional[Tuple[str, str]]:
action_type = get_proper_action(payload, action_type)
if action_type is not None:
return get_subject(payload), get_body(payload, action_type)
return get_topic(payload), get_body(payload, action_type)
return None
@ -47,7 +47,7 @@ def get_proper_action(payload: WildValue, action_type: Optional[str]) -> Optiona
return action_type
def get_subject(payload: WildValue) -> str:
def get_topic(payload: WildValue) -> str:
return get_action_data(payload)["board"]["name"].tame(check_string)

View File

@ -78,7 +78,7 @@ def prettify_date(date_string: str) -> str:
def process_card_action(payload: WildValue, action_type: str) -> Optional[Tuple[str, str]]:
proper_action = get_proper_action(payload, action_type)
if proper_action is not None:
return get_subject(payload), get_body(payload, proper_action)
return get_topic(payload), get_body(payload, proper_action)
return None
@ -131,7 +131,7 @@ def get_proper_action(payload: WildValue, action_type: str) -> Optional[str]:
return action_type
def get_subject(payload: WildValue) -> str:
def get_topic(payload: WildValue) -> str:
return get_action_data(payload)["board"]["name"].tame(check_string)

View File

@ -18,9 +18,9 @@ def send_message_for_event(
request: HttpRequest, user_profile: UserProfile, event: WildValue
) -> None:
event_type = get_event_type(event)
subject = TOPIC_TEMPLATE.format(service_url=event["check"]["url"].tame(check_string))
topic = TOPIC_TEMPLATE.format(service_url=event["check"]["url"].tame(check_string))
body = EVENT_TYPE_BODY_MAPPER[event_type](event)
check_send_webhook_message(request, user_profile, subject, body, event_type)
check_send_webhook_message(request, user_profile, topic, body, event_type)
def get_body_for_up_event(event: WildValue) -> str:

View File

@ -46,7 +46,7 @@ def api_uptimerobot_webhook(
try:
body = get_body_for_http_request(payload, event_type)
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
except ValidationError:
message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format(
bot_name=user_profile.full_name,
@ -56,11 +56,11 @@ def api_uptimerobot_webhook(
raise JsonableError(_("Invalid payload"))
check_send_webhook_message(request, user_profile, subject, body, event)
check_send_webhook_message(request, user_profile, topic, body, event)
return json_success(request)
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
return UPTIMEROBOT_TOPIC_TEMPLATE.format(
monitor_friendly_name=payload["monitor_friendly_name"].tame(check_string)
)

View File

@ -38,7 +38,7 @@ def api_zabbix_webhook(
) -> HttpResponse:
try:
body = get_body_for_http_request(payload)
subject = get_subject_for_http_request(payload)
topic = get_topic_for_http_request(payload)
except ValidationError:
message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format(
bot_name=user_profile.full_name,
@ -48,11 +48,11 @@ def api_zabbix_webhook(
raise JsonableError(_("Invalid payload"))
check_send_webhook_message(request, user_profile, subject, body)
check_send_webhook_message(request, user_profile, topic, body)
return json_success(request)
def get_subject_for_http_request(payload: WildValue) -> str:
def get_topic_for_http_request(payload: WildValue) -> str:
return ZABBIX_TOPIC_TEMPLATE.format(hostname=payload["hostname"].tame(check_string))

View File

@ -25,9 +25,9 @@ def api_zendesk_webhook(
) -> HttpResponse:
"""
Zendesk uses triggers with message templates. This webhook uses the
ticket_id and ticket_title to create a subject. And passes with zendesk
ticket_id and ticket_title to create a topic. And passes with zendesk
user's configured message to zulip.
"""
subject = truncate(f"#{ticket_id}: {ticket_title}", 60)
check_send_webhook_message(request, user_profile, subject, message)
topic = truncate(f"#{ticket_id}: {ticket_title}", 60)
check_send_webhook_message(request, user_profile, topic, message)
return json_success(request)