6
6
# `hg push`). See https://zulip.com/integrations for installation instructions.
7
7
8
8
import sys
9
+ from email .utils import parseaddr
9
10
10
11
from mercurial import repository as repo
11
12
from mercurial import ui
15
16
VERSION = "0.9"
16
17
17
18
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
+
18
28
def format_summary_line (
19
29
web_url : str , user : str , base : int , tip : int , branch : str , node : str
20
30
) -> str :
@@ -23,10 +33,11 @@ def format_summary_line(
23
33
information about the changeset and links to the changelog if a
24
34
web URL has been configured:
25
35
26
- Jane Doe <jane@example.com> pushed 1 commit to default (170:e494a5be3393):
36
+ Jane Doe pushed 1 commit to default (170:e494a5be3393):
27
37
"""
28
38
revcount = tip - base
29
39
plural = "s" if revcount > 1 else ""
40
+ display_user = parse_user (user )
30
41
31
42
if web_url :
32
43
shortlog_base_url = web_url .rstrip ("/" ) + "/shortlog/"
@@ -35,7 +46,7 @@ def format_summary_line(
35
46
else :
36
47
formatted_commit_count = f"{ revcount } commit{ plural } "
37
48
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 "
39
50
40
51
41
52
def format_commit_lines (web_url : str , repo : repo , base : int , tip : int ) -> str :
0 commit comments