mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	@@ -19,13 +19,13 @@ def api_airbrake_webhook(
 | 
				
			|||||||
    user_profile: UserProfile,
 | 
					    user_profile: UserProfile,
 | 
				
			||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    subject = get_subject(payload)
 | 
					    topic = get_topic(payload)
 | 
				
			||||||
    body = get_body(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)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_subject(payload: WildValue) -> str:
 | 
					def get_topic(payload: WildValue) -> str:
 | 
				
			||||||
    return AIRBRAKE_TOPIC_TEMPLATE.format(
 | 
					    return AIRBRAKE_TOPIC_TEMPLATE.format(
 | 
				
			||||||
        project_name=payload["error"]["project"]["name"].tame(check_string)
 | 
					        project_name=payload["error"]["project"]["name"].tame(check_string)
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,9 +29,9 @@ def api_ansibletower_webhook(
 | 
				
			|||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    body = get_body(payload)
 | 
					    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)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,13 +24,13 @@ def api_appveyor_webhook(
 | 
				
			|||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    body = get_body_for_http_request(payload)
 | 
					    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)
 | 
					    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"]
 | 
					    event_data = payload["eventData"]
 | 
				
			||||||
    return APPVEYOR_TOPIC_TEMPLATE.format(project_name=event_data["projectName"].tame(check_string))
 | 
					    return APPVEYOR_TOPIC_TEMPLATE.format(project_name=event_data["projectName"].tame(check_string))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,7 +49,7 @@ def api_basecamp_webhook(
 | 
				
			|||||||
    if event not in SUPPORT_EVENTS:
 | 
					    if event not in SUPPORT_EVENTS:
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError(event)
 | 
					        raise UnsupportedWebhookEventTypeError(event)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    subject = get_project_name(payload)
 | 
					    topic = get_project_name(payload)
 | 
				
			||||||
    if event.startswith("document_"):
 | 
					    if event.startswith("document_"):
 | 
				
			||||||
        body = get_document_body(event, payload)
 | 
					        body = get_document_body(event, payload)
 | 
				
			||||||
        event = "document"
 | 
					        event = "document"
 | 
				
			||||||
@@ -74,7 +74,7 @@ def api_basecamp_webhook(
 | 
				
			|||||||
    else:
 | 
					    else:
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError(event)
 | 
					        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)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -90,11 +90,11 @@ def get_event_creator(payload: WildValue) -> str:
 | 
				
			|||||||
    return payload["creator"]["name"].tame(check_string)
 | 
					    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)
 | 
					    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)
 | 
					    return payload["recording"]["title"].tame(check_string)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -128,7 +128,7 @@ def get_questions_answer_body(event: str, payload: WildValue) -> str:
 | 
				
			|||||||
    return template.format(
 | 
					    return template.format(
 | 
				
			||||||
        user_name=get_event_creator(payload),
 | 
					        user_name=get_event_creator(payload),
 | 
				
			||||||
        verb=verb,
 | 
					        verb=verb,
 | 
				
			||||||
        answer_url=get_subject_url(payload),
 | 
					        answer_url=get_topic_url(payload),
 | 
				
			||||||
        question_title=title,
 | 
					        question_title=title,
 | 
				
			||||||
        question_url=question["app_url"].tame(check_string),
 | 
					        question_url=question["app_url"].tame(check_string),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
@@ -142,7 +142,7 @@ def get_comment_body(event: str, payload: WildValue) -> str:
 | 
				
			|||||||
    return template.format(
 | 
					    return template.format(
 | 
				
			||||||
        user_name=get_event_creator(payload),
 | 
					        user_name=get_event_creator(payload),
 | 
				
			||||||
        verb=verb,
 | 
					        verb=verb,
 | 
				
			||||||
        answer_url=get_subject_url(payload),
 | 
					        answer_url=get_topic_url(payload),
 | 
				
			||||||
        task_title=task["title"].tame(check_string),
 | 
					        task_title=task["title"].tame(check_string),
 | 
				
			||||||
        task_url=task["app_url"].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:
 | 
					def get_generic_body(event: str, payload: WildValue, prefix: str, template: str) -> str:
 | 
				
			||||||
    verb = get_verb(event, prefix)
 | 
					    verb = get_verb(event, prefix)
 | 
				
			||||||
    title = get_subject_title(payload)
 | 
					    title = get_topic_title(payload)
 | 
				
			||||||
    template = add_punctuation_if_necessary(template, title)
 | 
					    template = add_punctuation_if_necessary(template, title)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return template.format(
 | 
					    return template.format(
 | 
				
			||||||
        user_name=get_event_creator(payload),
 | 
					        user_name=get_event_creator(payload),
 | 
				
			||||||
        verb=verb,
 | 
					        verb=verb,
 | 
				
			||||||
        title=get_subject_title(payload),
 | 
					        title=get_topic_title(payload),
 | 
				
			||||||
        url=get_subject_url(payload),
 | 
					        url=get_topic_url(payload),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,12 +27,12 @@ def build_message_from_gitlog(
 | 
				
			|||||||
    deleted: bool = False,
 | 
					    deleted: bool = False,
 | 
				
			||||||
) -> Tuple[str, str]:
 | 
					) -> Tuple[str, str]:
 | 
				
			||||||
    short_ref = re.sub(r"^refs/heads/", "", ref)
 | 
					    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)
 | 
					    commits_data = _transform_commits_list_to_common_format(commits)
 | 
				
			||||||
    content = get_push_commits_event_message(pusher, url, short_ref, commits_data, deleted=deleted)
 | 
					    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]]:
 | 
					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:
 | 
					        if branches is not None and branches.find(payload["branch"].tame(check_string)) == -1:
 | 
				
			||||||
            return json_success(request)
 | 
					            return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        subject, content = build_message_from_gitlog(
 | 
					        topic, content = build_message_from_gitlog(
 | 
				
			||||||
            user_profile,
 | 
					            user_profile,
 | 
				
			||||||
            payload["repository"]["name"].tame(check_string),
 | 
					            payload["repository"]["name"].tame(check_string),
 | 
				
			||||||
            payload["ref"].tame(check_string),
 | 
					            payload["ref"].tame(check_string),
 | 
				
			||||||
@@ -86,8 +86,8 @@ def api_beanstalk_webhook(
 | 
				
			|||||||
        revision = payload["revision"].tame(check_int)
 | 
					        revision = payload["revision"].tame(check_int)
 | 
				
			||||||
        (short_commit_msg, _, _) = payload["message"].tame(check_string).partition("\n")
 | 
					        (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}"
 | 
					        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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@ def api_bitbucket_webhook(
 | 
				
			|||||||
    if len(commits) == 0:
 | 
					    if len(commits) == 0:
 | 
				
			||||||
        # Bitbucket doesn't give us enough information to really give
 | 
					        # Bitbucket doesn't give us enough information to really give
 | 
				
			||||||
        # a useful message :/
 | 
					        # a useful message :/
 | 
				
			||||||
        subject = repository["name"].tame(check_string)
 | 
					        topic = repository["name"].tame(check_string)
 | 
				
			||||||
        content = "{} [force pushed]({}).".format(
 | 
					        content = "{} [force pushed]({}).".format(
 | 
				
			||||||
            payload.get("user", "Someone").tame(check_string),
 | 
					            payload.get("user", "Someone").tame(check_string),
 | 
				
			||||||
            payload["canon_url"].tame(check_string) + repository["absolute_url"].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)
 | 
					        committer = payload.get("user", "Someone").tame(check_string)
 | 
				
			||||||
        content = get_push_commits_event_message(committer, None, branch, commits)
 | 
					        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
 | 
					            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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -93,15 +93,15 @@ def api_bitbucket2_webhook(
 | 
				
			|||||||
        if branch and branches and branches.find(branch) == -1:
 | 
					        if branch and branches and branches.find(branch) == -1:
 | 
				
			||||||
            return json_success(request)
 | 
					            return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        subjects = get_push_subjects(payload)
 | 
					        topics = get_push_topics(payload)
 | 
				
			||||||
        bodies = get_push_bodies(request, 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(
 | 
					            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:
 | 
					    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_function = get_body_based_on_type(type)
 | 
				
			||||||
        body = body_function(
 | 
					        body = body_function(
 | 
				
			||||||
            request,
 | 
					            request,
 | 
				
			||||||
@@ -110,13 +110,13 @@ def api_bitbucket2_webhook(
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        check_send_webhook_message(
 | 
					        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)
 | 
					    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
 | 
					    payload: WildValue, branch_name: Optional[str] = None
 | 
				
			||||||
) -> str:
 | 
					) -> str:
 | 
				
			||||||
    return TOPIC_WITH_BRANCH_TEMPLATE.format(
 | 
					    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]:
 | 
					def get_push_topics(payload: WildValue) -> List[str]:
 | 
				
			||||||
    subjects_list = []
 | 
					    topics_list = []
 | 
				
			||||||
    for change in payload["push"]["changes"]:
 | 
					    for change in payload["push"]["changes"]:
 | 
				
			||||||
        potential_tag = (change["new"] or change["old"])["type"].tame(check_string)
 | 
					        potential_tag = (change["new"] or change["old"])["type"].tame(check_string)
 | 
				
			||||||
        if potential_tag == "tag":
 | 
					        if potential_tag == "tag":
 | 
				
			||||||
            subjects_list.append(get_subject(payload))
 | 
					            topics_list.append(get_topic(payload))
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            if change.get("new"):
 | 
					            if change.get("new"):
 | 
				
			||||||
                branch_name = change["new"]["name"].tame(check_string)
 | 
					                branch_name = change["new"]["name"].tame(check_string)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                branch_name = change["old"]["name"].tame(check_string)
 | 
					                branch_name = change["old"]["name"].tame(check_string)
 | 
				
			||||||
            subjects_list.append(get_subject_for_branch_specified_events(payload, branch_name))
 | 
					            topics_list.append(get_topic_for_branch_specified_events(payload, branch_name))
 | 
				
			||||||
    return subjects_list
 | 
					    return topics_list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_subject(payload: WildValue) -> str:
 | 
					def get_topic(payload: WildValue) -> str:
 | 
				
			||||||
    return BITBUCKET_TOPIC_TEMPLATE.format(
 | 
					    return BITBUCKET_TOPIC_TEMPLATE.format(
 | 
				
			||||||
        repository_name=get_repository_name(payload["repository"])
 | 
					        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"):
 | 
					    if type.startswith("pull_request"):
 | 
				
			||||||
        return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
 | 
					        return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
 | 
				
			||||||
            repo=get_repository_name(payload["repository"]),
 | 
					            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),
 | 
					            title=payload["issue"]["title"].tame(check_string),
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    assert type != "push"
 | 
					    assert type != "push"
 | 
				
			||||||
    return get_subject(payload)
 | 
					    return get_topic(payload)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_type(request: HttpRequest, payload: WildValue) -> str:
 | 
					def get_type(request: HttpRequest, payload: WildValue) -> str:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,11 +75,11 @@ def ping_handler(
 | 
				
			|||||||
    include_title: Optional[str],
 | 
					    include_title: Optional[str],
 | 
				
			||||||
) -> List[Dict[str, str]]:
 | 
					) -> List[Dict[str, str]]:
 | 
				
			||||||
    if include_title:
 | 
					    if include_title:
 | 
				
			||||||
        subject = include_title
 | 
					        topic = include_title
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        subject = "Bitbucket Server Ping"
 | 
					        topic = "Bitbucket Server Ping"
 | 
				
			||||||
    body = "Congratulations! The Bitbucket Server webhook was configured successfully!"
 | 
					    body = "Congratulations! The Bitbucket Server webhook was configured successfully!"
 | 
				
			||||||
    return [{"subject": subject, "body": body}]
 | 
					    return [{"topic": topic, "body": body}]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def repo_comment_handler(
 | 
					def repo_comment_handler(
 | 
				
			||||||
@@ -89,7 +89,7 @@ def repo_comment_handler(
 | 
				
			|||||||
    include_title: Optional[str],
 | 
					    include_title: Optional[str],
 | 
				
			||||||
) -> List[Dict[str, str]]:
 | 
					) -> List[Dict[str, str]]:
 | 
				
			||||||
    repo_name = payload["repository"]["name"].tame(check_string)
 | 
					    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)
 | 
					    sha = payload["commit"].tame(check_string)
 | 
				
			||||||
    commit_url = payload["repository"]["links"]["self"][0]["href"].tame(check_string)[
 | 
					    commit_url = payload["repository"]["links"]["self"][0]["href"].tame(check_string)[
 | 
				
			||||||
        : -len("browse")
 | 
					        : -len("browse")
 | 
				
			||||||
@@ -105,7 +105,7 @@ def repo_comment_handler(
 | 
				
			|||||||
        sha=sha,
 | 
					        sha=sha,
 | 
				
			||||||
        message=message,
 | 
					        message=message,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    return [{"subject": subject, "body": body}]
 | 
					    return [{"topic": topic, "body": body}]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def repo_forked_handler(
 | 
					def repo_forked_handler(
 | 
				
			||||||
@@ -114,14 +114,14 @@ def repo_forked_handler(
 | 
				
			|||||||
    include_title: Optional[str],
 | 
					    include_title: Optional[str],
 | 
				
			||||||
) -> List[Dict[str, str]]:
 | 
					) -> List[Dict[str, str]]:
 | 
				
			||||||
    repo_name = payload["repository"]["origin"]["name"].tame(check_string)
 | 
					    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(
 | 
					    body = BITBUCKET_FORK_BODY.format(
 | 
				
			||||||
        display_name=payload["actor"]["displayName"].tame(check_string),
 | 
					        display_name=payload["actor"]["displayName"].tame(check_string),
 | 
				
			||||||
        username=get_user_name(payload),
 | 
					        username=get_user_name(payload),
 | 
				
			||||||
        fork_name=payload["repository"]["name"].tame(check_string),
 | 
					        fork_name=payload["repository"]["name"].tame(check_string),
 | 
				
			||||||
        fork_url=payload["repository"]["links"]["self"][0]["href"].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(
 | 
					def repo_modified_handler(
 | 
				
			||||||
@@ -129,7 +129,7 @@ def repo_modified_handler(
 | 
				
			|||||||
    branches: Optional[str],
 | 
					    branches: Optional[str],
 | 
				
			||||||
    include_title: Optional[str],
 | 
					    include_title: Optional[str],
 | 
				
			||||||
) -> List[Dict[str, 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)
 | 
					        repository_name=payload["new"]["name"].tame(check_string)
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    new_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.
 | 
					    )  # 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 ""
 | 
					    punctuation = "." if new_name[-1] not in string.punctuation else ""
 | 
				
			||||||
    body = f"{body}{punctuation}"
 | 
					    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]:
 | 
					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
 | 
					        message = "{}.{}".format(payload["eventKey"].tame(check_string), event_type)  # nocoverage
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError(message)
 | 
					        raise UnsupportedWebhookEventTypeError(message)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repo_name, branch=branch_name)
 | 
					    topic = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repo_name, branch=branch_name)
 | 
				
			||||||
    return {"subject": subject, "body": body}
 | 
					    return {"topic": topic, "body": body}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def repo_push_tag_data(payload: WildValue, change: WildValue) -> Dict[str, str]:
 | 
					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
 | 
					        message = "{}.{}".format(payload["eventKey"].tame(check_string), event_type)  # nocoverage
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError(message)
 | 
					        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)
 | 
					    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(
 | 
					def repo_push_handler(
 | 
				
			||||||
@@ -230,7 +230,7 @@ def get_assignees_string(pr: WildValue) -> Optional[str]:
 | 
				
			|||||||
    return assignees
 | 
					    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)
 | 
					    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],
 | 
					    include_title: Optional[str],
 | 
				
			||||||
) -> List[Dict[str, str]]:
 | 
					) -> List[Dict[str, str]]:
 | 
				
			||||||
    pr = payload["pullRequest"]
 | 
					    pr = payload["pullRequest"]
 | 
				
			||||||
    subject = get_pr_subject(
 | 
					    topic = get_pr_topic(
 | 
				
			||||||
        pr["toRef"]["repository"]["name"].tame(check_string),
 | 
					        pr["toRef"]["repository"]["name"].tame(check_string),
 | 
				
			||||||
        type="PR",
 | 
					        type="PR",
 | 
				
			||||||
        id=pr["id"].tame(check_int),
 | 
					        id=pr["id"].tame(check_int),
 | 
				
			||||||
@@ -358,7 +358,7 @@ def pr_handler(
 | 
				
			|||||||
    else:
 | 
					    else:
 | 
				
			||||||
        body = get_simple_pr_body(payload, action, include_title)
 | 
					        body = get_simple_pr_body(payload, action, include_title)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return [{"subject": subject, "body": body}]
 | 
					    return [{"topic": topic, "body": body}]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def pr_comment_handler(
 | 
					def pr_comment_handler(
 | 
				
			||||||
@@ -368,7 +368,7 @@ def pr_comment_handler(
 | 
				
			|||||||
    include_title: Optional[str],
 | 
					    include_title: Optional[str],
 | 
				
			||||||
) -> List[Dict[str, str]]:
 | 
					) -> List[Dict[str, str]]:
 | 
				
			||||||
    pr = payload["pullRequest"]
 | 
					    pr = payload["pullRequest"]
 | 
				
			||||||
    subject = get_pr_subject(
 | 
					    topic = get_pr_topic(
 | 
				
			||||||
        pr["toRef"]["repository"]["name"].tame(check_string),
 | 
					        pr["toRef"]["repository"]["name"].tame(check_string),
 | 
				
			||||||
        type="PR",
 | 
					        type="PR",
 | 
				
			||||||
        id=pr["id"].tame(check_int),
 | 
					        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,
 | 
					        title=pr["title"].tame(check_string) if include_title else None,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return [{"subject": subject, "body": body}]
 | 
					    return [{"topic": topic, "body": body}]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class EventHandler(Protocol):
 | 
					class EventHandler(Protocol):
 | 
				
			||||||
@@ -447,7 +447,7 @@ def api_bitbucket3_webhook(
 | 
				
			|||||||
        check_send_webhook_message(
 | 
					        check_send_webhook_message(
 | 
				
			||||||
            request,
 | 
					            request,
 | 
				
			||||||
            user_profile,
 | 
					            user_profile,
 | 
				
			||||||
            element["subject"],
 | 
					            element["topic"],
 | 
				
			||||||
            element["body"],
 | 
					            element["body"],
 | 
				
			||||||
            eventkey,
 | 
					            eventkey,
 | 
				
			||||||
            unquote_url_parameters=True,
 | 
					            unquote_url_parameters=True,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -67,12 +67,12 @@ def api_circleci_webhook(
 | 
				
			|||||||
    type = payload["type"].tame(check_string)
 | 
					    type = payload["type"].tame(check_string)
 | 
				
			||||||
    if type == "ping":
 | 
					    if type == "ping":
 | 
				
			||||||
        # Ping events don't have full payloads, so our normal codepath won't work
 | 
					        # 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(
 | 
					        body = "Webhook '{name}' test event successful.".format(
 | 
				
			||||||
            name=payload["webhook"]["name"].tame(check_string)
 | 
					            name=payload["webhook"]["name"].tame(check_string)
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        subject = get_subject(payload)
 | 
					        topic = get_topic(payload)
 | 
				
			||||||
        body = get_body(payload)
 | 
					        body = get_body(payload)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # We currently don't support projects using VCS providers other than GitHub,
 | 
					        # We currently don't support projects using VCS providers other than GitHub,
 | 
				
			||||||
@@ -86,14 +86,14 @@ def api_circleci_webhook(
 | 
				
			|||||||
    check_send_webhook_message(
 | 
					    check_send_webhook_message(
 | 
				
			||||||
        request,
 | 
					        request,
 | 
				
			||||||
        user_profile,
 | 
					        user_profile,
 | 
				
			||||||
        subject,
 | 
					        topic,
 | 
				
			||||||
        body,
 | 
					        body,
 | 
				
			||||||
        payload["type"].tame(check_string),
 | 
					        payload["type"].tame(check_string),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    return json_success(request)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_subject(payload: WildValue) -> str:
 | 
					def get_topic(payload: WildValue) -> str:
 | 
				
			||||||
    return payload["project"]["name"].tame(check_string)
 | 
					    return payload["project"]["name"].tame(check_string)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,14 +29,14 @@ def api_codeship_webhook(
 | 
				
			|||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    payload = payload["build"]
 | 
					    payload = payload["build"]
 | 
				
			||||||
    subject = get_subject_for_http_request(payload)
 | 
					    topic = get_topic_for_http_request(payload)
 | 
				
			||||||
    body = get_body_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)
 | 
					    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(
 | 
					    return CODESHIP_TOPIC_TEMPLATE.format(
 | 
				
			||||||
        project_name=payload["project_name"].tame(check_string),
 | 
					        project_name=payload["project_name"].tame(check_string),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,11 +26,11 @@ def api_crashlytics_webhook(
 | 
				
			|||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    event = payload["event"]
 | 
					    event = payload["event"]
 | 
				
			||||||
    if event == VERIFICATION_EVENT:
 | 
					    if event == VERIFICATION_EVENT:
 | 
				
			||||||
        subject = CRASHLYTICS_SETUP_TOPIC_TEMPLATE
 | 
					        topic = CRASHLYTICS_SETUP_TOPIC_TEMPLATE
 | 
				
			||||||
        body = CRASHLYTICS_SETUP_MESSAGE_TEMPLATE
 | 
					        body = CRASHLYTICS_SETUP_MESSAGE_TEMPLATE
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        issue_body = payload["payload"]
 | 
					        issue_body = payload["payload"]
 | 
				
			||||||
        subject = CRASHLYTICS_TOPIC_TEMPLATE.format(
 | 
					        topic = CRASHLYTICS_TOPIC_TEMPLATE.format(
 | 
				
			||||||
            display_id=issue_body["display_id"].tame(check_int),
 | 
					            display_id=issue_body["display_id"].tame(check_int),
 | 
				
			||||||
            title=issue_body["title"].tame(check_string),
 | 
					            title=issue_body["title"].tame(check_string),
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
@@ -39,5 +39,5 @@ def api_crashlytics_webhook(
 | 
				
			|||||||
            url=issue_body["url"].tame(check_string),
 | 
					            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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,13 +18,13 @@ def api_errbit_webhook(
 | 
				
			|||||||
    user_profile: UserProfile,
 | 
					    user_profile: UserProfile,
 | 
				
			||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    subject = get_subject(payload)
 | 
					    topic = get_topic(payload)
 | 
				
			||||||
    body = get_body(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)
 | 
					    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"]["app_name"].tame(check_string)
 | 
				
			||||||
    project += " / " + payload["problem"]["environment"].tame(check_string)
 | 
					    project += " / " + payload["problem"]["environment"].tame(check_string)
 | 
				
			||||||
    return ERRBIT_TOPIC_TEMPLATE.format(project_name=project)
 | 
					    return ERRBIT_TOPIC_TEMPLATE.format(project_name=project)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -139,7 +139,7 @@ def api_freshdesk_webhook(
 | 
				
			|||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    ticket = payload["freshdesk_webhook"]
 | 
					    ticket = payload["freshdesk_webhook"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    subject = (
 | 
					    topic = (
 | 
				
			||||||
        f"#{ticket['ticket_id'].tame(check_string)}: {ticket['ticket_subject'].tame(check_string)}"
 | 
					        f"#{ticket['ticket_id'].tame(check_string)}: {ticket['ticket_subject'].tame(check_string)}"
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    event_info = parse_freshdesk_event(ticket["triggered_event"].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.
 | 
					        # Not an event we know handle; do nothing.
 | 
				
			||||||
        return json_success(request)
 | 
					        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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,7 +28,7 @@ def api_freshping_webhook(
 | 
				
			|||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    body = get_body_for_http_request(payload)
 | 
					    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)
 | 
					    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:
 | 
					    if check_state_name not in CHECK_STATE_NAME_TO_EVENT_TYPE:
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError(check_state_name)
 | 
					        raise UnsupportedWebhookEventTypeError(check_state_name)
 | 
				
			||||||
@@ -36,22 +36,22 @@ def api_freshping_webhook(
 | 
				
			|||||||
    check_send_webhook_message(
 | 
					    check_send_webhook_message(
 | 
				
			||||||
        request,
 | 
					        request,
 | 
				
			||||||
        user_profile,
 | 
					        user_profile,
 | 
				
			||||||
        subject,
 | 
					        topic,
 | 
				
			||||||
        body,
 | 
					        body,
 | 
				
			||||||
        CHECK_STATE_NAME_TO_EVENT_TYPE[check_state_name],
 | 
					        CHECK_STATE_NAME_TO_EVENT_TYPE[check_state_name],
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    return json_success(request)
 | 
					    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"]
 | 
					    webhook_event_data = payload["webhook_event_data"]
 | 
				
			||||||
    if webhook_event_data["application_name"].tame(check_string) == "Webhook test":
 | 
					    if webhook_event_data["application_name"].tame(check_string) == "Webhook test":
 | 
				
			||||||
        subject = FRESHPING_TOPIC_TEMPLATE_TEST
 | 
					        topic = FRESHPING_TOPIC_TEMPLATE_TEST
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        subject = FRESHPING_TOPIC_TEMPLATE.format(
 | 
					        topic = FRESHPING_TOPIC_TEMPLATE.format(
 | 
				
			||||||
            check_name=webhook_event_data["check_name"].tame(check_string)
 | 
					            check_name=webhook_event_data["check_name"].tame(check_string)
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    return subject
 | 
					    return topic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_body_for_http_request(payload: WildValue) -> str:
 | 
					def get_body_for_http_request(payload: WildValue) -> str:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -87,7 +87,7 @@ def api_freshstatus_webhook(
 | 
				
			|||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        body = get_body_for_http_request(payload)
 | 
					        body = get_body_for_http_request(payload)
 | 
				
			||||||
        subject = get_subject_for_http_request(payload)
 | 
					        topic = get_topic_for_http_request(payload)
 | 
				
			||||||
    except ValidationError:
 | 
					    except ValidationError:
 | 
				
			||||||
        message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format(
 | 
					        message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format(
 | 
				
			||||||
            bot_name=user_profile.full_name,
 | 
					            bot_name=user_profile.full_name,
 | 
				
			||||||
@@ -98,7 +98,7 @@ def api_freshstatus_webhook(
 | 
				
			|||||||
        raise JsonableError(_("Invalid payload"))
 | 
					        raise JsonableError(_("Invalid payload"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    check_send_webhook_message(
 | 
					    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)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -117,7 +117,7 @@ def get_services_content(services_data: List[Dict[str, str]]) -> str:
 | 
				
			|||||||
    return services_content.rstrip()
 | 
					    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"]
 | 
					    event_data = payload["event_data"]
 | 
				
			||||||
    if (
 | 
					    if (
 | 
				
			||||||
        event_data["event_type"].tame(check_string) == "INCIDENT_OPEN"
 | 
					        event_data["event_type"].tame(check_string) == "INCIDENT_OPEN"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -142,10 +142,10 @@ def api_gci_webhook(
 | 
				
			|||||||
    event = get_event(payload)
 | 
					    event = get_event(payload)
 | 
				
			||||||
    if event is not None:
 | 
					    if event is not None:
 | 
				
			||||||
        body = get_body_based_on_event(event)(payload)
 | 
					        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),
 | 
					            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)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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/")
 | 
					    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:
 | 
					    if "pull_request" in event:
 | 
				
			||||||
        return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
 | 
					        return TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
 | 
				
			||||||
            repo=get_repository_name(payload),
 | 
					            repo=get_repository_name(payload),
 | 
				
			||||||
@@ -831,7 +831,7 @@ def api_github_webhook(
 | 
				
			|||||||
        # for events that are valid but not yet handled by us.
 | 
					        # for events that are valid but not yet handled by us.
 | 
				
			||||||
        # See IGNORED_EVENTS, for example.
 | 
					        # See IGNORED_EVENTS, for example.
 | 
				
			||||||
        return json_success(request)
 | 
					        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]
 | 
					    body_function = EVENT_FUNCTION_MAPPER[event]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -842,7 +842,7 @@ def api_github_webhook(
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
    body = body_function(helper)
 | 
					    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)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -436,7 +436,7 @@ def api_gitlab_webhook(
 | 
				
			|||||||
            project_url = f"[{get_repo_name(payload)}]({get_project_homepage(payload)})"
 | 
					            project_url = f"[{get_repo_name(payload)}]({get_project_homepage(payload)})"
 | 
				
			||||||
            body = f"[{project_url}] {body}"
 | 
					            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)
 | 
					        check_send_webhook_message(request, user_profile, topic, body, event)
 | 
				
			||||||
    return json_success(request)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -445,9 +445,7 @@ def get_body_based_on_event(event: str) -> EventFunction:
 | 
				
			|||||||
    return EVENT_FUNCTION_MAPPER[event]
 | 
					    return EVENT_FUNCTION_MAPPER[event]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_subject_based_on_event(
 | 
					def get_topic_based_on_event(event: str, payload: WildValue, use_merge_request_title: bool) -> str:
 | 
				
			||||||
    event: str, payload: WildValue, use_merge_request_title: bool
 | 
					 | 
				
			||||||
) -> str:
 | 
					 | 
				
			||||||
    if event == "Push Hook":
 | 
					    if event == "Push Hook":
 | 
				
			||||||
        return f"{get_repo_name(payload)} / {get_branch_name(payload)}"
 | 
					        return f"{get_repo_name(payload)} / {get_branch_name(payload)}"
 | 
				
			||||||
    elif event == "Job Hook" or event == "Build Hook":
 | 
					    elif event == "Job Hook" or event == "Build Hook":
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -166,7 +166,7 @@ def get_issue_title(payload: WildValue) -> str:
 | 
				
			|||||||
    return get_in(payload, ["issue", "fields", "summary"]).tame(check_string)
 | 
					    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)}"
 | 
					    return f"{get_issue_id(payload)}: {get_issue_title(payload)}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -370,10 +370,10 @@ def api_jira_webhook(
 | 
				
			|||||||
    if content_func is None:
 | 
					    if content_func is None:
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError(event)
 | 
					        raise UnsupportedWebhookEventTypeError(event)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    subject = get_issue_subject(payload)
 | 
					    topic = get_issue_topic(payload)
 | 
				
			||||||
    content: str = content_func(payload, user_profile)
 | 
					    content: str = content_func(payload, user_profile)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    check_send_webhook_message(
 | 
					    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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,13 +24,13 @@ def api_json_webhook(
 | 
				
			|||||||
    payload: Dict[str, Any] = REQ(argument_type="body"),
 | 
					    payload: Dict[str, Any] = REQ(argument_type="body"),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    body = get_body_for_http_request(payload)
 | 
					    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)
 | 
					    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"
 | 
					    return "JSON"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,15 +61,15 @@ def api_lidarr_webhook(
 | 
				
			|||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    body = get_body_for_http_request(payload)
 | 
					    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(
 | 
					    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)
 | 
					    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":
 | 
					    if payload["eventType"].tame(check_string) == "Test":
 | 
				
			||||||
        topic = LIDARR_TOPIC_TEMPLATE_TEST
 | 
					        topic = LIDARR_TOPIC_TEMPLATE_TEST
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -115,14 +115,14 @@ def api_opbeat_webhook(
 | 
				
			|||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> 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
 | 
					    and the summary from Opbeat as the message body, with
 | 
				
			||||||
    details about the object mentioned.
 | 
					    details about the object mentioned.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    message_subject = payload["title"].tame(check_string)
 | 
					    topic = payload["title"].tame(check_string)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    message = format_object(payload, "base", "")
 | 
					    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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -226,10 +226,10 @@ def send_formatted_pagerduty(
 | 
				
			|||||||
    else:
 | 
					    else:
 | 
				
			||||||
        template = INCIDENT_WITH_ASSIGNEE
 | 
					        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)
 | 
					    body = template.format(**format_dict)
 | 
				
			||||||
    assert isinstance(format_dict["action"], str)
 | 
					    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)
 | 
					@webhook_view("PagerDuty", all_event_types=ALL_EVENT_TYPES)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,16 +48,16 @@ def api_pingdom_webhook(
 | 
				
			|||||||
    check_type = get_check_type(payload)
 | 
					    check_type = get_check_type(payload)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if check_type in SUPPORTED_CHECK_TYPES:
 | 
					    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)
 | 
					        body = get_body_for_http_request(payload)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError(check_type)
 | 
					        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)
 | 
					    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))
 | 
					    return PINGDOM_TOPIC_TEMPLATE.format(name=payload["check_name"].tame(check_string))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,10 +46,10 @@ def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> T
 | 
				
			|||||||
    more_info = f" [(view)]({url})."
 | 
					    more_info = f" [(view)]({url})."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if event_type == "story_update":
 | 
					    if event_type == "story_update":
 | 
				
			||||||
        subject = name
 | 
					        topic = name
 | 
				
			||||||
        content = description + more_info
 | 
					        content = description + more_info
 | 
				
			||||||
    elif event_type == "note_create":
 | 
					    elif event_type == "note_create":
 | 
				
			||||||
        subject = "Comment added"
 | 
					        topic = "Comment added"
 | 
				
			||||||
        content = description + more_info
 | 
					        content = description + more_info
 | 
				
			||||||
    elif event_type == "story_create":
 | 
					    elif event_type == "story_create":
 | 
				
			||||||
        issue_desc = get_text(["stories", "story", "description"])
 | 
					        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"])
 | 
					        estimate = get_text(["stories", "story", "estimate"])
 | 
				
			||||||
        if estimate != "":
 | 
					        if estimate != "":
 | 
				
			||||||
            estimate = f" worth {estimate} story points"
 | 
					            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}"
 | 
					        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 = [
 | 
					UNSUPPORTED_EVENT_TYPES = [
 | 
				
			||||||
@@ -107,7 +107,7 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> T
 | 
				
			|||||||
    changes = payload.get("changes", [])
 | 
					    changes = payload.get("changes", [])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    content = ""
 | 
					    content = ""
 | 
				
			||||||
    subject = f"#{story_id}: {story_name}"
 | 
					    topic = f"#{story_id}: {story_name}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def extract_comment(change: Dict[str, Any]) -> Optional[str]:
 | 
					    def extract_comment(change: Dict[str, Any]) -> Optional[str]:
 | 
				
			||||||
        if change.get("kind") == "comment":
 | 
					        if change.get("kind") == "comment":
 | 
				
			||||||
@@ -172,21 +172,21 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> T
 | 
				
			|||||||
    else:
 | 
					    else:
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError(event_type)
 | 
					        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)
 | 
					@webhook_view("Pivotal", all_event_types=ALL_EVENT_TYPES)
 | 
				
			||||||
@has_request_variables
 | 
					@has_request_variables
 | 
				
			||||||
def api_pivotal_webhook(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
 | 
					def api_pivotal_webhook(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
 | 
				
			||||||
    subject = content = None
 | 
					    topic = content = None
 | 
				
			||||||
    try:
 | 
					    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:
 | 
					    except Exception:
 | 
				
			||||||
        # Attempt to parse v5 JSON payload
 | 
					        # 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:
 | 
					    if not content:
 | 
				
			||||||
        raise JsonableError(_("Unable to handle Pivotal payload"))
 | 
					        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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -52,15 +52,15 @@ def api_radarr_webhook(
 | 
				
			|||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    body = get_body_for_http_request(payload)
 | 
					    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(
 | 
					    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)
 | 
					    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)
 | 
					    event_type = payload["eventType"].tame(check_string)
 | 
				
			||||||
    if event_type == "Test":
 | 
					    if event_type == "Test":
 | 
				
			||||||
        return RADARR_TOPIC_TEMPLATE_TEST
 | 
					        return RADARR_TOPIC_TEMPLATE_TEST
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,10 +18,10 @@ def api_rundeck_webhook(
 | 
				
			|||||||
    user_profile: UserProfile,
 | 
					    user_profile: UserProfile,
 | 
				
			||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    subject = get_topic(payload)
 | 
					    topic = get_topic(payload)
 | 
				
			||||||
    body = get_body(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)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -101,12 +101,12 @@ def api_semaphore_webhook(
 | 
				
			|||||||
    content, project_name, branch_name, event = (
 | 
					    content, project_name, branch_name, event = (
 | 
				
			||||||
        semaphore_classic(payload) if "event" in payload else semaphore_2(payload)
 | 
					        semaphore_classic(payload) if "event" in payload else semaphore_2(payload)
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    subject = (
 | 
					    topic = (
 | 
				
			||||||
        TOPIC_TEMPLATE.format(project=project_name, branch=branch_name)
 | 
					        TOPIC_TEMPLATE.format(project=project_name, branch=branch_name)
 | 
				
			||||||
        if branch_name
 | 
					        if branch_name
 | 
				
			||||||
        else project_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)
 | 
					    return json_success(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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]:
 | 
					def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
 | 
				
			||||||
    """Handle either an exception type event or a message type event payload."""
 | 
					    """Handle either an exception type event or a message type event payload."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    subject = event["title"]
 | 
					    topic = event["title"]
 | 
				
			||||||
    platform_name = event["platform"]
 | 
					    platform_name = event["platform"]
 | 
				
			||||||
    syntax_highlight_as = syntax_highlight_as_map.get(platform_name, "")
 | 
					    syntax_highlight_as = syntax_highlight_as_map.get(platform_name, "")
 | 
				
			||||||
    if syntax_highlight_as == "":  # nocoverage
 | 
					    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:
 | 
					        if ["sample_event", "yes"] not in tags:
 | 
				
			||||||
            raise UnsupportedWebhookEventTypeError("Raven SDK")
 | 
					            raise UnsupportedWebhookEventTypeError("Raven SDK")
 | 
				
			||||||
    context = {
 | 
					    context = {
 | 
				
			||||||
        "title": subject,
 | 
					        "title": topic,
 | 
				
			||||||
        "level": event["level"],
 | 
					        "level": event["level"],
 | 
				
			||||||
        "web_link": event["web_url"],
 | 
					        "web_link": event["web_url"],
 | 
				
			||||||
        "datetime": event["datetime"].split(".")[0].replace("T", " "),
 | 
					        "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)
 | 
					                body = EXCEPTION_EVENT_TEMPLATE_WITH_TRACEBACK.format(**context)
 | 
				
			||||||
                return (subject, body)
 | 
					                return (topic, body)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        context.update(filename=filename)  # nocoverage
 | 
					        context.update(filename=filename)  # nocoverage
 | 
				
			||||||
        body = EXCEPTION_EVENT_TEMPLATE.format(**context)  # nocoverage
 | 
					        body = EXCEPTION_EVENT_TEMPLATE.format(**context)  # nocoverage
 | 
				
			||||||
        return (subject, body)  # nocoverage
 | 
					        return (topic, body)  # nocoverage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    elif "logentry" in event:
 | 
					    elif "logentry" in event:
 | 
				
			||||||
        # The event was triggered by a sentry.capture_message() call
 | 
					        # 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:
 | 
					    else:
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError("unknown-event type")
 | 
					        raise UnsupportedWebhookEventTypeError("unknown-event type")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (subject, body)
 | 
					    return (topic, body)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def handle_issue_payload(
 | 
					def handle_issue_payload(
 | 
				
			||||||
    action: str, issue: Dict[str, Any], actor: Dict[str, Any]
 | 
					    action: str, issue: Dict[str, Any], actor: Dict[str, Any]
 | 
				
			||||||
) -> Tuple[str, str]:
 | 
					) -> Tuple[str, str]:
 | 
				
			||||||
    """Handle either an issue type event."""
 | 
					    """Handle either an issue type event."""
 | 
				
			||||||
    subject = issue["title"]
 | 
					    topic = issue["title"]
 | 
				
			||||||
    datetime = issue["lastSeen"].split(".")[0].replace("T", " ")
 | 
					    datetime = issue["lastSeen"].split(".")[0].replace("T", " ")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if issue["assignedTo"]:
 | 
					    if issue["assignedTo"]:
 | 
				
			||||||
@@ -191,7 +191,7 @@ def handle_issue_payload(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if action == "created":
 | 
					    if action == "created":
 | 
				
			||||||
        context = {
 | 
					        context = {
 | 
				
			||||||
            "title": subject,
 | 
					            "title": topic,
 | 
				
			||||||
            "level": issue["level"],
 | 
					            "level": issue["level"],
 | 
				
			||||||
            "datetime": datetime,
 | 
					            "datetime": datetime,
 | 
				
			||||||
            "assignee": assignee,
 | 
					            "assignee": assignee,
 | 
				
			||||||
@@ -200,14 +200,14 @@ def handle_issue_payload(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    elif action == "resolved":
 | 
					    elif action == "resolved":
 | 
				
			||||||
        context = {
 | 
					        context = {
 | 
				
			||||||
            "title": subject,
 | 
					            "title": topic,
 | 
				
			||||||
            "actor": actor["name"],
 | 
					            "actor": actor["name"],
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        body = ISSUE_RESOLVED_MESSAGE_TEMPLATE.format(**context)
 | 
					        body = ISSUE_RESOLVED_MESSAGE_TEMPLATE.format(**context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    elif action == "assigned":
 | 
					    elif action == "assigned":
 | 
				
			||||||
        context = {
 | 
					        context = {
 | 
				
			||||||
            "title": subject,
 | 
					            "title": topic,
 | 
				
			||||||
            "assignee": assignee,
 | 
					            "assignee": assignee,
 | 
				
			||||||
            "actor": actor["name"],
 | 
					            "actor": actor["name"],
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -215,7 +215,7 @@ def handle_issue_payload(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    elif action == "ignored":
 | 
					    elif action == "ignored":
 | 
				
			||||||
        context = {
 | 
					        context = {
 | 
				
			||||||
            "title": subject,
 | 
					            "title": topic,
 | 
				
			||||||
            "actor": actor["name"],
 | 
					            "actor": actor["name"],
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        body = ISSUE_IGNORED_MESSAGE_TEMPLATE.format(**context)
 | 
					        body = ISSUE_IGNORED_MESSAGE_TEMPLATE.format(**context)
 | 
				
			||||||
@@ -223,17 +223,17 @@ def handle_issue_payload(
 | 
				
			|||||||
    else:
 | 
					    else:
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError("unknown-issue-action type")
 | 
					        raise UnsupportedWebhookEventTypeError("unknown-issue-action type")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (subject, body)
 | 
					    return (topic, body)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def handle_deprecated_payload(payload: Dict[str, Any]) -> Tuple[str, str]:
 | 
					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(
 | 
					    body = DEPRECATED_EXCEPTION_MESSAGE_TEMPLATE.format(
 | 
				
			||||||
        level=payload["level"].upper(),
 | 
					        level=payload["level"].upper(),
 | 
				
			||||||
        url=payload.get("url"),
 | 
					        url=payload.get("url"),
 | 
				
			||||||
        message=payload.get("message"),
 | 
					        message=payload.get("message"),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    return (subject, body)
 | 
					    return (topic, body)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def transform_webhook_payload(payload: Dict[str, Any]) -> Optional[Dict[str, Any]]:
 | 
					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.
 | 
					    # We currently support two types of payloads: events and issues.
 | 
				
			||||||
    if data:
 | 
					    if data:
 | 
				
			||||||
        if "event" in data:
 | 
					        if "event" in data:
 | 
				
			||||||
            subject, body = handle_event_payload(data["event"])
 | 
					            topic, body = handle_event_payload(data["event"])
 | 
				
			||||||
        elif "issue" in data:
 | 
					        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:
 | 
					        else:
 | 
				
			||||||
            raise UnsupportedWebhookEventTypeError(str(list(data.keys())))
 | 
					            raise UnsupportedWebhookEventTypeError(str(list(data.keys())))
 | 
				
			||||||
    else:
 | 
					    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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,13 +28,13 @@ def api_slack_webhook(
 | 
				
			|||||||
        raise JsonableError(_("Error: channels_map_to_topics parameter other than 0 or 1"))
 | 
					        raise JsonableError(_("Error: channels_map_to_topics parameter other than 0 or 1"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if channels_map_to_topics == VALID_OPTIONS["SHOULD_BE_MAPPED"]:
 | 
					    if channels_map_to_topics == VALID_OPTIONS["SHOULD_BE_MAPPED"]:
 | 
				
			||||||
        subject = f"channel: {channel_name}"
 | 
					        topic = f"channel: {channel_name}"
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        stream = channel_name
 | 
					        stream = channel_name
 | 
				
			||||||
        subject = _("Message from Slack")
 | 
					        topic = _("Message from Slack")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    content = ZULIP_MESSAGE_TEMPLATE.format(message_sender=user_name, text=text)
 | 
					    content = ZULIP_MESSAGE_TEMPLATE.format(message_sender=user_name, text=text)
 | 
				
			||||||
    client = RequestNotes.get_notes(request).client
 | 
					    client = RequestNotes.get_notes(request).client
 | 
				
			||||||
    assert client is not None
 | 
					    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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,15 +46,15 @@ def api_sonarr_webhook(
 | 
				
			|||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    body = get_body_for_http_request(payload)
 | 
					    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(
 | 
					    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)
 | 
					    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)
 | 
					    event_type = payload["eventType"].tame(check_string)
 | 
				
			||||||
    if event_type != "Test" and event_type != "Health":
 | 
					    if event_type != "Test" and event_type != "Health":
 | 
				
			||||||
        topic = SONARR_TOPIC_TEMPLATE.format(
 | 
					        topic = SONARR_TOPIC_TEMPLATE.format(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ def api_transifex_webhook(
 | 
				
			|||||||
    translated: Optional[int] = REQ(json_validator=check_int, default=None),
 | 
					    translated: Optional[int] = REQ(json_validator=check_int, default=None),
 | 
				
			||||||
    reviewed: Optional[int] = REQ(json_validator=check_int, default=None),
 | 
					    reviewed: Optional[int] = REQ(json_validator=check_int, default=None),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    subject = f"{project} in {language}"
 | 
					    topic = f"{project} in {language}"
 | 
				
			||||||
    if translated:
 | 
					    if translated:
 | 
				
			||||||
        event = "translated"
 | 
					        event = "translated"
 | 
				
			||||||
        body = f"Resource {resource} fully translated."
 | 
					        body = f"Resource {resource} fully translated."
 | 
				
			||||||
@@ -34,5 +34,5 @@ def api_transifex_webhook(
 | 
				
			|||||||
        body = f"Resource {resource} fully reviewed."
 | 
					        body = f"Resource {resource} fully reviewed."
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        raise UnsupportedWebhookEventTypeError("Unknown Event Type")
 | 
					        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)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,17 +24,17 @@ def api_trello_webhook(
 | 
				
			|||||||
    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
					    payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    action_type = payload["action"]["type"].tame(check_string)
 | 
					    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:
 | 
					    if message is None:
 | 
				
			||||||
        return json_success(request)
 | 
					        return json_success(request)
 | 
				
			||||||
    else:
 | 
					    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)
 | 
					    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:
 | 
					    if action_type in SUPPORTED_CARD_ACTIONS:
 | 
				
			||||||
        return process_card_action(payload, action_type)
 | 
					        return process_card_action(payload, action_type)
 | 
				
			||||||
    if action_type in IGNORED_CARD_ACTIONS:
 | 
					    if action_type in IGNORED_CARD_ACTIONS:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ def process_board_action(
 | 
				
			|||||||
) -> Optional[Tuple[str, str]]:
 | 
					) -> Optional[Tuple[str, str]]:
 | 
				
			||||||
    action_type = get_proper_action(payload, action_type)
 | 
					    action_type = get_proper_action(payload, action_type)
 | 
				
			||||||
    if action_type is not None:
 | 
					    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
 | 
					    return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -47,7 +47,7 @@ def get_proper_action(payload: WildValue, action_type: Optional[str]) -> Optiona
 | 
				
			|||||||
    return action_type
 | 
					    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)
 | 
					    return get_action_data(payload)["board"]["name"].tame(check_string)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,7 +78,7 @@ def prettify_date(date_string: str) -> str:
 | 
				
			|||||||
def process_card_action(payload: WildValue, action_type: str) -> Optional[Tuple[str, str]]:
 | 
					def process_card_action(payload: WildValue, action_type: str) -> Optional[Tuple[str, str]]:
 | 
				
			||||||
    proper_action = get_proper_action(payload, action_type)
 | 
					    proper_action = get_proper_action(payload, action_type)
 | 
				
			||||||
    if proper_action is not None:
 | 
					    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
 | 
					    return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -131,7 +131,7 @@ def get_proper_action(payload: WildValue, action_type: str) -> Optional[str]:
 | 
				
			|||||||
    return action_type
 | 
					    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)
 | 
					    return get_action_data(payload)["board"]["name"].tame(check_string)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,9 +18,9 @@ def send_message_for_event(
 | 
				
			|||||||
    request: HttpRequest, user_profile: UserProfile, event: WildValue
 | 
					    request: HttpRequest, user_profile: UserProfile, event: WildValue
 | 
				
			||||||
) -> None:
 | 
					) -> None:
 | 
				
			||||||
    event_type = get_event_type(event)
 | 
					    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)
 | 
					    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:
 | 
					def get_body_for_up_event(event: WildValue) -> str:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,7 @@ def api_uptimerobot_webhook(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        body = get_body_for_http_request(payload, event_type)
 | 
					        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:
 | 
					    except ValidationError:
 | 
				
			||||||
        message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format(
 | 
					        message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format(
 | 
				
			||||||
            bot_name=user_profile.full_name,
 | 
					            bot_name=user_profile.full_name,
 | 
				
			||||||
@@ -56,11 +56,11 @@ def api_uptimerobot_webhook(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        raise JsonableError(_("Invalid payload"))
 | 
					        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)
 | 
					    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(
 | 
					    return UPTIMEROBOT_TOPIC_TEMPLATE.format(
 | 
				
			||||||
        monitor_friendly_name=payload["monitor_friendly_name"].tame(check_string)
 | 
					        monitor_friendly_name=payload["monitor_friendly_name"].tame(check_string)
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,7 +38,7 @@ def api_zabbix_webhook(
 | 
				
			|||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        body = get_body_for_http_request(payload)
 | 
					        body = get_body_for_http_request(payload)
 | 
				
			||||||
        subject = get_subject_for_http_request(payload)
 | 
					        topic = get_topic_for_http_request(payload)
 | 
				
			||||||
    except ValidationError:
 | 
					    except ValidationError:
 | 
				
			||||||
        message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format(
 | 
					        message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format(
 | 
				
			||||||
            bot_name=user_profile.full_name,
 | 
					            bot_name=user_profile.full_name,
 | 
				
			||||||
@@ -48,11 +48,11 @@ def api_zabbix_webhook(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        raise JsonableError(_("Invalid payload"))
 | 
					        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)
 | 
					    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))
 | 
					    return ZABBIX_TOPIC_TEMPLATE.format(hostname=payload["hostname"].tame(check_string))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,9 +25,9 @@ def api_zendesk_webhook(
 | 
				
			|||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Zendesk uses triggers with message templates. This webhook uses the
 | 
					    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.
 | 
					    user's configured message to zulip.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    subject = truncate(f"#{ticket_id}: {ticket_title}", 60)
 | 
					    topic = truncate(f"#{ticket_id}: {ticket_title}", 60)
 | 
				
			||||||
    check_send_webhook_message(request, user_profile, subject, message)
 | 
					    check_send_webhook_message(request, user_profile, topic, message)
 | 
				
			||||||
    return json_success(request)
 | 
					    return json_success(request)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user