59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
import typer
|
|
|
|
import git_flow.command.base as base
|
|
from git_flow import GitFlowError
|
|
from git_flow.git import Git
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
@app.command()
|
|
def release():
|
|
"""Realiza el merge de la rama, o crea el PR para hacerlo si tiene un remoto configurado"""
|
|
base.ensure_initialized()
|
|
|
|
branch = base.ensure_right_branch()
|
|
env, _ = base.get_branch_env_and_type(branch)
|
|
|
|
if env == base.environments[-1]:
|
|
raise GitFlowError(
|
|
"No se puede hacer release de una rama en el ultimo entorno."
|
|
)
|
|
|
|
has_remote = "flow.remote" in base.flowconfig
|
|
|
|
base.ensure_clean_worktree(has_remote)
|
|
|
|
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}"
|
|
)
|
|
|
|
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.")
|
|
|
|
print("Cambios a pasar al proximo entorno:")
|
|
|
|
for commit in commits:
|
|
print("- " + commit)
|
|
|
|
if has_remote and Git.get_tracking_branch(next_env):
|
|
Git("switch", next_env).exec(print="Cambiando a la rama objetivo")
|
|
Git("pull").exec(print="Sincronizando cambios la rama objetivo")
|
|
Git("switch", "-").exec(print="Volviendo a la rama original")
|
|
|
|
Git("switch", next_branch, create=True).exec(print="Creando rama release")
|
|
|
|
status = Git("rebase", fork_point, next_branch, onto=next_env).code(
|
|
print="Moviendo cambios hacia el siguiente ambiente"
|
|
)
|
|
|
|
if status:
|
|
Git("rebase", abort=True).exec(print="Deshaciendo cambios por conflictos")
|
|
raise GitFlowError("Error al realizar pasaje de cambios a rama objetivo")
|