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:
72
zerver/webhooks/gitea/view.py
Normal file
72
zerver/webhooks/gitea/view.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# vim:fenc=utf-8
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import webhook_view
|
||||
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
|
||||
from zerver.lib.validator import WildValue, check_bool, check_int, check_string
|
||||
from zerver.lib.webhooks.common import OptionalUserSpecifiedTopicStr, default_fixture_to_headers
|
||||
from zerver.lib.webhooks.git import get_pull_request_event_message
|
||||
from zerver.models import UserProfile
|
||||
|
||||
# Gitea is a fork of Gogs, and so the webhook implementation is nearly the same.
|
||||
from zerver.webhooks.gogs.view import gogs_webhook_main
|
||||
|
||||
fixture_to_headers = default_fixture_to_headers("HTTP_X_GITEA_EVENT")
|
||||
|
||||
|
||||
def format_pull_request_event(payload: WildValue, include_title: bool = False) -> str:
|
||||
assignee = payload["pull_request"]["assignee"]
|
||||
|
||||
if payload["pull_request"]["merged"].tame(check_bool):
|
||||
user_name = payload["pull_request"]["merged_by"]["username"].tame(check_string)
|
||||
action = "merged"
|
||||
else:
|
||||
user_name = payload["sender"]["username"].tame(check_string)
|
||||
action = payload["action"].tame(check_string)
|
||||
|
||||
url = payload["pull_request"]["html_url"].tame(check_string)
|
||||
number = payload["pull_request"]["number"].tame(check_int)
|
||||
target_branch = None
|
||||
base_branch = None
|
||||
if action != "edited":
|
||||
if "head" in payload["pull_request"]:
|
||||
target_branch = payload["pull_request"]["head"]["ref"].tame(check_string)
|
||||
if "base" in payload["pull_request"]:
|
||||
base_branch = payload["pull_request"]["base"]["ref"].tame(check_string)
|
||||
title = payload["pull_request"]["title"].tame(check_string) if include_title else None
|
||||
stringified_assignee = assignee["login"].tame(check_string) if assignee else None
|
||||
|
||||
return get_pull_request_event_message(
|
||||
user_name=user_name,
|
||||
action=action,
|
||||
url=url,
|
||||
number=number,
|
||||
target_branch=target_branch,
|
||||
base_branch=base_branch,
|
||||
title=title,
|
||||
assignee=stringified_assignee,
|
||||
assignee_updated=stringified_assignee if action == "assigned" else None,
|
||||
)
|
||||
|
||||
|
||||
@webhook_view("Gitea")
|
||||
@typed_endpoint
|
||||
def api_gitea_webhook(
|
||||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
*,
|
||||
payload: JsonBodyPayload[WildValue],
|
||||
branches: str | None = None,
|
||||
user_specified_topic: OptionalUserSpecifiedTopicStr = None,
|
||||
) -> HttpResponse:
|
||||
return gogs_webhook_main(
|
||||
"Gitea",
|
||||
"X-Gitea-Event",
|
||||
format_pull_request_event,
|
||||
request,
|
||||
user_profile,
|
||||
payload,
|
||||
branches,
|
||||
user_specified_topic,
|
||||
)
|
||||
Reference in New Issue
Block a user