From 99b87dd78d031a77bd36f9f18d3fc63209a9439b Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Mon, 19 Jun 2017 12:39:07 +0100 Subject: [PATCH] integrations/perforce: Display changelist ID as a p4web link. The general regex-based linkify in zulip does not allow '@' as the prefix. In any case we know here that it is definitely a changelist number, which is better. Adding P4_WEB="https://p4web.example.com" to the config will enable this behaviour. If P4_WEB is absent from the config, or has the value None, no link is inserted. --- integrations/perforce/zulip_change-commit.py | 11 ++++++++++- integrations/perforce/zulip_perforce_config.py | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/integrations/perforce/zulip_change-commit.py b/integrations/perforce/zulip_change-commit.py index f75eb33..ed1caf5 100755 --- a/integrations/perforce/zulip_change-commit.py +++ b/integrations/perforce/zulip_change-commit.py @@ -76,6 +76,15 @@ if destination is None: # Don't forward the notice anywhere sys.exit(0) +change = metadata["change"] +p4web = None +if hasattr(config, "P4_WEB"): + p4web = config.P4_WEB + +if p4web is not None: + # linkify the change number + change = '[{change}]({p4web}/{change}?ac=10)'.format(p4web=p4web, change=change) + message = """**{user}** committed revision @{change} to `{path}`. ```quote @@ -83,7 +92,7 @@ message = """**{user}** committed revision @{change} to `{path}`. ``` """.format( user=metadata["user"], - change=metadata["change"], + change=change, path=changeroot, desc=metadata["desc"]) # type: str diff --git a/integrations/perforce/zulip_perforce_config.py b/integrations/perforce/zulip_perforce_config.py index 2a4bfeb..2b23920 100644 --- a/integrations/perforce/zulip_perforce_config.py +++ b/integrations/perforce/zulip_perforce_config.py @@ -26,6 +26,10 @@ ZULIP_USER = "p4-bot@example.com" ZULIP_API_KEY = "0123456789abcdef0123456789abcdef" ZULIP_SITE = "https://zulip.example.com" +# Set this to point at a p4web installation to get changelist IDs as links +# P4_WEB = "https://p4web.example.com" +P4_WEB = None + # commit_notice_destination() lets you customize where commit notices # are sent to with the full power of a Python function. #