Add a more specific function for shas

This commit is contained in:
Philip Sakievich 2025-03-04 14:45:01 -07:00 committed by psakiev
parent c512512b49
commit c713c5567f
3 changed files with 8 additions and 4 deletions

View File

@ -4207,8 +4207,7 @@ def _specs_with_commits(spec):
" does not meet commit syntax requirements." " does not meet commit syntax requirements."
) )
# TODO probably want a more specific function just for sha validation assert vn.is_git_commit_sha(spec.variants["commit"].value), invalid_commit_msg
assert vn.is_git_version(spec.variants["commit"].value), invalid_commit_msg
# Specs with GitVersions # Specs with GitVersions
# - must have a commit variant, or add it here # - must have a commit variant, or add it here

View File

@ -20,6 +20,7 @@
VersionError, VersionError,
VersionLookupError, VersionLookupError,
infinity_versions, infinity_versions,
is_git_commit_sha,
is_git_version, is_git_version,
) )
from .version_types import ( from .version_types import (
@ -58,6 +59,7 @@
"any_version", "any_version",
"from_string", "from_string",
"infinity_versions", "infinity_versions",
"is_git_commit_sha",
"is_git_version", "is_git_version",
"ver", "ver",
] ]

View File

@ -23,11 +23,14 @@
STRING_TO_PRERELEASE = {"alpha": ALPHA, "beta": BETA, "rc": RC, "final": FINAL} STRING_TO_PRERELEASE = {"alpha": ALPHA, "beta": BETA, "rc": RC, "final": FINAL}
def is_git_commit_sha(string: str) -> bool:
return len(string) == 40 and bool(COMMIT_VERSION.match(string))
def is_git_version(string: str) -> bool: def is_git_version(string: str) -> bool:
return ( return (
string.startswith("git.") string.startswith("git.")
or len(string) == 40 or is_git_commit_sha(string)
and bool(COMMIT_VERSION.match(string))
or "=" in string[1:] or "=" in string[1:]
) )