integrations/perforce: Skip messages for missing streams.
For a large perforce server with many users, this allows projects to opt-in to zulip notifications by creating the stream for the branch to be monitored. Commits to paths for which a stream mapping yields a result, but no stream exists in Zulip, are simply dropped silently. This behaviour is opt-in, by setting the configuration key ZULIP_IGNORE_MISSING_STREAM = True in the zulip_perforce_config.py file.
This commit is contained in:
parent
99b87dd78d
commit
c3d99f6613
|
@ -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"):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue