From 29ebbcebfe0e194f24301b17d9ef60231c2f3504 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 | 14 ++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) 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..eabead4 --- /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 999: https://github.com/nedbat/scriv/pull/ 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..03e4812 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,8 @@ 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 - repo = repos.pop() - assert re.fullmatch(r"\w+/\w+", repo) - assert not repo.endswith(".git") + assert len(repos) >= 1 + for repo in repos: + + assert re.fullmatch(r"\w+/\w+", repo) + assert not repo.endswith(".git")