diff --git a/changelog.d/20240608_184756_dickinsm.rst b/changelog.d/20240608_184756_dickinsm.rst new file mode 100644 index 0000000..bbd7770 --- /dev/null +++ b/changelog.d/20240608_184756_dickinsm.rst @@ -0,0 +1,35 @@ +.. A new scriv changelog fragment. +.. +.. Uncomment the header that is right (remove the leading dots). +.. +.. Removed +.. ....... +.. +.. - A bullet item for the Removed category. +.. +.. Added +.. ..... +.. +.. - A bullet item for the Added category. +.. +.. Changed +.. ....... +.. +.. - A bullet item for the Changed category. +.. +.. Deprecated +.. .......... +.. +.. - A bullet item for the Deprecated category. +.. +Fixed +..... + +- Replaced the invalid GitHub config key ``scriv.user_nick`` with + ``scriv.userNick``. +.. +.. Security +.. ........ +.. +.. - A bullet item for the Security category. +.. diff --git a/docs/configuration.rst b/docs/configuration.rst index 3fcc8dc..0ac9cf4 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -417,7 +417,7 @@ User Nickname Scriv includes your git or GitHub username in the file names of changelog fragments you create. If you don't like the name it finds for you, you can set -a name as the ``scriv.user_nick`` git setting. +a name as the ``scriv.userNick`` git setting. .. _git config: https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration diff --git a/src/scriv/gitinfo.py b/src/scriv/gitinfo.py index 74bce54..1377dd7 100644 --- a/src/scriv/gitinfo.py +++ b/src/scriv/gitinfo.py @@ -19,7 +19,7 @@ def user_nick() -> str: """ Get a short name for the current user. """ - nick = git_config("scriv.user_nick") + nick = git_config("scriv.userNick") if nick: return nick diff --git a/tests/faker.py b/tests/faker.py index b0657a1..6a63a13 100644 --- a/tests/faker.py +++ b/tests/faker.py @@ -1,5 +1,6 @@ """Fake implementations of some of our external information sources.""" +import re import shlex from typing import Callable, Dict, Iterable, List, Optional, Set, Tuple @@ -8,6 +9,9 @@ # A function that simulates run_command. CmdHandler = Callable[[List[str]], CmdResult] +# A regex to help with catching some (but not all) invalid Git config keys. +GIT_CONFIG_KEY = re.compile(r".*\.[a-zA-Z][a-zA-Z0-9-]*") + class FakeRunCommand: """ @@ -87,6 +91,8 @@ def run_command(self, argv: List[str]) -> CmdResult: def set_config(self, name: str, value: str) -> None: """Set a fake Git configuration value.""" + if GIT_CONFIG_KEY.fullmatch(name) is None: + raise ValueError(f"error: invalid key: {name}") self.config[name] = value def set_branch(self, branch_name: str) -> None: diff --git a/tests/test_gitinfo.py b/tests/test_gitinfo.py index 621ced8..ee1b6e4 100644 --- a/tests/test_gitinfo.py +++ b/tests/test_gitinfo.py @@ -6,7 +6,7 @@ def test_user_nick_from_scriv_user_nick(fake_git): - fake_git.set_config("scriv.user_nick", "joedev") + fake_git.set_config("scriv.userNick", "joedev") assert user_nick() == "joedev"