fix: use prior tag before target version when version tag exists
This commit is contained in:
1 parent
e188bd69ba
commit
7867db3f2a
2 files changed
+21
-7
No files matched your search
@@ -41,7 +41,15 @@ def run_git(args):
|
||||
return 1, "", str(e)
|
||||
|
||||
|
||||
def find_previous_tag(to_ref, tag_pattern):
|
||||
def find_previous_tag(to_ref, tag_pattern, version=""):
|
||||
# 0. If a target version is provided (e.g. 1.8.0), check if tag v$VERSION already exists.
|
||||
# If it does, the commits for this release start from the tag BEFORE v$VERSION:
|
||||
if version:
|
||||
target_tag = version if version.startswith("v") else f"v{version}"
|
||||
code_prev, prev_tag, _ = run_git(["describe", "--tags", f"--match={tag_pattern}", "--abbrev=0", f"{target_tag}^"])
|
||||
if code_prev == 0 and prev_tag:
|
||||
return prev_tag
|
||||
|
||||
# 1. Check if to_ref itself is tagged with an exact tag matching tag_pattern:
|
||||
if tag_pattern:
|
||||
code, stdout, _ = run_git(["describe", "--tags", f"--match={tag_pattern}", "--exact-match", to_ref])
|
||||
@@ -72,12 +80,12 @@ def find_previous_tag(to_ref, tag_pattern):
|
||||
return None
|
||||
|
||||
|
||||
def collect_commits(from_ref, to_ref, tag_pattern, max_commits):
|
||||
def collect_commits(from_ref, to_ref, tag_pattern, max_commits, version=""):
|
||||
# Ensure tags are up-to-date
|
||||
run_git(["fetch", "--tags", "--prune"])
|
||||
|
||||
if not from_ref:
|
||||
from_ref = find_previous_tag(to_ref, tag_pattern)
|
||||
from_ref = find_previous_tag(to_ref, tag_pattern, version)
|
||||
|
||||
commits = ""
|
||||
if from_ref:
|
||||
@@ -179,7 +187,7 @@ def query_llm(args, commits_text):
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
commits = collect_commits(args.from_ref, args.to_ref, args.tag_pattern, args.max_commits)
|
||||
commits = collect_commits(args.from_ref, args.to_ref, args.tag_pattern, args.max_commits, args.version)
|
||||
|
||||
if not commits:
|
||||
sys.stderr.write("[action-release-notes] No commits discovered; using fallback release notes.\n")
|
||||
|
||||
Reference in new issue
Block a user