integrations: Add IGNORE_PRIVATE_REPOSITORIES preset WebhookUrlOption.

This refactors the `ignore_private_repositories` URL option to be a
preset because it can be used by other "version-control" integrations.
This commit is contained in:
PieterCK
2025-05-12 19:15:15 +07:00
committed by Tim Abbott
parent 57ff908af9
commit 3863f4d6a5
3 changed files with 16 additions and 6 deletions

View File

@@ -297,6 +297,13 @@ Currently configured preset URL options:
input `main` and `dev` for the branches of their repository, then input `main` and `dev` for the branches of their repository, then
`&branches=main%2Cdev` would be appended to the generated integration URL. `&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 ## Step 4: Manually testing the webhook
For either one of the command line tools, first, you'll need to get an For either one of the command line tools, first, you'll need to get an

View File

@@ -472,11 +472,7 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
stream_name="github", stream_name="github",
url_options=[ url_options=[
WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES), WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES),
WebhookUrlOption( WebhookUrlOption.build_preset_config(PresetUrlOption.IGNORE_PRIVATE_REPOSITORIES),
name="ignore_private_repositories",
label="Exclude notifications from private repositories",
validator=check_bool,
),
], ],
), ),
WebhookIntegration( WebhookIntegration(

View File

@@ -32,7 +32,7 @@ from zerver.lib.request import RequestNotes
from zerver.lib.send_email import FromAddress from zerver.lib.send_email import FromAddress
from zerver.lib.timestamp import timestamp_to_datetime from zerver.lib.timestamp import timestamp_to_datetime
from zerver.lib.typed_endpoint import ApiParamConfig, typed_endpoint 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 from zerver.models import UserProfile
MISSING_EVENT_HEADER_MESSAGE = """\ MISSING_EVENT_HEADER_MESSAGE = """\
@@ -58,6 +58,7 @@ OptionalUserSpecifiedTopicStr: TypeAlias = Annotated[str | None, ApiParamConfig(
class PresetUrlOption(str, Enum): class PresetUrlOption(str, Enum):
BRANCHES = "branches" BRANCHES = "branches"
IGNORE_PRIVATE_REPOSITORIES = "ignore_private_repositories"
@dataclass @dataclass
@@ -89,6 +90,12 @@ class WebhookUrlOption:
label="", label="",
validator=check_string, 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)) raise AssertionError(_("Unknown 'PresetUrlOption': {config}").format(config=config))