From c7a6fcaf881a09f15f0a9b630bf4d9f780b134c4 Mon Sep 17 00:00:00 2001 From: Niloth P <20315308+Niloth-p@users.noreply.github.com> Date: Tue, 22 Jul 2025 04:13:41 +0530 Subject: [PATCH] integrations: Add new file for fixtureless screenshot configs registry. This does not include any screenshot configs, just defining the format, and loading FIXTURELESS_SCREENSHOT_CONFIG from the file. Co-authored-by: Lauryn Menard --- docs/documentation/integrations.md | 14 ++++++++++---- zerver/lib/integrations.py | 15 +++++++++++++++ zerver/webhooks/fixtureless_integrations.py | 11 +++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 zerver/webhooks/fixtureless_integrations.py diff --git a/docs/documentation/integrations.md b/docs/documentation/integrations.md index bff36477a4..0a282061b5 100644 --- a/docs/documentation/integrations.md +++ b/docs/documentation/integrations.md @@ -54,10 +54,16 @@ Typically, the documentation process involves the following steps: generate a screenshot of the message to provide an example message in the integration's documentation. - If your new integration is an incoming webhook integration, you can - generate the screenshot using - `tools/screenshots/generate-integration-docs-screenshot`, where - `integrationname` is the name of the integration: + If your new integration is not a webhook and does not have fixtures, add a + message template and topic to `zerver/webhooks/fixtureless_integrations.py`. + Then, add your integration's name to `FIXTURELESS_INTEGRATIONS_WITH_SCREENSHOTS` + in `zerver/lib/integrations.py`. + + Otherwise, you should have already added your integration to + `WEBHOOK_SCREENSHOT_CONFIG`. + + Generate the screenshot using `tools/screenshots/generate-integration-docs-screenshot`, + where `integrationname` is the name of the integration: ```bash ./tools/screenshots/generate-integration-docs-screenshot --integration integrationname diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index 8b38cdce07..d52fb7248d 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -14,6 +14,7 @@ from django_stubs_ext import StrPromise from zerver.lib.storage import static_path from zerver.lib.validator import check_bool from zerver.lib.webhooks.common import PresetUrlOption, WebhookConfigOption, WebhookUrlOption +from zerver.webhooks import fixtureless_integrations """This module declares all of the (documented) integrations available in the Zulip server. The Integration class is used as part of @@ -60,6 +61,15 @@ CATEGORIES: dict[str, StrPromise] = { "version-control": gettext_lazy("Version control"), } +# Can also be computed from INTEGRATIONS by removing entries from +# WEBHOOK_INTEGRATIONS and NO_SCREENSHOT_CONFIG, but defined explicitly to +# avoid circular dependency +FIXTURELESS_INTEGRATIONS_WITH_SCREENSHOTS: list[str] = [] +FIXTURELESS_SCREENSHOT_CONTENT: dict[str, list[fixtureless_integrations.ScreenshotContent]] = { + key: [getattr(fixtureless_integrations, key.upper().replace("-", "_"))] + for key in FIXTURELESS_INTEGRATIONS_WITH_SCREENSHOTS +} + class Integration: DEFAULT_LOGO_STATIC_PATH_PNG = "images/integrations/logos/{name}.png" @@ -846,6 +856,11 @@ WEBHOOK_SCREENSHOT_CONFIG: dict[str, list[WebhookScreenshotConfig]] = { } FIXTURELESS_SCREENSHOT_CONFIG: dict[str, list[FixturelessScreenshotConfig]] = {} +for integration, screenshots_contents in FIXTURELESS_SCREENSHOT_CONTENT.items(): + FIXTURELESS_SCREENSHOT_CONFIG[integration] = [ + FixturelessScreenshotConfig(screenshot_content["content"], screenshot_content["topic"]) + for screenshot_content in screenshots_contents + ] DOC_SCREENSHOT_CONFIG: dict[ str, list[WebhookScreenshotConfig] | list[FixturelessScreenshotConfig] diff --git a/zerver/webhooks/fixtureless_integrations.py b/zerver/webhooks/fixtureless_integrations.py new file mode 100644 index 0000000000..2557b1fd34 --- /dev/null +++ b/zerver/webhooks/fixtureless_integrations.py @@ -0,0 +1,11 @@ +from typing import TypedDict + +# For integrations that don't have example webhook fixtures/payloads, +# we create an Zulip notification message content and topic here in +# order to generate an example screenshot to include in the documentation +# page for those integrations. + + +class ScreenshotContent(TypedDict): + topic: str + content: str