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

This commit is contained in:
upstream-mirror
2026-09-15 15:05:30 +05:00
commit 64898b2c79
8999 changed files with 1757358 additions and 0 deletions

View File

View File

@@ -0,0 +1,30 @@
# Zulip Sonarqube integration
Get Zulip notifications for your Sonarqube code analysis!
{start_tabs}
1. {!create-an-incoming-webhook.md!}
1. {!generate-webhook-url-basic.md!}
1. To configure webhooks for a specific SonarQube project, go to the project,
and select **Administration**. Select **Webhooks**, and click **Create**.
1. Set **Name** of the webhook to a name of your choice, such as `Zulip`.
Set **URL** to the URL generated above, and click **Create**.
!!! tip ""
You can also configure webhooks globally in SonarQube via
**Configurations** -> **Webhooks**.
{end_tabs}
{!congrats.md!}
![](/static/images/integrations/sonarqube/001.png)
### Related documentation
{!webhooks-url-specification.md!}

View File

@@ -0,0 +1,46 @@
{
"serverUrl": "http://localhost:9000",
"taskId": "AXgTFfXRZCzhMRNj54bo",
"status": "SUCCESS",
"analysedAt": "2021-03-08T18:25:04+0000",
"changedAt": "2021-03-08T18:25:04+0000",
"project": {
"key": "test-sonar",
"name": "test-sonar",
"url": "http://localhost:9000/dashboard?id=test-sonar"
},
"branch": {
"name": "master",
"type": "BRANCH",
"isMain": true,
"url": "http://localhost:9000/dashboard?id=test-sonar"
},
"qualityGate": {
"name": "Sonar way",
"status": "ERROR",
"conditions": [
{
"metric": "maintainability_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "coverage",
"operator": "LESS_THAN",
"value": "0.0",
"status": "ERROR",
"errorThreshold": "80"
},
{
"metric": "duplicated_lines_density",
"operator": "GREATER_THAN",
"value": "89.39828080229226",
"status": "ERROR",
"errorThreshold": "3"
}
]
},
"properties": {}
}

View File

@@ -0,0 +1,40 @@
{
"serverUrl": "http://localhost:9000",
"taskId": "AXgTFfXRZCzhMRNj54bo",
"status": "SUCCESS",
"analysedAt": "2021-03-08T18:25:04+0000",
"changedAt": "2021-03-08T18:25:04+0000",
"project": {
"key": "test-sonar",
"name": "test-sonar",
"url": "http://localhost:9000/dashboard?id=test-sonar"
},
"qualityGate": {
"name": "Sonar way",
"status": "ERROR",
"conditions": [
{
"metric": "maintainability_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "coverage",
"operator": "LESS_THAN",
"value": "0.0",
"status": "ERROR",
"errorThreshold": "80"
},
{
"metric": "duplicated_lines_density",
"operator": "GREATER_THAN",
"value": "89.39828080229226",
"status": "ERROR",
"errorThreshold": "3"
}
]
},
"properties": {}
}

View File

@@ -0,0 +1,45 @@
{
"serverUrl": "http://localhost:9000",
"taskId": "AXgTFfXRZCzhMRNj54bo",
"status": "SUCCESS",
"analysedAt": "2021-03-08T18:25:04+0000",
"changedAt": "2021-03-08T18:25:04+0000",
"project": {
"key": "test-sonar",
"name": "test-sonar",
"url": "http://localhost:9000/dashboard?id=test-sonar"
},
"branch": {
"name": "master",
"type": "BRANCH",
"isMain": true,
"url": "http://localhost:9000/dashboard?id=test-sonar"
},
"qualityGate": {
"name": "Sonar way",
"status": "ERROR",
"conditions": [
{
"metric": "maintainability_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "coverage",
"operator": "LESS_THAN",
"value": "0.0",
"status": "ERROR",
"errorThreshold": "80"
},
{
"metric": "duplicated_lines_density",
"operator": "GREATER_THAN",
"status": "ERROR",
"errorThreshold": "3"
}
]
},
"properties": {}
}

View File

