Skip to content

Commit

Permalink
refactor: simplify code that reads git settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ned Batchelder committed Oct 9, 2023
1 parent 28a5340 commit 4630d8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/scriv/gitinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import click

from .shell import run_command, run_simple_command
from .shell import run_simple_command

logger = logging.getLogger(__name__)

Expand All @@ -19,17 +19,17 @@ def user_nick() -> str:
"""
Get a short name for the current user.
"""
ok, out = run_command("git config --get scriv.user_nick")
if ok:
return out.strip()
nick = git_config("scriv.user_nick")
if nick:
return nick

ok, out = run_command("git config --get github.user")
if ok:
return out.strip()
nick = git_config("github.user")
if nick:
return nick

ok, out = run_command("git config --get user.email")
if ok:
nick = out.partition("@")[0]
email = git_config("user.email")
if email:
nick = email.partition("@")[0]
return nick

return os.getenv("USER", "somebody")
Expand Down
1 change: 0 additions & 1 deletion tests/faker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self, mocker):
"""Make the faker."""
self.handlers: Dict[str, CmdHandler] = {}
self.mocker = mocker
self.patch_module("scriv.gitinfo")
self.patch_module("scriv.shell")

def patch_module(self, mod_name: str) -> None:
Expand Down

0 comments on commit 4630d8c

Please sign in to comment.