diff --git a/integrations/perforce/zulip_change-commit.py b/integrations/perforce/zulip_change-commit.py index ed1caf5..71c211d 100755 --- a/integrations/perforce/zulip_change-commit.py +++ b/integrations/perforce/zulip_change-commit.py @@ -72,10 +72,22 @@ except ValueError: metadata = git_p4.p4_describe(changelist) # type: Dict[str, str] destination = config.commit_notice_destination(changeroot, changelist) # type: Optional[Dict[str, str]] + if destination is None: # Don't forward the notice anywhere sys.exit(0) +ignore_missing_stream = None +if hasattr(config, "ZULIP_IGNORE_MISSING_STREAM"): + ignore_missing_stream = config.ZULIP_IGNORE_MISSING_STREAM + +if ignore_missing_stream: + # Check if the destination stream exists yet + stream_state = client.get_stream_id(destination["stream"]) + if stream_state["result"] == "error": + # Silently discard the message + sys.exit(0) + change = metadata["change"] p4web = None if hasattr(config, "P4_WEB"): diff --git a/integrations/perforce/zulip_perforce_config.py b/integrations/perforce/zulip_perforce_config.py index 2b23920..6827cc9 100644 --- a/integrations/perforce/zulip_perforce_config.py +++ b/integrations/perforce/zulip_perforce_config.py @@ -26,6 +26,11 @@ ZULIP_USER = "p4-bot@example.com" ZULIP_API_KEY = "0123456789abcdef0123456789abcdef" ZULIP_SITE = "https://zulip.example.com" +# Set this to True to silently drop messages if the destination stream +# does not exist. This prevents the warnings from Zulip's Notification Bot +# when commits are made on a branch for which no stream has been created. +ZULIP_IGNORE_MISSING_STREAM = False + # Set this to point at a p4web installation to get changelist IDs as links # P4_WEB = "https://p4web.example.com" P4_WEB = None