mirror of
https://github.com/zulip/zulip.git
synced 2025-11-20 22:48:16 +00:00
integrations: Migrate channel name from Integration to ScreenshotConfig.
Migrate `stream_name` in Integration class to `channel` in `WebhookScreenshotConfig` and `FixturelessScreenshotConfig` dataclasses. `stream_name` is being used only when generating screenshots, and hence belongs better in the screenshot config objects. In the next commit, the ScreenshotConfig will be added as an Integration property.
This commit is contained in:
@@ -97,11 +97,11 @@ def create_integration_bot(integration: Integration, bot_name: str | None = None
|
||||
return bot
|
||||
|
||||
|
||||
def create_integration_stream(integration: Integration, bot: UserProfile) -> None:
|
||||
def create_integration_channel(channel_name: str, bot: UserProfile) -> None:
|
||||
assert isinstance(bot.bot_owner, UserProfile)
|
||||
realm = bot.bot_owner.realm
|
||||
stream, _created = create_stream_if_needed(realm, integration.stream_name)
|
||||
bulk_add_subscriptions(realm, [stream], [bot, bot.bot_owner], acting_user=bot)
|
||||
channel, _created = create_stream_if_needed(realm, channel_name)
|
||||
bulk_add_subscriptions(realm, [channel], [bot, bot.bot_owner], acting_user=bot)
|
||||
|
||||
|
||||
def get_fixture_info(fixture_path: str) -> tuple[Any, bool, bool, str]:
|
||||
@@ -168,9 +168,9 @@ def send_bot_payload_message(
|
||||
headers.update(dict(Authorization=auth))
|
||||
|
||||
assert isinstance(bot.bot_owner, UserProfile)
|
||||
stream = integration.stream_name or "devel"
|
||||
channel_name = config.channel or integration.name
|
||||
url = f"{bot.bot_owner.realm.url}/{integration.url}"
|
||||
params = {"api_key": bot.api_key, "stream": stream}
|
||||
params = {"api_key": bot.api_key, "stream": channel_name}
|
||||
params.update(config.extra_params)
|
||||
|
||||
extra_args = {}
|
||||
@@ -243,7 +243,8 @@ def generate_screenshot_from_config(
|
||||
) -> None:
|
||||
integration = INTEGRATIONS[integration_name]
|
||||
bot = create_integration_bot(integration, screenshot_config.bot_name)
|
||||
create_integration_stream(integration, bot)
|
||||
channel_name = screenshot_config.channel or integration.name
|
||||
create_integration_channel(channel_name, bot)
|
||||
image_path = get_image_path(integration, screenshot_config)
|
||||
|
||||
if isinstance(integration, WebhookIntegration):
|
||||
@@ -252,10 +253,9 @@ def generate_screenshot_from_config(
|
||||
message_sent = send_bot_payload_message(bot, integration, fixture_path, screenshot_config)
|
||||
else:
|
||||
assert isinstance(screenshot_config, FixturelessScreenshotConfig)
|
||||
create_integration_stream(integration, bot)
|
||||
send_bot_mock_message(
|
||||
bot,
|
||||
channel=screenshot_config.channel or integration.stream_name,
|
||||
channel=channel_name,
|
||||
topic=screenshot_config.topic,
|
||||
message=screenshot_config.message,
|
||||
)
|
||||
@@ -311,7 +311,7 @@ fixtureless_group.add_argument("-M", "--message", help="Message to use for the m
|
||||
fixtureless_group.add_argument(
|
||||
"-C",
|
||||
"--channel",
|
||||
help="Channel name to use for the mock message. Defaults to stream name. Ignored if --topic and --message are not specified.",
|
||||
help="Channel name to use for the mock message. Ignored if --topic and --message are not specified.",
|
||||
)
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
@@ -108,7 +108,6 @@ class Integration:
|
||||
secondary_line_text: str | None = None,
|
||||
display_name: str | None = None,
|
||||
doc: str | None = None,
|
||||
stream_name: str | None = None,
|
||||
legacy: bool = False,
|
||||
config_options: Sequence[WebhookConfigOption] = [],
|
||||
url_options: Sequence[WebhookUrlOption] = [],
|
||||
@@ -148,10 +147,6 @@ class Integration:
|
||||
doc = self.DEFAULT_DOC_PATH.format(name=self.name)
|
||||
self.doc = doc
|
||||
|
||||
if stream_name is None:
|
||||
stream_name = self.name
|
||||
self.stream_name = stream_name
|
||||
|
||||
def is_enabled(self) -> bool:
|
||||
return True
|
||||
|
||||
@@ -236,7 +231,6 @@ class PythonAPIIntegration(Integration):
|
||||
display_name: str | None = None,
|
||||
directory_name: str | None = None,
|
||||
doc: str | None = None,
|
||||
stream_name: str | None = None,
|
||||
legacy: bool = False,
|
||||
) -> None:
|
||||
if directory_name is None:
|
||||
@@ -256,7 +250,6 @@ class PythonAPIIntegration(Integration):
|
||||
secondary_line_text=secondary_line_text,
|
||||
display_name=display_name,
|
||||
doc=doc,
|
||||
stream_name=stream_name,
|
||||
legacy=legacy,
|
||||
)
|
||||
|
||||
@@ -278,7 +271,6 @@ class WebhookIntegration(Integration):
|
||||
url: str | None = None,
|
||||
display_name: str | None = None,
|
||||
doc: str | None = None,
|
||||
stream_name: str | None = None,
|
||||
legacy: bool = False,
|
||||
config_options: Sequence[WebhookConfigOption] = [],
|
||||
url_options: Sequence[WebhookUrlOption] = [],
|
||||
@@ -293,7 +285,6 @@ class WebhookIntegration(Integration):
|
||||
logo=logo,
|
||||
secondary_line_text=secondary_line_text,
|
||||
display_name=display_name,
|
||||
stream_name=stream_name,
|
||||
legacy=legacy,
|
||||
config_options=config_options,
|
||||
url_options=url_options,
|
||||
@@ -343,6 +334,7 @@ class WebhookScreenshotConfig:
|
||||
image_name: str = "001.png"
|
||||
image_dir: str | None = None
|
||||
bot_name: str | None = None
|
||||
channel: str | None = None
|
||||
payload_as_query_param: bool = False
|
||||
payload_param_name: str = "payload"
|
||||
extra_params: dict[str, str] = field(default_factory=dict)
|
||||
@@ -448,7 +440,7 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
||||
display_name="AzureDevOps",
|
||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||
),
|
||||
WebhookIntegration("beanstalk", ["version-control"], stream_name="commits"),
|
||||
WebhookIntegration("beanstalk", ["version-control"]),
|
||||
WebhookIntegration("basecamp", ["project-management"]),
|
||||
WebhookIntegration("beeminder", ["misc"], display_name="Beeminder"),
|
||||
WebhookIntegration(
|
||||
@@ -456,7 +448,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
||||
["version-control"],
|
||||
logo="images/integrations/logos/bitbucket.svg",
|
||||
display_name="Bitbucket Server",
|
||||
stream_name="bitbucket",
|
||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||
),
|
||||
WebhookIntegration(
|
||||
@@ -464,7 +455,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
||||
["version-control"],
|
||||
logo="images/integrations/logos/bitbucket.svg",
|
||||
display_name="Bitbucket",
|
||||
stream_name="bitbucket",
|
||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||
),
|
||||
WebhookIntegration(
|
||||
@@ -472,7 +462,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
||||
["version-control"],
|
||||
display_name="Bitbucket",
|
||||
secondary_line_text="(Enterprise)",
|
||||
stream_name="commits",
|
||||
legacy=True,
|
||||
),
|
||||
WebhookIntegration("buildbot", ["continuous-integration"]),
|
||||
@@ -493,7 +482,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
||||
WebhookIntegration(
|
||||
"gitea",
|
||||
["version-control"],
|
||||
stream_name="commits",
|
||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||
),
|
||||
WebhookIntegration(
|
||||
@@ -512,7 +500,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
||||
logo="images/integrations/logos/github.svg",
|
||||
dir_name="github",
|
||||
doc="github/githubsponsors.md",
|
||||
stream_name="github",
|
||||
),
|
||||
WebhookIntegration(
|
||||
"gitlab",
|
||||
@@ -524,7 +511,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
||||
WebhookIntegration(
|
||||
"gogs",
|
||||
["version-control"],
|
||||
stream_name="commits",
|
||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||
),
|
||||
WebhookIntegration("gosquared", ["marketing"], display_name="GoSquared"),
|
||||
@@ -618,10 +604,7 @@ INTEGRATIONS: dict[str, Integration] = {
|
||||
"errbot": Integration("errbot", ["meta-integration", "bots"]),
|
||||
"giphy": Integration("giphy", ["misc"], display_name="GIPHY"),
|
||||
"github-actions": Integration(
|
||||
"github-actions",
|
||||
["continuous-integration"],
|
||||
display_name="GitHub Actions",
|
||||
stream_name="github-actions updates",
|
||||
"github-actions", ["continuous-integration"], display_name="GitHub Actions"
|
||||
),
|
||||
"hubot": Integration("hubot", ["meta-integration", "bots"]),
|
||||
"jenkins": Integration("jenkins", ["continuous-integration"]),
|
||||
@@ -636,7 +619,7 @@ INTEGRATIONS: dict[str, Integration] = {
|
||||
|
||||
PYTHON_API_INTEGRATIONS: list[PythonAPIIntegration] = [
|
||||
PythonAPIIntegration("codebase", ["version-control"]),
|
||||
PythonAPIIntegration("git", ["version-control"], stream_name="commits"),
|
||||
PythonAPIIntegration("git", ["version-control"]),
|
||||
PythonAPIIntegration(
|
||||
"google-calendar", ["productivity"], display_name="Google Calendar", directory_name="google"
|
||||
),
|
||||
@@ -650,21 +633,14 @@ PYTHON_API_INTEGRATIONS: list[PythonAPIIntegration] = [
|
||||
secondary_line_text="(locally installed)",
|
||||
display_name="Jira",
|
||||
directory_name="jira",
|
||||
stream_name="jira",
|
||||
legacy=True,
|
||||
),
|
||||
PythonAPIIntegration("matrix", ["communication"], directory_name="bridge_with_matrix"),
|
||||
PythonAPIIntegration(
|
||||
"mercurial",
|
||||
["version-control"],
|
||||
display_name="Mercurial (hg)",
|
||||
stream_name="commits",
|
||||
directory_name="hg",
|
||||
"mercurial", ["version-control"], display_name="Mercurial (hg)", directory_name="hg"
|
||||
),
|
||||
PythonAPIIntegration("nagios", ["monitoring"]),
|
||||
PythonAPIIntegration(
|
||||
"openshift", ["deployment"], display_name="OpenShift", stream_name="deployments"
|
||||
),
|
||||
PythonAPIIntegration("openshift", ["deployment"], display_name="OpenShift"),
|
||||
PythonAPIIntegration("perforce", ["version-control"]),
|
||||
PythonAPIIntegration("rss", ["communication"], display_name="RSS"),
|
||||
PythonAPIIntegration("svn", ["version-control"], display_name="Subversion"),
|
||||
@@ -768,18 +744,26 @@ WEBHOOK_SCREENSHOT_CONFIG: dict[str, list[WebhookScreenshotConfig]] = {
|
||||
"basecamp": [WebhookScreenshotConfig("doc_active.json")],
|
||||
"beanstalk": [
|
||||
WebhookScreenshotConfig(
|
||||
"git_multiple.json", use_basic_auth=True, payload_as_query_param=True
|
||||
"git_multiple.json", channel="commits", use_basic_auth=True, payload_as_query_param=True
|
||||
)
|
||||
],
|
||||
# 'beeminder': [WebhookScreenshotConfig('derail_worried.json')],
|
||||
"bitbucket": [
|
||||
WebhookScreenshotConfig(
|
||||
"push.json", "002.png", use_basic_auth=True, payload_as_query_param=True
|
||||
"push.json",
|
||||
"002.png",
|
||||
channel="commits",
|
||||
use_basic_auth=True,
|
||||
payload_as_query_param=True,
|
||||
)
|
||||
],
|
||||
"bitbucket2": [
|
||||
WebhookScreenshotConfig(
|
||||
"issue_created.json", "003.png", "bitbucket", bot_name="Bitbucket Bot"
|
||||
"issue_created.json",
|
||||
"003.png",
|
||||
"bitbucket",
|
||||
bot_name="Bitbucket Bot",
|
||||
channel="bitbucket",
|
||||
)
|
||||
],
|
||||
"bitbucket3": [
|
||||
@@ -788,6 +772,7 @@ WEBHOOK_SCREENSHOT_CONFIG: dict[str, list[WebhookScreenshotConfig]] = {
|
||||
"004.png",
|
||||
"bitbucket",
|
||||
bot_name="Bitbucket Server Bot",
|
||||
channel="bitbucket",
|
||||
)
|
||||
],
|
||||
"buildbot": [WebhookScreenshotConfig("started.json")],
|
||||
@@ -809,12 +794,12 @@ WEBHOOK_SCREENSHOT_CONFIG: dict[str, list[WebhookScreenshotConfig]] = {
|
||||
"freshping": [WebhookScreenshotConfig("freshping_check_unreachable.json")],
|
||||
"freshstatus": [WebhookScreenshotConfig("freshstatus_incident_open.json")],
|
||||
"front": [WebhookScreenshotConfig("inbound_message.json")],
|
||||
"gitea": [WebhookScreenshotConfig("pull_request__merged.json")],
|
||||
"gitea": [WebhookScreenshotConfig("pull_request__merged.json", channel="commits")],
|
||||
"github": [WebhookScreenshotConfig("push__1_commit.json")],
|
||||
"githubsponsors": [WebhookScreenshotConfig("created.json")],
|
||||
"githubsponsors": [WebhookScreenshotConfig("created.json", channel="github")],
|
||||
"gitlab": [WebhookScreenshotConfig("push_hook__push_local_branch_without_commits.json")],
|
||||
"gocd": [WebhookScreenshotConfig("pipeline_with_mixed_job_result.json")],
|
||||
"gogs": [WebhookScreenshotConfig("pull_request__opened.json")],
|
||||
"gogs": [WebhookScreenshotConfig("pull_request__opened.json", channel="commits")],
|
||||
"gosquared": [WebhookScreenshotConfig("traffic_spike.json")],
|
||||
"grafana": [WebhookScreenshotConfig("alert_values_v11.json")],
|
||||
"greenhouse": [WebhookScreenshotConfig("candidate_stage_change.json")],
|
||||
@@ -908,9 +893,13 @@ for integration, screenshots_contents in FIXTURELESS_SCREENSHOT_CONTENT.items():
|
||||
]
|
||||
|
||||
FIXTURELESS_SCREENSHOT_CONFIG_OPTIONAL_FIELDS = {
|
||||
"mercurial": {"image_dir": "hg"},
|
||||
"jenkins": {"image_name": "004.png"},
|
||||
"git": {"channel": "commits"},
|
||||
"github-actions": {"channel": "github-actions updates"},
|
||||
"google-calendar": {"image_name": "003.png", "image_dir": "google/calendar"},
|
||||
"jenkins": {"image_name": "004.png"},
|
||||
"jira-plugin": {"channel": "jira"},
|
||||
"mercurial": {"image_dir": "hg", "channel": "commits"},
|
||||
"openshift": {"channel": "deployments"},
|
||||
}
|
||||
|
||||
for integration, fields in FIXTURELESS_SCREENSHOT_CONFIG_OPTIONAL_FIELDS.items():
|
||||
|
||||
Reference in New Issue
Block a user