snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
97
zerver/webhooks/beanstalk/view.py
Normal file
97
zerver/webhooks/beanstalk/view.py
Normal file
@@ -0,0 +1,97 @@
|
||||
# Webhooks for external integrations.
|
||||
import re
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from pydantic import Json
|
||||
|
||||
from zerver.decorator import authenticated_rest_api_view
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.typed_endpoint import typed_endpoint
|
||||
from zerver.lib.validator import WildValue, check_int, check_string
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
from zerver.lib.webhooks.git import (
|
||||
TOPIC_WITH_BRANCH_TEMPLATE,
|
||||
get_push_commits_event_message,
|
||||
is_branch_name_notifiable,
|
||||
)
|
||||
from zerver.models import UserProfile
|
||||
|
||||
|
||||
def build_message_from_gitlog(
|
||||
user_profile: UserProfile,
|
||||
name: str,
|
||||
ref: str,
|
||||
commits: WildValue,
|
||||
before: str,
|
||||
after: str,
|
||||
url: str,
|
||||
pusher: str,
|
||||
forced: str | None = None,
|
||||
created: str | None = None,
|
||||
deleted: bool = False,
|
||||
) -> tuple[str, str]:
|
||||
short_ref = re.sub(r"^refs/heads/", "", ref)
|
||||
topic_name = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)
|
||||
|
||||
commits_data = _transform_commits_list_to_common_format(commits)
|
||||
content = get_push_commits_event_message(pusher, url, short_ref, commits_data, deleted=deleted)
|
||||
|
||||
return topic_name, content
|
||||
|
||||
|
||||
def _transform_commits_list_to_common_format(commits: WildValue) -> list[dict[str, str]]:
|
||||
return [
|
||||
{
|
||||
"name": commit["author"]["name"].tame(check_string),
|
||||
"sha": commit["id"].tame(check_string),
|
||||
"url": commit["url"].tame(check_string),
|
||||
"message": commit["message"].tame(check_string),
|
||||
}
|
||||
for commit in commits
|
||||
]
|
||||
|
||||
|
||||
@authenticated_rest_api_view(
|
||||
webhook_client_name="Beanstalk",
|
||||
# Beanstalk's web hook UI rejects URL with a @ in the username section
|
||||
# So we ask the user to replace them with %40
|
||||
beanstalk_email_decode=True,
|
||||
)
|
||||
@typed_endpoint
|
||||
def api_beanstalk_webhook(
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
*,
|
||||
payload: Json[WildValue],
|
||||
branches: str | None = None,
|
||||
) -> HttpResponse:
|
||||
# Beanstalk supports both SVN and Git repositories
|
||||
# We distinguish between the two by checking for a
|
||||
# 'uri' key that is only present for Git repos
|
||||
git_repo = "uri" in payload
|
||||
if git_repo:
|
||||
branch = payload["branch"].tame(check_string)
|
||||
if not is_branch_name_notifiable(branch, branches):
|
||||
return json_success(request)
|
||||
|
||||
topic_name, content = build_message_from_gitlog(
|
||||
user_profile,
|
||||
payload["repository"]["name"].tame(check_string),
|
||||
payload["ref"].tame(check_string),
|
||||
payload["commits"],
|
||||
payload["before"].tame(check_string),
|
||||
payload["after"].tame(check_string),
|
||||
payload["repository"]["url"].tame(check_string),
|
||||
payload["pusher_name"].tame(check_string),
|
||||
)
|
||||
else:
|
||||
author = payload["author_full_name"].tame(check_string)
|
||||
url = payload["changeset_url"].tame(check_string)
|
||||
revision = payload["revision"].tame(check_int)
|
||||
(short_commit_msg, _, _) = payload["message"].tame(check_string).partition("\n")
|
||||
|
||||
topic_name = f"svn r{revision}"
|
||||
content = f"{author} pushed [revision {revision}]({url}):\n\n> {short_commit_msg}"
|
||||
|
||||
check_send_webhook_message(request, user_profile, topic_name, content)
|
||||
return json_success(request)
|
||||
Reference in New Issue
Block a user