bugfix: muevo generacion de CHANGELOG.md a comando tag
This commit is contained in:
+18
-5
@@ -17,7 +17,7 @@ class Status:
|
|||||||
class Git:
|
class Git:
|
||||||
FLOWCONFIG_FILE = ".flowconfig"
|
FLOWCONFIG_FILE = ".flowconfig"
|
||||||
CHANGELOG_FILE = "CHANGELOG.md"
|
CHANGELOG_FILE = "CHANGELOG.md"
|
||||||
UPDATED_CHANGELOG_MSG = "Updated " + CHANGELOG_FILE
|
BUMP_VERSION = "chore: bump version and update CHANGELOG.md [skip ci]"
|
||||||
|
|
||||||
command: list[str]
|
command: list[str]
|
||||||
check_returncode: bool = True
|
check_returncode: bool = True
|
||||||
@@ -38,15 +38,28 @@ class Git:
|
|||||||
def status():
|
def status():
|
||||||
return list(map(Status, Git("status", porcelain=True).lines(False)))
|
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
|
@staticmethod
|
||||||
def _get_references(kind: str):
|
def _get_references(kind: str):
|
||||||
prefix = "refs/" + kind + "/"
|
prefix = "refs/" + kind + "/"
|
||||||
return map(
|
return map(
|
||||||
lambda r: r.removeprefix(prefix),
|
lambda r: r.removeprefix(prefix),
|
||||||
filter(
|
Git("for-each-ref", prefix + "*", format="%(refname)").lines(),
|
||||||
lambda l: l.startswith(prefix),
|
|
||||||
Git("for-each-ref", format="%(refname)").lines(),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, subcommand: str, *args: str, **kwargs: str | int | bool) -> None:
|
def __init__(self, subcommand: str, *args: str, **kwargs: str | int | bool) -> None:
|
||||||
|
|||||||
+15
-25
@@ -269,10 +269,6 @@ def merge_command():
|
|||||||
"y ejecutar nuevamente este comando.")
|
"y ejecutar nuevamente este comando.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if update_changelog(branch, target):
|
|
||||||
Git("add", Git.CHANGELOG_FILE).exec()
|
|
||||||
Git("commit", message=Git.UPDATED_CHANGELOG_MSG).exec()
|
|
||||||
|
|
||||||
if remote:
|
if remote:
|
||||||
Git("push", remote, branch, set_upstream=True).exec()
|
Git("push", remote, branch, set_upstream=True).exec()
|
||||||
url = Git("remote", "get-url", remote).firstline()
|
url = Git("remote", "get-url", remote).firstline()
|
||||||
@@ -379,8 +375,7 @@ def tag_command():
|
|||||||
|
|
||||||
remote = Git.flow_config("flow.remote").firstline()
|
remote = Git.flow_config("flow.remote").firstline()
|
||||||
branch = Git.get_current_branch()
|
branch = Git.get_current_branch()
|
||||||
output = Git("describe", abbrev="0", tags=True).without_checking().firstline()
|
last_version = Git.get_current_tag() or "v1.0.0"
|
||||||
last_version = output if output else "v1.0.0"
|
|
||||||
from_major = 1
|
from_major = 1
|
||||||
until_dash = last_version.index("-") if "-" in last_version else None
|
until_dash = last_version.index("-") if "-" in last_version else None
|
||||||
[major, minor, patch] = map(int, last_version[from_major:until_dash].split("."))
|
[major, minor, patch] = map(int, last_version[from_major:until_dash].split("."))
|
||||||
@@ -408,6 +403,11 @@ def tag_command():
|
|||||||
if url:
|
if url:
|
||||||
[service, repository] = parse_url(url)
|
[service, repository] = parse_url(url)
|
||||||
create_tag(service, repository, token, new_version, commit)
|
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:
|
else:
|
||||||
Git("tag", new_version, commit).exec()
|
Git("tag", new_version, commit).exec()
|
||||||
|
|
||||||
@@ -422,16 +422,8 @@ def release_command():
|
|||||||
if env == env_branches[-1]:
|
if env == env_branches[-1]:
|
||||||
raise RuntimeError("No se puede hacer release de una rama en el ultimo entorno.")
|
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]
|
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}"
|
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()
|
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 = []
|
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:
|
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:
|
if message == Git.UPDATED_CHANGELOG_MSG:
|
||||||
continue
|
continue
|
||||||
@@ -580,12 +575,7 @@ def get_changelog_content_lines(target: str):
|
|||||||
commit_type = message[:index]
|
commit_type = message[:index]
|
||||||
commit_message = message[index+1:]
|
commit_message = message[index+1:]
|
||||||
|
|
||||||
lines.append(f"- **{commit_type}**: {commit_message} ({commit})")
|
lines.append(f"- **{commit_type}**: {commit_message} por [{username}]({email}) ({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})")
|
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
@@ -599,7 +589,7 @@ def get_changelog_footer_lines():
|
|||||||
|
|
||||||
def generate_changelog_entry(branch: str, target: str):
|
def generate_changelog_entry(branch: str, target: str):
|
||||||
entry_lines = get_changelog_header_lines(branch)
|
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()
|
entry_lines += get_changelog_footer_lines()
|
||||||
|
|
||||||
return "\n".join(entry_lines)
|
return "\n".join(entry_lines)
|
||||||
|
|||||||
Reference in New Issue
Block a user