From 4bccd20e4544df2f2135b1d24654d804812e224c Mon Sep 17 00:00:00 2001 From: Jonathan Teran Date: Fri, 7 Nov 2025 11:42:24 -0300 Subject: [PATCH] bugfix: muevo generacion de CHANGELOG.md a comando tag --- src/git_flow/git.py | 23 ++++++++++++++++++----- src/git_flow/main.py | 40 +++++++++++++++------------------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/git_flow/git.py b/src/git_flow/git.py index bd8f23d..f9324bb 100644 --- a/src/git_flow/git.py +++ b/src/git_flow/git.py @@ -17,7 +17,7 @@ class Status: class Git: FLOWCONFIG_FILE = ".flowconfig" CHANGELOG_FILE = "CHANGELOG.md" - UPDATED_CHANGELOG_MSG = "Updated " + CHANGELOG_FILE + BUMP_VERSION = "chore: bump version and update CHANGELOG.md [skip ci]" command: list[str] check_returncode: bool = True @@ -38,15 +38,28 @@ class Git: def status(): return list(map(Status, Git("status", porcelain=True).lines(False))) + @staticmethod + def get_current_tag(): + return Git("describe", abbrev="0", tags=True).without_checking().firstline() + + @staticmethod + def get_first_fork_point(branch: str, env: str): + boundary_commits = list(filter( + lambda c: c.startswith("-"), # boundary commits + Git("rev-list", env + "..." + branch, topo_order=True, boundary=True).lines() + )) + + if not boundary_commits: + raise RuntimeError("No se encontro un commit base para realizar el rebase.") + + return boundary_commits[-1].removeprefix("-") + @staticmethod def _get_references(kind: str): prefix = "refs/" + kind + "/" return map( lambda r: r.removeprefix(prefix), - filter( - lambda l: l.startswith(prefix), - Git("for-each-ref", format="%(refname)").lines(), - ), + Git("for-each-ref", prefix + "*", format="%(refname)").lines(), ) def __init__(self, subcommand: str, *args: str, **kwargs: str | int | bool) -> None: diff --git a/src/git_flow/main.py b/src/git_flow/main.py index 3e91884..cb06bb4 100755 --- a/src/git_flow/main.py +++ b/src/git_flow/main.py @@ -269,10 +269,6 @@ def merge_command(): "y ejecutar nuevamente este comando.") return - if update_changelog(branch, target): - Git("add", Git.CHANGELOG_FILE).exec() - Git("commit", message=Git.UPDATED_CHANGELOG_MSG).exec() - if remote: Git("push", remote, branch, set_upstream=True).exec() url = Git("remote", "get-url", remote).firstline() @@ -379,8 +375,7 @@ def tag_command(): remote = Git.flow_config("flow.remote").firstline() branch = Git.get_current_branch() - output = Git("describe", abbrev="0", tags=True).without_checking().firstline() - last_version = output if output else "v1.0.0" + last_version = Git.get_current_tag() or "v1.0.0" from_major = 1 until_dash = last_version.index("-") if "-" in last_version else None [major, minor, patch] = map(int, last_version[from_major:until_dash].split(".")) @@ -408,6 +403,11 @@ def tag_command(): if url: [service, repository] = parse_url(url) create_tag(service, repository, token, new_version, commit) + + if update_changelog(merged_branch, branch): + Git("add", Git.CHANGELOG_FILE).exec() + Git("commit", message=Git.UPDATED_CHANGELOG_MSG).exec() + Git("push").exec() else: Git("tag", new_version, commit).exec() @@ -422,16 +422,8 @@ def release_command(): if env == env_branches[-1]: raise RuntimeError("No se puede hacer release de una rama en el ultimo entorno.") + base = Git.get_first_fork_point(branch, env) next_env = env_branches[env_branches.index(env) + 1] - boundary_commits = list(filter( - lambda c: c.startswith("-"), # boundary commits - Git("rev-list", env + "..." + branch, topo_order=True, boundary=True).lines() - )) - - if not boundary_commits: - raise RuntimeError("No se encontro un commit base para realizar el rebase.") - - base = boundary_commits[-1].removeprefix("-") next_branch = branch.replace(f"/{env}/", f"/{next_env}/") if branch.startswith("release/") else f"release/{next_env}/{branch}" Git("switch", next_branch, create=True).exec() @@ -566,12 +558,15 @@ def get_changelog_header_lines(branch: str): "" ] -def get_changelog_content_lines(target: str): +def get_changelog_content_lines(branch: str, target: str): lines = [] - commits = Git("log", target + "..", first_parent=True, format="%h", merges=False).lines() + base = Git.get_first_fork_point(branch, target) + commits = Git("log", base + ".." + branch, first_parent=True, format="%h", merges=False).lines() for commit in commits: - message = Git("show", commit, no_patch=True, format="%s").firstline() + message = Git("show", commit, patch=False, format="%s").firstline() + email = Git("show", commit, patch=False, format="%ae").firstline() + username = email[:email.index('@')] if message == Git.UPDATED_CHANGELOG_MSG: continue @@ -580,12 +575,7 @@ def get_changelog_content_lines(target: str): commit_type = message[:index] commit_message = message[index+1:] - lines.append(f"- **{commit_type}**: {commit_message} ({commit})") - diff_tree = Git("diff-tree", commit, r=True, commit_id=False, name_status=True).lines() - - for diff in diff_tree: - [status, filename] = diff.split("\t") - lines.append(f"\t- {filename} ({status})") + lines.append(f"- **{commit_type}**: {commit_message} por [{username}]({email}) ({commit})") return lines @@ -599,7 +589,7 @@ def get_changelog_footer_lines(): def generate_changelog_entry(branch: str, target: str): entry_lines = get_changelog_header_lines(branch) - entry_lines += get_changelog_content_lines(target) + entry_lines += get_changelog_content_lines(branch, target) entry_lines += get_changelog_footer_lines() return "\n".join(entry_lines)