@@ -0,0 +1,64 @@
{
"serverUrl": "http://localhost:9000",
"taskId": "AXgTFfXRZCzhMRNj54bo",
"status": "SUCCESS",
"analysedAt": "2021-03-08T18:25:04+0000",
"changedAt": "2021-03-08T18:25:04+0000",
"project": {
"key": "test-sonar",
"name": "test-sonar",
"url": "http://localhost:9000/dashboard?id=test-sonar"
},
"branch": {
"name": "master",
"type": "BRANCH",
"isMain": true,
"url": "http://localhost:9000/dashboard?id=test-sonar"
},
"qualityGate": {
"name": "Sonar way",
"status": "OK",
"conditions": [
{
"metric": "new_reliability_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "new_security_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "new_maintainability_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "new_coverage",
"operator": "LESS_THAN",
"status": "NO_VALUE",
"errorThreshold": "80"
},
{
"metric": "new_duplicated_lines_density",
"operator": "GREATER_THAN",
"status": "NO_VALUE",
"errorThreshold": "3"
},
{
"metric": "new_security_hotspots_reviewed",
"operator": "LESS_THAN",
"status": "NO_VALUE",
"errorThreshold": "100"
}
]
},
"properties": {}
}

View File

@@ -0,0 +1,58 @@
{
"serverUrl": "http://localhost:9000",
"taskId": "AXgTFfXRZCzhMRNj54bo",
"status": "SUCCESS",
"analysedAt": "2021-03-08T18:25:04+0000",
"changedAt": "2021-03-08T18:25:04+0000",
"project": {
"key": "test-sonar",
"name": "test-sonar",
"url": "http://localhost:9000/dashboard?id=test-sonar"
},
"qualityGate": {
"name": "Sonar way",
"status": "OK",
"conditions": [
{
"metric": "new_reliability_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "new_security_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "new_maintainability_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "new_coverage",
"operator": "LESS_THAN",
"status": "NO_VALUE",
"errorThreshold": "80"
},
{
"metric": "new_duplicated_lines_density",
"operator": "GREATER_THAN",
"status": "NO_VALUE",
"errorThreshold": "3"
},
{
"metric": "new_security_hotspots_reviewed",
"operator": "LESS_THAN",
"status": "NO_VALUE",
"errorThreshold": "100"
}
]
},
"properties": {}
}

View File

