gpt-5.2 ChatGPT: move git config lookup into core.git query
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / lint-shell (push) Has been cancelled
Mark stable commit / lint-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / lint-shell (push) Has been cancelled
Mark stable commit / lint-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
- Replace inline `git config --get` subprocess usage in release/files.py with core.git.queries.get_config_value() - Keep core.git.run() strict; interpret exit code 1 for missing config keys at the query layer - Export get_config_value via core.git.queries https://chatgpt.com/share/69413aef-9814-800f-a9c3-e98666a4204a
This commit is contained in:
@@ -24,6 +24,8 @@ import tempfile
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
|
from pkgmgr.core.git.queries import get_config_value
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Editor helper for interactive changelog messages
|
# Editor helper for interactive changelog messages
|
||||||
@@ -74,10 +76,7 @@ def _open_editor_for_changelog(initial_message: Optional[str] = None) -> str:
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
lines = [
|
lines = [line for line in content.splitlines() if not line.strip().startswith("#")]
|
||||||
line for line in content.splitlines()
|
|
||||||
if not line.strip().startswith("#")
|
|
||||||
]
|
|
||||||
return "\n".join(lines).strip()
|
return "\n".join(lines).strip()
|
||||||
|
|
||||||
|
|
||||||
@@ -85,6 +84,7 @@ def _open_editor_for_changelog(initial_message: Optional[str] = None) -> str:
|
|||||||
# File update helpers (pyproject + extra packaging + changelog)
|
# File update helpers (pyproject + extra packaging + changelog)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def update_pyproject_version(
|
def update_pyproject_version(
|
||||||
pyproject_path: str,
|
pyproject_path: str,
|
||||||
new_version: str,
|
new_version: str,
|
||||||
@@ -365,24 +365,6 @@ def update_changelog(
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def _get_git_config_value(key: str) -> Optional[str]:
|
|
||||||
"""
|
|
||||||
Try to read a value from `git config --get <key>`.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
result = subprocess.run(
|
|
||||||
["git", "config", "--get", key],
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
check=False,
|
|
||||||
)
|
|
||||||
except Exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
value = result.stdout.strip()
|
|
||||||
return value or None
|
|
||||||
|
|
||||||
|
|
||||||
def _get_debian_author() -> Tuple[str, str]:
|
def _get_debian_author() -> Tuple[str, str]:
|
||||||
"""
|
"""
|
||||||
Determine the maintainer name/email for debian/changelog entries.
|
Determine the maintainer name/email for debian/changelog entries.
|
||||||
@@ -396,9 +378,9 @@ def _get_debian_author() -> Tuple[str, str]:
|
|||||||
email = os.environ.get("GIT_AUTHOR_EMAIL")
|
email = os.environ.get("GIT_AUTHOR_EMAIL")
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
name = _get_git_config_value("user.name")
|
name = get_config_value("user.name")
|
||||||
if not email:
|
if not email:
|
||||||
email = _get_git_config_value("user.email")
|
email = get_config_value("user.email")
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
name = "Unknown Maintainer"
|
name = "Unknown Maintainer"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from .get_remote_push_urls import get_remote_push_urls
|
|||||||
from .probe_remote_reachable import probe_remote_reachable
|
from .probe_remote_reachable import probe_remote_reachable
|
||||||
from .get_changelog import get_changelog, GitChangelogQueryError
|
from .get_changelog import get_changelog, GitChangelogQueryError
|
||||||
from .get_tags_at_ref import get_tags_at_ref, GitTagsAtRefQueryError
|
from .get_tags_at_ref import get_tags_at_ref, GitTagsAtRefQueryError
|
||||||
|
from .get_config_value import get_config_value
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"get_current_branch",
|
"get_current_branch",
|
||||||
@@ -23,4 +24,5 @@ __all__ = [
|
|||||||
"GitChangelogQueryError",
|
"GitChangelogQueryError",
|
||||||
"get_tags_at_ref",
|
"get_tags_at_ref",
|
||||||
"GitTagsAtRefQueryError",
|
"GitTagsAtRefQueryError",
|
||||||
|
"get_config_value",
|
||||||
]
|
]
|
||||||
|
|||||||
34
src/pkgmgr/core/git/queries/get_config_value.py
Normal file
34
src/pkgmgr/core/git/queries/get_config_value.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from ..errors import GitError
|
||||||
|
from ..run import run
|
||||||
|
|
||||||
|
|
||||||
|
def _is_missing_key_error(exc: GitError) -> bool:
|
||||||
|
msg = str(exc).lower()
|
||||||
|
|
||||||
|
# Ensure we only swallow the expected case for THIS command.
|
||||||
|
if "git config --get" not in msg:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# 'git config --get' returns exit code 1 when the key is not set.
|
||||||
|
return "exit code: 1" in msg
|
||||||
|
|
||||||
|
def get_config_value(key: str, *, cwd: str = ".") -> Optional[str]:
|
||||||
|
"""
|
||||||
|
Return a value from `git config --get <key>`, or None if not set.
|
||||||
|
|
||||||
|
We keep core.git.run() strict (check=True) and interpret the known
|
||||||
|
'not set' exit-code case here.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
output = run(["config", "--get", key], cwd=cwd)
|
||||||
|
except GitError as exc:
|
||||||
|
if _is_missing_key_error(exc):
|
||||||
|
return None
|
||||||
|
raise
|
||||||
|
|
||||||
|
output = output.strip()
|
||||||
|
return output or None
|
||||||
Reference in New Issue
Block a user