Skip to content

hg: Display formatted user name. #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions zulip/integrations/hg/zulip_changegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# `hg push`). See https://zulip.com/integrations for installation instructions.

import sys
from email.utils import parseaddr

from mercurial import repository as repo
from mercurial import ui
Expand All @@ -15,6 +16,15 @@
VERSION = "0.9"


def parse_user(user: str) -> str:
"""
Extract the name from user string, or fall back to email or raw string
if the user string is not in the form "Jane Doe <[email protected]>".
"""
name, email = parseaddr(user)
return name or email or user.strip()


def format_summary_line(
web_url: str, user: str, base: int, tip: int, branch: str, node: str
) -> str:
Expand All @@ -23,10 +33,11 @@ def format_summary_line(
information about the changeset and links to the changelog if a
web URL has been configured:
Jane Doe <[email protected]> pushed 1 commit to default (170:e494a5be3393):
Jane Doe pushed 1 commit to default (170:e494a5be3393):
"""
revcount = tip - base
plural = "s" if revcount > 1 else ""
display_user = parse_user(user)

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

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


def format_commit_lines(web_url: str, repo: repo, base: int, tip: int) -> str:
Expand Down
Loading