@@ -0,0 +1,79 @@
from zerver.lib.test_classes import WebhookTestCase
class SonarqubeHookTests(WebhookTestCase):
def test_analysis_success(self) -> None:
expected_topic_name = "test-sonar / master"
expected_message = """
Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis of branch master resulted in success.
""".strip()
self.check_webhook(
"success",
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_analysis_error(self) -> None:
expected_topic_name = "test-sonar / master"
expected_message = """
Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis of branch master resulted in error:
* coverage: **error** 0.0 should be greater than or equal to 80.
* duplicated lines density: **error** 89.39828080229226 should be less than or equal to 3.
""".strip()
self.check_webhook(
"error",
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_analysis_error_no_value(self) -> None:
expected_topic_name = "test-sonar / master"
expected_message = """
Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis of branch master resulted in error:
* coverage: **error** 0.0 should be greater than or equal to 80.
* duplicated lines density: **error**.
""".strip()
self.check_webhook(
"error_no_value",
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_analysis_success_no_branch(self) -> None:
expected_topic_name = "test-sonar"
expected_message = """
Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis resulted in success.
""".strip()
self.check_webhook(
"success_no_branch",
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_analysis_error_no_branch(self) -> None:
expected_topic_name = "test-sonar"
expected_message = """
Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis resulted in error:
* coverage: **error** 0.0 should be greater than or equal to 80.
* duplicated lines density: **error** 89.39828080229226 should be less than or equal to 3.
""".strip()
self.check_webhook(
"error_no_branch",
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)

View File

@@ -0,0 +1,130 @@
# Webhooks for external integrations.
from django.http import HttpRequest, HttpResponse
from zerver.decorator import webhook_view
from zerver.lib.response import json_success
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
from zerver.lib.validator import WildValue, check_none_or, check_string
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
TOPIC_WITH_BRANCH = "{} / {}"
MESSAGE_WITH_BRANCH_AND_CONDITIONS = "Project [{}]({}) analysis of branch {} resulted in {}:\n"
MESSAGE_WITH_BRANCH_AND_WITHOUT_CONDITIONS = (
"Project [{}]({}) analysis of branch {} resulted in {}."
)
MESSAGE_WITHOUT_BRANCH_AND_WITH_CONDITIONS = "Project [{}]({}) analysis resulted in {}:\n"
MESSAGE_WITHOUT_BRANCH_AND_CONDITIONS = "Project [{}]({}) analysis resulted in {}."
INVERSE_OPERATORS = {
"WORSE_THAN": "should be better or equal to",
"GREATER_THAN": "should be less than or equal to",
"LESS_THAN": "should be greater than or equal to",
}
TEMPLATES = {
"default": "* {}: **{}** {} {} {}.",
"no_value": "* {}: **{}**.",
}
def parse_metric_name(metric_name: str) -> str:
return " ".join(metric_name.split("_"))
def parse_condition(condition: WildValue) -> str:
metric = condition["metric"].tame(check_string)
metric_name = parse_metric_name(metric)
operator = condition["operator"].tame(check_string)
operator = INVERSE_OPERATORS.get(operator, operator)
value = condition.get("value", "no value").tame(check_string)
status = condition["status"].tame(check_string).lower()
threshold = condition["errorThreshold"].tame(check_string)
if value == "no value":
return TEMPLATES["no_value"].format(metric_name, status)
template = TEMPLATES["default"]
return template.format(metric_name, status, value, operator, threshold)
def parse_conditions(conditions: WildValue) -> str:
return "\n".join(
[
parse_condition(condition)
for condition in conditions
if condition["status"].tame(check_string).lower() != "ok"
and condition["status"].tame(check_string).lower() != "no_value"
]
)
def render_body_with_branch(payload: WildValue) -> str:
project_name = payload["project"]["name"].tame(check_string)
project_url = payload["project"]["url"].tame(check_string)
quality_gate_status = payload["qualityGate"]["status"].tame(check_string).lower()
if quality_gate_status == "ok":
quality_gate_status = "success"
else:
quality_gate_status = "error"
branch = payload["branch"]["name"].tame(check_string)
conditions = parse_conditions(payload["qualityGate"]["conditions"])
if not conditions:
return MESSAGE_WITH_BRANCH_AND_WITHOUT_CONDITIONS.format(
project_name, project_url, branch, quality_gate_status
)
msg = MESSAGE_WITH_BRANCH_AND_CONDITIONS.format(
project_name, project_url, branch, quality_gate_status
)
msg += conditions
return msg
def render_body_without_branch(payload: WildValue) -> str:
project_name = payload["project"]["name"].tame(check_string)
project_url = payload["project"]["url"].tame(check_string)
quality_gate_status = payload["qualityGate"]["status"].tame(check_string).lower()
if quality_gate_status == "ok":
quality_gate_status = "success"
else:
quality_gate_status = "error"
conditions = parse_conditions(payload["qualityGate"]["conditions"])
if not conditions:
return MESSAGE_WITHOUT_BRANCH_AND_CONDITIONS.format(
project_name, project_url, quality_gate_status
)
msg = MESSAGE_WITHOUT_BRANCH_AND_WITH_CONDITIONS.format(
project_name, project_url, quality_gate_status
)
msg += conditions
return msg
@webhook_view("Sonarqube")
@typed_endpoint
def api_sonarqube_webhook(
request: HttpRequest,
user_profile: UserProfile,
*,
payload: JsonBodyPayload[WildValue],
) -> HttpResponse:
project = payload["project"]["name"].tame(check_string)
branch = None
if "branch" in payload:
branch = payload["branch"].get("name").tame(check_none_or(check_string))
if branch:
topic_name = TOPIC_WITH_BRANCH.format(project, branch)
message = render_body_with_branch(payload)
else:
topic_name = project
message = render_body_without_branch(payload)
check_send_webhook_message(request, user_profile, topic_name, message)
return json_success(request)