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 new file for fixtureless screenshot configs registry.

Niloth Pc7a6fcaf881a
diff --git a/docs/documentation/integrations.md b/docs/documentation/integrations.md
index bff36477a42..0a282061b53 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 8b38cdce073..d52fb7248d6 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 00000000000..2557b1fd34f
--- /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