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.
This commit is contained in:
Shane Kearns 2017-06-19 12:39:07 +01:00 committed by showell
parent 680f453834
commit 99b87dd78d
2 changed files with 14 additions and 1 deletions

View file

@ -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

View file

@ -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.
#