refactor: use base.io_ methods
This commit is contained in:
@@ -3,6 +3,7 @@ from git_flow import (
|
|||||||
REPOSITORY_TOKEN_FILENAME,
|
REPOSITORY_TOKEN_FILENAME,
|
||||||
FLOWCONFIG_FILENAME,
|
FLOWCONFIG_FILENAME,
|
||||||
FLOWCONFIG_VERSION,
|
FLOWCONFIG_VERSION,
|
||||||
|
COMMIT_TYPES,
|
||||||
GitFlowError,
|
GitFlowError,
|
||||||
)
|
)
|
||||||
from git_flow.git import Git
|
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):
|
def io_error(message: str, title: Optional[str] = None):
|
||||||
_io_status(message, "✖ Error: ", "red", title)
|
_io_status(message, "✖ Error: ", "red", title)
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,8 @@ def commit():
|
|||||||
else:
|
else:
|
||||||
raise GitFlowError("Debe agregar algún cambio al indice para continuar.")
|
raise GitFlowError("Debe agregar algún cambio al indice para continuar.")
|
||||||
|
|
||||||
commit_type = base.io_choice("Tipo de commit", COMMIT_TYPES)
|
message = base.get_commit_message()
|
||||||
commit_message = base.io_prompt(
|
commit_type = message[:message.index(':')]
|
||||||
"Mensaje de commit",
|
|
||||||
validator=lambda s: 0 < len(s) and len(s) < 100,
|
|
||||||
instruction="100 caracteres máximo",
|
|
||||||
)
|
|
||||||
message = commit_type + ": " + commit_message
|
|
||||||
|
|
||||||
if branch.startswith(WIP_BRANCH_PREFIX):
|
if branch.startswith(WIP_BRANCH_PREFIX):
|
||||||
original_branch = branch.removeprefix(WIP_BRANCH_PREFIX)
|
original_branch = branch.removeprefix(WIP_BRANCH_PREFIX)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
from git_flow import COMMIT_TYPES, GitFlowError
|
from git_flow import COMMIT_TYPES, GitFlowError
|
||||||
from git_flow.command.base import *
|
|
||||||
from git_flow.git import Git
|
from git_flow.git import Git
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import typer
|
import typer
|
||||||
|
import git_flow.command.base as base
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
|
||||||
@@ -10,29 +10,29 @@ app = typer.Typer()
|
|||||||
@app.command()
|
@app.command()
|
||||||
def release(group: Optional[str] = None):
|
def release(group: Optional[str] = None):
|
||||||
"""Realiza el merge de la rama, o crea el PR para hacerlo si tiene un remoto configurado"""
|
"""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()
|
branch = base.ensure_right_branch()
|
||||||
env, _ = get_branch_env_and_type(branch)
|
env, _ = base.get_branch_env_and_type(branch)
|
||||||
|
|
||||||
if env == environments[-1]:
|
if env == base.environments[-1]:
|
||||||
raise GitFlowError(
|
raise GitFlowError(
|
||||||
"No se puede hacer release de una rama en el ultimo entorno."
|
"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 = (
|
next_branch = (
|
||||||
branch.replace(f"/{env}/", f"/{next_env}/")
|
branch.replace(f"/{env}/", f"/{next_env}/")
|
||||||
if branch.startswith("release/")
|
if branch.startswith("release/")
|
||||||
else f"release/{next_env}/{branch}"
|
else f"release/{next_env}/{branch}"
|
||||||
)
|
)
|
||||||
|
|
||||||
base = Git.get_first_fork_point(branch, env)
|
fork_point = Git.get_first_fork_point(branch, env)
|
||||||
commits = Git("log", base + "..", format="%s").lines()
|
commits = Git("log", fork_point + "..", format="%s").lines()
|
||||||
|
|
||||||
if not commits:
|
if not commits:
|
||||||
raise GitFlowError("No hay cambios a mergear.")
|
raise GitFlowError("No hay cambios a mergear.")
|
||||||
@@ -45,9 +45,9 @@ def release(group: Optional[str] = None):
|
|||||||
grouping = group is not None
|
grouping = group is not None
|
||||||
|
|
||||||
if not group:
|
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
|
grouping = True
|
||||||
group = choice(
|
group = base.io_choice(
|
||||||
"Grupo release: ", Git.get_branches("release/" + next_env + "/")
|
"Grupo release: ", Git.get_branches("release/" + next_env + "/")
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -58,18 +58,13 @@ def release(group: Optional[str] = None):
|
|||||||
Git("pull").exec(print="Sincronizando cambios la rama objetivo")
|
Git("pull").exec(print="Sincronizando cambios la rama objetivo")
|
||||||
Git("switch", "-").exec(print="Volviendo a la rama original")
|
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
|
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])
|
Git("switch", next_branch, fork_point, create=True).exec(
|
||||||
commit_message = prompt(
|
|
||||||
"Mensaje (máximo recomendado: 100 caracteres)", persistent=True
|
|
||||||
)
|
|
||||||
message = commit_type + ": " + commit_message
|
|
||||||
|
|
||||||
Git("switch", next_branch, base, create=True).exec(
|
|
||||||
print="Creando rama release en base"
|
print="Creando rama release en base"
|
||||||
)
|
)
|
||||||
Git("merge", branch, squash=True).exec(print="Squasheando commits en uno solo")
|
Git("merge", branch, squash=True).exec(print="Squasheando commits en uno solo")
|
||||||
@@ -77,7 +72,7 @@ def release(group: Optional[str] = None):
|
|||||||
else:
|
else:
|
||||||
Git("switch", next_branch, create=True).exec(print="Creando rama release")
|
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"
|
print="Moviendo cambios hacia el siguiente ambiente"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user