Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

integrations: Add `IGNORE_PRIVATE_REPOSITORIES` preset WebhookUrlOption.

PieterCK3863f4d6a59e
diff --git a/api_docs/incoming-webhooks-walkthrough.md b/api_docs/incoming-webhooks-walkthrough.md
index f60fce3c571..af14103b28c 100644
--- a/api_docs/incoming-webhooks-walkthrough.md
+++ b/api_docs/incoming-webhooks-walkthrough.md
@@ -297,6 +297,13 @@ Currently configured preset URL options:
input `main` and `dev` for the branches of their repository, then
`&branches=main%2Cdev` would be appended to the generated integration URL.
+- **`IGNORE_PRIVATE_REPOSITORIES`**: This preset is intended to be used for
+ [version control integrations](/integrations/version-control), and adds UI
+ for the user exclude private repositories from triggering Zulip
+ notification messages. When the user selects this option, the
+ `ignore_private_repositories` boolean parameter will be added to the
+ [generated integration URL](/help/generate-integration-url).
+
## Step 4: Manually testing the webhook
For either one of the command line tools, first, you'll need to get an
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py
index 84745df5200..8b38cdce073 100644
--- a/zerver/lib/integrations.py
+++ b/zerver/lib/integrations.py
@@ -472,11 +472,7 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
stream_name="github",
url_options=[
WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES),
- WebhookUrlOption(
- name="ignore_private_repositories",
- label="Exclude notifications from private repositories",
- validator=check_bool,
- ),
+ WebhookUrlOption.build_preset_config(PresetUrlOption.IGNORE_PRIVATE_REPOSITORIES),
],
),
WebhookIntegration(
diff --git a/zerver/lib/webhooks/common.py b/zerver/lib/webhooks/common.py
index 16ac2425e33..e646fba3fa0 100644
--- a/zerver/lib/webhooks/common.py
+++ b/zerver/lib/webhooks/common.py
@@ -32,7 +32,7 @@ from zerver.lib.request import RequestNotes
from zerver.lib.send_email import FromAddress
from zerver.lib.timestamp import timestamp_to_datetime
from zerver.lib.typed_endpoint import ApiParamConfig, typed_endpoint
-from zerver.lib.validator import check_string
+from zerver.lib.validator import check_bool, check_string
from zerver.models import UserProfile
MISSING_EVENT_HEADER_MESSAGE = """\
@@ -58,6 +58,7 @@ OptionalUserSpecifiedTopicStr: TypeAlias = Annotated[str | None, ApiParamConfig(
class PresetUrlOption(str, Enum):
BRANCHES = "branches"
+ IGNORE_PRIVATE_REPOSITORIES = "ignore_private_repositories"
@dataclass
@@ -89,6 +90,12 @@ class WebhookUrlOption:
label="",
validator=check_string,
)
+ case PresetUrlOption.IGNORE_PRIVATE_REPOSITORIES:
+ return cls(
+ name=config.value,
+ label="Exclude notifications from private repositories",
+ validator=check_bool,
+ )
raise AssertionError(_("Unknown 'PresetUrlOption': {config}").format(config=config))