Skip to content

Commit 6939913

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

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

zulip/integrations/hg/zulip_changegroup.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# `hg push`). See https://zulip.com/integrations for installation instructions.
77

88
import sys
9+
from email.utils import parseaddr
910

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

1718

19+
def parse_user(user: str) -> str:
20+
"""
21+
Extract the name from user string, or fall back to email or raw string
22+
if the user string is not in the form "Jane Doe <email@example.com>".
23+
"""
24+
name, email = parseaddr(user)
25+
return name or email or user.strip()
26+
27+
1828
def format_summary_line(
1929
web_url: str, user: str, base: int, tip: int, branch: str, node: str
2030
) -> str:
@@ -23,10 +33,11 @@ def format_summary_line(
2333
information about the changeset and links to the changelog if a
2434
web URL has been configured:
2535
26-
Jane Doe <jane@example.com> pushed 1 commit to default (170:e494a5be3393):
36+
Jane Doe pushed 1 commit to default (170:e494a5be3393):
2737
"""
2838
revcount = tip - base
2939
plural = "s" if revcount > 1 else ""
40+
display_user = parse_user(user)
3041

3142
if web_url:
3243
shortlog_base_url = web_url.rstrip("/") + "/shortlog/"
@@ -35,7 +46,7 @@ def format_summary_line(
3546
else:
3647
formatted_commit_count = f"{revcount} commit{plural}"
3748

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

4051

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

0 commit comments

Comments
 (0)