refactor: use base.io_ methods

This commit is contained in:
jt
2026-07-16 22:26:48 -03:00
parent add4cd2747
commit 919e680e75
+9 -9
View File
@@ -7,7 +7,7 @@ from git_flow import (
GitFlowError, GitFlowError,
) )
from git_flow.changelog import Changelog from git_flow.changelog import Changelog
from git_flow.command.base import * import git_flow.command.base as base
from git_flow.git import Git from git_flow.git import Git
from typing import Optional from typing import Optional
import typer import typer
@@ -18,22 +18,22 @@ app = typer.Typer()
@app.command() @app.command()
def tag(token: Optional[str] = None): def tag(token: Optional[str] = None):
"""Crea un nuevo tag para el último merge.""" """Crea un nuevo tag para el último merge."""
ensure_initialized() base.ensure_initialized()
target = Git.get_current_branch() target = Git.get_current_branch()
if target not in environments: if target not in base.environments:
raise GitFlowError("Solo se pueden taggear commits en ramas principales.") raise GitFlowError("Solo se pueden taggear commits en ramas principales.")
branch = Git( branch = Git(
"show", get_last_merge_commit() + "^2", patch=False, format="%h" "show", get_last_merge_commit() + "^2", patch=False, format="%h"
).firstline() ).firstline()
base = Git.get_first_fork_point(branch, target) fork_point = Git.get_first_fork_point(branch, target)
commits = Git("log", base + ".." + branch, format="%s").lines() commits = Git("log", fork_point + ".." + branch, format="%s").lines()
next_tag = get_next_tag_from_commits(commits, target) next_tag = get_next_tag_from_commits(commits, target)
if not next_tag: if not next_tag:
info( base.io_info(
"Los cambios realizados no implican un salto de versión, se mantiene la anterior." "Los cambios realizados no implican un salto de versión, se mantiene la anterior."
) )
return return
@@ -45,21 +45,21 @@ def tag(token: Optional[str] = None):
changelog = Changelog() changelog = Changelog()
changelog.update(next_tag, base, branch) changelog.update(next_tag, fork_point, branch)
Git("add", Changelog.FILENAME).exec(print="Agregando nuevo CHANGELOG.md") Git("add", Changelog.FILENAME).exec(print="Agregando nuevo CHANGELOG.md")
Git("commit", message=Changelog.COMMIT_MESSAGE).exec(print="Creando commit") Git("commit", message=Changelog.COMMIT_MESSAGE).exec(print="Creando commit")
tag_commit = Git("show", "HEAD", patch=False, format="%h").firstline() tag_commit = Git("show", "HEAD", patch=False, format="%h").firstline()
if ci: if ci:
Git("push").exec(print="Subiendo commit al remoto para taggearlo") Git("push").exec(print="Subiendo commit al remoto para taggearlo")
success(get_remote_api(token).create_tag(next_tag, tag_commit)) base.io_success(base.get_remote_api(token).create_tag(next_tag, tag_commit))
Git("tag", next_tag, tag_commit).exec(print="Creando tag localmente") Git("tag", next_tag, tag_commit).exec(print="Creando tag localmente")
def get_token_and_ci(token: Optional[str]): def get_token_and_ci(token: Optional[str]):
try: try:
return (ensure_repository_token(), False) return (base.ensure_repository_token(), False)
except GitFlowError: except GitFlowError:
return (token, True) return (token, True)