Skip to content

Commit 29e9d95

Browse files
committed
hg: Display formatted user name.
1 parent 3a2c96e commit 29e9d95

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

zulip/integrations/hg/zulip_changegroup.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# This hook is called when changesets are pushed to the default repository (ie
66
# `hg push`). See https://zulip.com/integrations for installation instructions.
77

8+
import re
89
import sys
910

1011
from mercurial import repository as repo
@@ -15,6 +16,18 @@
1516
VERSION = "0.9"
1617

1718

19+
def parse_user(user: str) -> str:
20+
"""Extract the name from user string, or fall back to email or raw string."""
21+
# Match: "Name <[email protected]>"
22+
match = re.match(r"^(.*)<([^>]+)>$", user)
23+
if match:
24+
name = match.group(1).strip()
25+
email = match.group(2).strip()
26+
return name if name else email
27+
else:
28+
return user.strip()
29+
30+
1831
def format_summary_line(
1932
web_url: str, user: str, base: int, tip: int, branch: str, node: str
2033
) -> str:
@@ -23,10 +36,11 @@ def format_summary_line(
2336
information about the changeset and links to the changelog if a
2437
web URL has been configured:
2538
26-
Jane Doe <[email protected]> pushed 1 commit to default (170:e494a5be3393):
39+
Jane Doe pushed 1 commit to default (170:e494a5be3393):
2740
"""
2841
revcount = tip - base
2942
plural = "s" if revcount > 1 else ""
43+
display_user = parse_user(user)
3044

3145
if web_url:
3246
shortlog_base_url = web_url.rstrip("/") + "/shortlog/"
@@ -35,7 +49,7 @@ def format_summary_line(
3549
else:
3650
formatted_commit_count = f"{revcount} commit{plural}"
3751

38-
return f"**{user}** pushed {formatted_commit_count} to **{branch}** (`{tip}:{node[:12]}`):\n\n"
52+
return f"**{display_user}** pushed {formatted_commit_count} to **{branch}** (`{tip}:{node[:12]}`):\n\n"
3953

4054

4155
def format_commit_lines(web_url: str, repo: repo, base: int, tip: int) -> str:

0 commit comments

Comments
 (0)