From add4cd27478086a52ee95753fb25d338bcd5dd71 Mon Sep 17 00:00:00 2001 From: Jonathan Teran Carballo Date: Thu, 16 Jul 2026 22:25:20 -0300 Subject: [PATCH] refactor: use base.io_ methods --- src/git_flow/command/base.py | 11 ++++++++++ src/git_flow/command/commit.py | 9 ++------ src/git_flow/command/release.py | 39 ++++++++++++++------------------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/git_flow/command/base.py b/src/git_flow/command/base.py index d2a7c41..398cd1d 100644 --- a/src/git_flow/command/base.py +++ b/src/git_flow/command/base.py @@ -3,6 +3,7 @@ from git_flow import ( REPOSITORY_TOKEN_FILENAME, FLOWCONFIG_FILENAME, FLOWCONFIG_VERSION, + COMMIT_TYPES, GitFlowError, ) from git_flow.git import Git @@ -147,6 +148,16 @@ def is_valid_ticket(ticket: str) -> bool: ) +def get_commit_message(commit_types: list[str] = COMMIT_TYPES) -> str: + commit_type = io_choice("Tipo de commit", commit_types) + commit_message = io_prompt( + "Mensaje de commit", + validator=lambda s: 0 < len(s) and len(s) < 100, + instruction="100 caracteres máximo", + ) + return commit_type + ": " + commit_message + + def io_error(message: str, title: Optional[str] = None): _io_status(message, "✖ Error: ", "red", title) diff --git a/src/git_flow/command/commit.py b/src/git_flow/command/commit.py index abe8a8b..fb49482 100644 --- a/src/git_flow/command/commit.py +++ b/src/git_flow/command/commit.py @@ -20,13 +20,8 @@ def commit(): else: raise GitFlowError("Debe agregar algún cambio al indice para continuar.") - commit_type = base.io_choice("Tipo de commit", COMMIT_TYPES) - commit_message = base.io_prompt( - "Mensaje de commit", - validator=lambda s: 0 < len(s) and len(s) < 100, - instruction="100 caracteres máximo", - ) - message = commit_type + ": " + commit_message + message = base.get_commit_message() + commit_type = message[:message.index(':')] if branch.startswith(WIP_BRANCH_PREFIX): original_branch = branch.removeprefix(WIP_BRANCH_PREFIX) diff --git a/src/git_flow/command/release.py b/src/git_flow/command/release.py index f0402b8..41b6ff4 100644 --- a/src/git_flow/command/release.py +++ b/src/git_flow/command/release.py @@ -1,8 +1,8 @@ from git_flow import COMMIT_TYPES, GitFlowError -from git_flow.command.base import * from git_flow.git import Git from typing import Optional import typer +import git_flow.command.base as base app = typer.Typer() @@ -10,29 +10,29 @@ app = typer.Typer() @app.command() def release(group: Optional[str] = None): """Realiza el merge de la rama, o crea el PR para hacerlo si tiene un remoto configurado""" - ensure_initialized() + base.ensure_initialized() - branch = ensure_right_branch() - env, _ = get_branch_env_and_type(branch) + branch = base.ensure_right_branch() + env, _ = base.get_branch_env_and_type(branch) - if env == environments[-1]: + if env == base.environments[-1]: raise GitFlowError( "No se puede hacer release de una rama en el ultimo entorno." ) - has_remote = "flow.remote" in flowconfig + has_remote = "flow.remote" in base.flowconfig - ensure_clean_worktree(has_remote) + base.ensure_clean_worktree(has_remote) - next_env = environments[environments.index(env) + 1] + next_env = base.environments[base.environments.index(env) + 1] next_branch = ( branch.replace(f"/{env}/", f"/{next_env}/") if branch.startswith("release/") else f"release/{next_env}/{branch}" ) - base = Git.get_first_fork_point(branch, env) - commits = Git("log", base + "..", format="%s").lines() + fork_point = Git.get_first_fork_point(branch, env) + commits = Git("log", fork_point + "..", format="%s").lines() if not commits: raise GitFlowError("No hay cambios a mergear.") @@ -45,9 +45,9 @@ def release(group: Optional[str] = None): grouping = group is not None if not group: - if confirm("¿Desea agrupar este release con otra rama?", False): + if base.io_confirm("¿Desea agrupar este release con otra rama?", False): grouping = True - group = choice( + group = base.io_choice( "Grupo release: ", Git.get_branches("release/" + next_env + "/") ) else: @@ -58,18 +58,13 @@ def release(group: Optional[str] = None): Git("pull").exec(print="Sincronizando cambios la rama objetivo") Git("switch", "-").exec(print="Volviendo a la rama original") - if len(commits) > 1 and confirm( + if len(commits) > 1 and base.io_confirm( f"¿Desea reemplazar los {len(commits)} commits de la rama por uno solo?", False ): - info("Debe ingresar el mensaje del commit a crear.") + base.io_info("Debe ingresar el mensaje del commit a crear.") + message = base.get_commit_message(COMMIT_TYPES[:-1]) - commit_type = choice("Tipo de commit", COMMIT_TYPES[:-1]) - commit_message = prompt( - "Mensaje (máximo recomendado: 100 caracteres)", persistent=True - ) - message = commit_type + ": " + commit_message - - Git("switch", next_branch, base, create=True).exec( + Git("switch", next_branch, fork_point, create=True).exec( print="Creando rama release en base" ) Git("merge", branch, squash=True).exec(print="Squasheando commits en uno solo") @@ -77,7 +72,7 @@ def release(group: Optional[str] = None): else: Git("switch", next_branch, create=True).exec(print="Creando rama release") - status = Git("rebase", base, next_branch, onto=group).code( + status = Git("rebase", fork_point, next_branch, onto=group).code( print="Moviendo cambios hacia el siguiente ambiente" )