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
|
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)
|
assert isinstance(bot.bot_owner, UserProfile)
|
||||||
realm = bot.bot_owner.realm
|
realm = bot.bot_owner.realm
|
||||||
stream, _created = create_stream_if_needed(realm, integration.stream_name)
|
channel, _created = create_stream_if_needed(realm, channel_name)
|
||||||
bulk_add_subscriptions(realm, [stream], [bot, bot.bot_owner], acting_user=bot)
|
bulk_add_subscriptions(realm, [channel], [bot, bot.bot_owner], acting_user=bot)
|
||||||
|
|
||||||
|
|
||||||
def get_fixture_info(fixture_path: str) -> tuple[Any, bool, bool, str]:
|
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))
|
headers.update(dict(Authorization=auth))
|
||||||
|
|
||||||
assert isinstance(bot.bot_owner, UserProfile)
|
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}"
|
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)
|
params.update(config.extra_params)
|
||||||
|
|
||||||
extra_args = {}
|
extra_args = {}
|
||||||
@@ -243,7 +243,8 @@ def generate_screenshot_from_config(
|
|||||||
) -> None:
|
) -> None:
|
||||||
integration = INTEGRATIONS[integration_name]
|
integration = INTEGRATIONS[integration_name]
|
||||||
bot = create_integration_bot(integration, screenshot_config.bot_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)
|
image_path = get_image_path(integration, screenshot_config)
|
||||||
|
|
||||||
if isinstance(integration, WebhookIntegration):
|
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)
|
message_sent = send_bot_payload_message(bot, integration, fixture_path, screenshot_config)
|
||||||
else:
|
else:
|
||||||
assert isinstance(screenshot_config, FixturelessScreenshotConfig)
|
assert isinstance(screenshot_config, FixturelessScreenshotConfig)
|
||||||
create_integration_stream(integration, bot)
|
|
||||||
send_bot_mock_message(
|
send_bot_mock_message(
|
||||||
bot,
|
bot,
|
||||||
channel=screenshot_config.channel or integration.stream_name,
|
channel=channel_name,
|
||||||
topic=screenshot_config.topic,
|
topic=screenshot_config.topic,
|
||||||
message=screenshot_config.message,
|
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(
|
fixtureless_group.add_argument(
|
||||||
"-C",
|
"-C",
|
||||||
"--channel",
|
"--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()
|
options = parser.parse_args()
|
||||||
|
|||||||
@@ -108,7 +108,6 @@ class Integration:
|
|||||||
secondary_line_text: str | None = None,
|
secondary_line_text: str | None = None,
|
||||||
display_name: str | None = None,
|
display_name: str | None = None,
|
||||||
doc: str | None = None,
|
doc: str | None = None,
|
||||||
stream_name: str | None = None,
|
|
||||||
legacy: bool = False,
|
legacy: bool = False,
|
||||||
config_options: Sequence[WebhookConfigOption] = [],
|
config_options: Sequence[WebhookConfigOption] = [],
|
||||||
url_options: Sequence[WebhookUrlOption] = [],
|
url_options: Sequence[WebhookUrlOption] = [],
|
||||||
@@ -148,10 +147,6 @@ class Integration:
|
|||||||
doc = self.DEFAULT_DOC_PATH.format(name=self.name)
|
doc = self.DEFAULT_DOC_PATH.format(name=self.name)
|
||||||
self.doc = doc
|
self.doc = doc
|
||||||
|
|
||||||
if stream_name is None:
|
|
||||||
stream_name = self.name
|
|
||||||
self.stream_name = stream_name
|
|
||||||
|
|
||||||
def is_enabled(self) -> bool:
|
def is_enabled(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -236,7 +231,6 @@ class PythonAPIIntegration(Integration):
|
|||||||
display_name: str | None = None,
|
display_name: str | None = None,
|
||||||
directory_name: str | None = None,
|
directory_name: str | None = None,
|
||||||
doc: str | None = None,
|
doc: str | None = None,
|
||||||
stream_name: str | None = None,
|
|
||||||
legacy: bool = False,
|
legacy: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
if directory_name is None:
|
if directory_name is None:
|
||||||
@@ -256,7 +250,6 @@ class PythonAPIIntegration(Integration):
|
|||||||
secondary_line_text=secondary_line_text,
|
secondary_line_text=secondary_line_text,
|
||||||
display_name=display_name,
|
display_name=display_name,
|
||||||
doc=doc,
|
doc=doc,
|
||||||
stream_name=stream_name,
|
|
||||||
legacy=legacy,
|
legacy=legacy,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -278,7 +271,6 @@ class WebhookIntegration(Integration):
|
|||||||
url: str | None = None,
|
url: str | None = None,
|
||||||
display_name: str | None = None,
|
display_name: str | None = None,
|
||||||
doc: str | None = None,
|
doc: str | None = None,
|
||||||
stream_name: str | None = None,
|
|
||||||
legacy: bool = False,
|
legacy: bool = False,
|
||||||
config_options: Sequence[WebhookConfigOption] = [],
|
config_options: Sequence[WebhookConfigOption] = [],
|
||||||
url_options: Sequence[WebhookUrlOption] = [],
|
url_options: Sequence[WebhookUrlOption] = [],
|
||||||
@@ -293,7 +285,6 @@ class WebhookIntegration(Integration):
|
|||||||
logo=logo,
|
logo=logo,
|
||||||
secondary_line_text=secondary_line_text,
|
secondary_line_text=secondary_line_text,
|
||||||
display_name=display_name,
|
display_name=display_name,
|
||||||
stream_name=stream_name,
|
|
||||||
legacy=legacy,
|
legacy=legacy,
|
||||||
config_options=config_options,
|
config_options=config_options,
|
||||||
url_options=url_options,
|
url_options=url_options,
|
||||||
@@ -343,6 +334,7 @@ class WebhookScreenshotConfig:
|
|||||||
image_name: str = "001.png"
|
image_name: str = "001.png"
|
||||||
image_dir: str | None = None
|
image_dir: str | None = None
|
||||||
bot_name: str | None = None
|
bot_name: str | None = None
|
||||||
|
channel: str | None = None
|
||||||
payload_as_query_param: bool = False
|
payload_as_query_param: bool = False
|
||||||
payload_param_name: str = "payload"
|
payload_param_name: str = "payload"
|
||||||
extra_params: dict[str, str] = field(default_factory=dict)
|
extra_params: dict[str, str] = field(default_factory=dict)
|
||||||
@@ -448,7 +440,7 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
|||||||
display_name="AzureDevOps",
|
display_name="AzureDevOps",
|
||||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||||
),
|
),
|
||||||
WebhookIntegration("beanstalk", ["version-control"], stream_name="commits"),
|
WebhookIntegration("beanstalk", ["version-control"]),
|
||||||
WebhookIntegration("basecamp", ["project-management"]),
|
WebhookIntegration("basecamp", ["project-management"]),
|
||||||
WebhookIntegration("beeminder", ["misc"], display_name="Beeminder"),
|
WebhookIntegration("beeminder", ["misc"], display_name="Beeminder"),
|
||||||
WebhookIntegration(
|
WebhookIntegration(
|
||||||
@@ -456,7 +448,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
|||||||
["version-control"],
|
["version-control"],
|
||||||
logo="images/integrations/logos/bitbucket.svg",
|
logo="images/integrations/logos/bitbucket.svg",
|
||||||
display_name="Bitbucket Server",
|
display_name="Bitbucket Server",
|
||||||
stream_name="bitbucket",
|
|
||||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||||
),
|
),
|
||||||
WebhookIntegration(
|
WebhookIntegration(
|
||||||
@@ -464,7 +455,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
|||||||
["version-control"],
|
["version-control"],
|
||||||
logo="images/integrations/logos/bitbucket.svg",
|
logo="images/integrations/logos/bitbucket.svg",
|
||||||
display_name="Bitbucket",
|
display_name="Bitbucket",
|
||||||
stream_name="bitbucket",
|
|
||||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||||
),
|
),
|
||||||
WebhookIntegration(
|
WebhookIntegration(
|
||||||
@@ -472,7 +462,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
|||||||
["version-control"],
|
["version-control"],
|
||||||
display_name="Bitbucket",
|
display_name="Bitbucket",
|
||||||
secondary_line_text="(Enterprise)",
|
secondary_line_text="(Enterprise)",
|
||||||
stream_name="commits",
|
|
||||||
legacy=True,
|
legacy=True,
|
||||||
),
|
),
|
||||||
WebhookIntegration("buildbot", ["continuous-integration"]),
|
WebhookIntegration("buildbot", ["continuous-integration"]),
|
||||||
@@ -493,7 +482,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
|||||||
WebhookIntegration(
|
WebhookIntegration(
|
||||||
"gitea",
|
"gitea",
|
||||||
["version-control"],
|
["version-control"],
|
||||||
stream_name="commits",
|
|
||||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||||
),
|
),
|
||||||
WebhookIntegration(
|
WebhookIntegration(
|
||||||
@@ -512,7 +500,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
|||||||
logo="images/integrations/logos/github.svg",
|
logo="images/integrations/logos/github.svg",
|
||||||
dir_name="github",
|
dir_name="github",
|
||||||
doc="github/githubsponsors.md",
|
doc="github/githubsponsors.md",
|
||||||
stream_name="github",
|
|
||||||
),
|
),
|
||||||
WebhookIntegration(
|
WebhookIntegration(
|
||||||
"gitlab",
|
"gitlab",
|
||||||
@@ -524,7 +511,6 @@ WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [
|
|||||||
WebhookIntegration(
|
WebhookIntegration(
|
||||||
"gogs",
|
"gogs",
|
||||||
["version-control"],
|
["version-control"],
|
||||||
stream_name="commits",
|
|
||||||
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
url_options=[WebhookUrlOption.build_preset_config(PresetUrlOption.BRANCHES)],
|
||||||
),
|
),
|
||||||
WebhookIntegration("gosquared", ["marketing"], display_name="GoSquared"),
|
WebhookIntegration("gosquared", ["marketing"], display_name="GoSquared"),
|
||||||
@@ -618,10 +604,7 @@ INTEGRATIONS: dict[str, Integration] = {
|
|||||||
"errbot": Integration("errbot", ["meta-integration", "bots"]),
|
"errbot": Integration("errbot", ["meta-integration", "bots"]),
|
||||||
"giphy": Integration("giphy", ["misc"], display_name="GIPHY"),
|
"giphy": Integration("giphy", ["misc"], display_name="GIPHY"),
|
||||||
"github-actions": Integration(
|
"github-actions": Integration(
|
||||||
"github-actions",
|
"github-actions", ["continuous-integration"], display_name="GitHub Actions"
|
||||||
["continuous-integration"],
|
|
||||||
display_name="GitHub Actions",
|
|
||||||
stream_name="github-actions updates",
|
|
||||||
),
|
),
|
||||||
"hubot": Integration("hubot", ["meta-integration", "bots"]),
|
"hubot": Integration("hubot", ["meta-integration", "bots"]),
|
||||||
"jenkins": Integration("jenkins", ["continuous-integration"]),
|
"jenkins": Integration("jenkins", ["continuous-integration"]),
|
||||||
@@ -636,7 +619,7 @@ INTEGRATIONS: dict[str, Integration] = {
|
|||||||
|
|
||||||
PYTHON_API_INTEGRATIONS: list[PythonAPIIntegration] = [
|
PYTHON_API_INTEGRATIONS: list[PythonAPIIntegration] = [
|
||||||
PythonAPIIntegration("codebase", ["version-control"]),
|
PythonAPIIntegration("codebase", ["version-control"]),
|
||||||
PythonAPIIntegration("git", ["version-control"], stream_name="commits"),
|
PythonAPIIntegration("git", ["version-control"]),
|
||||||
PythonAPIIntegration(
|
PythonAPIIntegration(
|
||||||
"google-calendar", ["productivity"], display_name="Google Calendar", directory_name="google"
|
"google-calendar", ["productivity"], display_name="Google Calendar", directory_name="google"
|
||||||
),
|
),
|
||||||
@@ -650,21 +633,14 @@ PYTHON_API_INTEGRATIONS: list[PythonAPIIntegration] = [
|
|||||||
secondary_line_text="(locally installed)",
|
secondary_line_text="(locally installed)",
|
||||||
display_name="Jira",
|
display_name="Jira",
|
||||||
directory_name="jira",
|
directory_name="jira",
|
||||||
stream_name="jira",
|
|
||||||
legacy=True,
|
legacy=True,
|
||||||
),
|
),
|
||||||
PythonAPIIntegration("matrix", ["communication"], directory_name="bridge_with_matrix"),
|
PythonAPIIntegration("matrix", ["communication"], directory_name="bridge_with_matrix"),
|
||||||
PythonAPIIntegration(
|
PythonAPIIntegration(
|
||||||
"mercurial",
|
"mercurial", ["version-control"], display_name="Mercurial (hg)", directory_name="hg"
|
||||||
["version-control"],
|
|
||||||
display_name="Mercurial (hg)",
|
|
||||||
stream_name="commits",
|
|
||||||
directory_name="hg",
|
|
||||||
),
|
),
|
||||||
PythonAPIIntegration("nagios", ["monitoring"]),
|
PythonAPIIntegration("nagios", ["monitoring"]),
|
||||||
PythonAPIIntegration(
|
PythonAPIIntegration("openshift", ["deployment"], display_name="OpenShift"),
|
||||||
"openshift", ["deployment"], display_name="OpenShift", stream_name="deployments"
|
|
||||||
),
|
|
||||||
PythonAPIIntegration("perforce", ["version-control"]),
|
PythonAPIIntegration("perforce", ["version-control"]),
|
||||||
PythonAPIIntegration("rss", ["communication"], display_name="RSS"),
|
PythonAPIIntegration("rss", ["communication"], display_name="RSS"),
|
||||||
PythonAPIIntegration("svn", ["version-control"], display_name="Subversion"),
|
PythonAPIIntegration("svn", ["version-control"], display_name="Subversion"),
|
||||||
@@ -768,18 +744,26 @@ WEBHOOK_SCREENSHOT_CONFIG: dict[str, list[WebhookScreenshotConfig]] = {
|
|||||||
"basecamp": [WebhookScreenshotConfig("doc_active.json")],
|
"basecamp": [WebhookScreenshotConfig("doc_active.json")],
|
||||||
"beanstalk": [
|
"beanstalk": [
|
||||||
WebhookScreenshotConfig(
|
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')],
|
# 'beeminder': [WebhookScreenshotConfig('derail_worried.json')],
|
||||||
"bitbucket": [
|
"bitbucket": [
|
||||||
WebhookScreenshotConfig(
|
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": [
|
"bitbucket2": [
|
||||||
WebhookScreenshotConfig(
|
WebhookScreenshotConfig(
|
||||||
"issue_created.json", "003.png", "bitbucket", bot_name="Bitbucket Bot"
|
"issue_created.json",
|
||||||
|
"003.png",
|
||||||
|
"bitbucket",
|
||||||
|
bot_name="Bitbucket Bot",
|
||||||
|
channel="bitbucket",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
"bitbucket3": [
|
"bitbucket3": [
|
||||||
@@ -788,6 +772,7 @@ WEBHOOK_SCREENSHOT_CONFIG: dict[str, list[WebhookScreenshotConfig]] = {
|
|||||||
"004.png",
|
"004.png",
|
||||||
"bitbucket",
|
"bitbucket",
|
||||||
bot_name="Bitbucket Server Bot",
|
bot_name="Bitbucket Server Bot",
|
||||||
|
channel="bitbucket",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
"buildbot": [WebhookScreenshotConfig("started.json")],
|
"buildbot": [WebhookScreenshotConfig("started.json")],
|
||||||
@@ -809,12 +794,12 @@ WEBHOOK_SCREENSHOT_CONFIG: dict[str, list[WebhookScreenshotConfig]] = {
|
|||||||
"freshping": [WebhookScreenshotConfig("freshping_check_unreachable.json")],
|
"freshping": [WebhookScreenshotConfig("freshping_check_unreachable.json")],
|
||||||
"freshstatus": [WebhookScreenshotConfig("freshstatus_incident_open.json")],
|
"freshstatus": [WebhookScreenshotConfig("freshstatus_incident_open.json")],
|
||||||
"front": [WebhookScreenshotConfig("inbound_message.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")],
|
"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")],
|
"gitlab": [WebhookScreenshotConfig("push_hook__push_local_branch_without_commits.json")],
|
||||||
"gocd": [WebhookScreenshotConfig("pipeline_with_mixed_job_result.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")],
|
"gosquared": [WebhookScreenshotConfig("traffic_spike.json")],
|
||||||
"grafana": [WebhookScreenshotConfig("alert_values_v11.json")],
|
"grafana": [WebhookScreenshotConfig("alert_values_v11.json")],
|
||||||
"greenhouse": [WebhookScreenshotConfig("candidate_stage_change.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 = {
|
FIXTURELESS_SCREENSHOT_CONFIG_OPTIONAL_FIELDS = {
|
||||||
"mercurial": {"image_dir": "hg"},
|
"git": {"channel": "commits"},
|
||||||
"jenkins": {"image_name": "004.png"},
|
"github-actions": {"channel": "github-actions updates"},
|
||||||
"google-calendar": {"image_name": "003.png", "image_dir": "google/calendar"},
|
"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():
|
for integration, fields in FIXTURELESS_SCREENSHOT_CONFIG_OPTIONAL_FIELDS.items():
|
||||||
|
|||||||
Reference in New Issue
Block a user