From e87843da7e537f461326cca48e0539f916371d6c Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Tue, 3 Oct 2023 08:35:27 +0200 Subject: [PATCH] address #103: introduce scriv.user_nick setting --- .../20231003_082812_ronny_user_nick_setting.rst | 10 ++++++++++ src/scriv/gitinfo.py | 4 ++++ tests/test_gitinfo.py | 7 ++++++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 changelog.d/20231003_082812_ronny_user_nick_setting.rst diff --git a/changelog.d/20231003_082812_ronny_user_nick_setting.rst b/changelog.d/20231003_082812_ronny_user_nick_setting.rst new file mode 100644 index 0000000..2bffea6 --- /dev/null +++ b/changelog.d/20231003_082812_ronny_user_nick_setting.rst @@ -0,0 +1,10 @@ + +Added +..... + +- consider the git config ``scriv.user_nick`` for the user nick part + of the fragment file - thanks to `Ronny Pfannschmidt `_, fixing `issue 103`_ + + +.. _issue 103: https://github.com/nedbat/scriv/pull/103 +.. _pull 106: https://github.com/nedbat/scriv/pull/106 diff --git a/src/scriv/gitinfo.py b/src/scriv/gitinfo.py index 79b58d5..db58fc0 100644 --- a/src/scriv/gitinfo.py +++ b/src/scriv/gitinfo.py @@ -19,6 +19,10 @@ 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() + ok, out = run_command("git config --get github.user") if ok: return out.strip() diff --git a/tests/test_gitinfo.py b/tests/test_gitinfo.py index f6067b8..621ced8 100644 --- a/tests/test_gitinfo.py +++ b/tests/test_gitinfo.py @@ -5,6 +5,11 @@ from scriv.gitinfo import current_branch_name, get_github_repos, user_nick +def test_user_nick_from_scriv_user_nick(fake_git): + fake_git.set_config("scriv.user_nick", "joedev") + assert user_nick() == "joedev" + + def test_user_nick_from_github(fake_git): fake_git.set_config("github.user", "joedev") assert user_nick() == "joedev" @@ -69,7 +74,7 @@ def test_real_get_github_repos(): # we can't be sure what we get, except it should be word/word, and not end # with .git repos = get_github_repos() - assert len(repos) == 1 + assert len(repos) >= 1 repo = repos.pop() assert re.fullmatch(r"\w+/\w+", repo) assert not repo.endswith(".git")