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