refactor: migrate from class commands to scripts commands
This commit is contained in:
+37
-40
@@ -1,56 +1,53 @@
|
||||
from argparse import Namespace
|
||||
import typer
|
||||
from git_flow import BRANCH_TYPES
|
||||
from git_flow.command.base import Command
|
||||
from git_flow.command.base import *
|
||||
from git_flow.git import Git
|
||||
|
||||
app = typer.Typer()
|
||||
|
||||
class NewCommand(Command):
|
||||
def name(self) -> str:
|
||||
return "new"
|
||||
|
||||
def description(self) -> str:
|
||||
return """Crea una nueva rama siguiendo conventional branches"""
|
||||
@app.command()
|
||||
def new():
|
||||
"""Crea una nueva rama siguiendo Conventional Branches"""
|
||||
|
||||
def run(self, args: Namespace = Namespace()):
|
||||
self.ensure_initialized()
|
||||
branch = self.ensure_right_branch()
|
||||
envs = self.flowconfig["flow.branches"].split(",")
|
||||
ensure_initialized()
|
||||
branch = ensure_right_branch()
|
||||
envs = flowconfig["flow.branches"].split(",")
|
||||
|
||||
if branch not in envs:
|
||||
self.warning("La rama actual no corresponde a un entorno configurado.")
|
||||
if branch not in envs:
|
||||
warning("La rama actual no corresponde a un entorno configurado.")
|
||||
|
||||
self.info("Se creará una nueva rama de trabajo sobre la rama actual.")
|
||||
self.info("Debe seleccionar el tipo de cambio a realizar.")
|
||||
info("Se creará una nueva rama de trabajo sobre la rama actual.")
|
||||
info("Debe seleccionar el tipo de cambio a realizar.")
|
||||
|
||||
branch_type = self.choice("Tipos de cambio", BRANCH_TYPES)
|
||||
new_branch = self._get_unique_branch_name(branch_type)
|
||||
branch_type = choice("Tipos de cambio", BRANCH_TYPES)
|
||||
new_branch = _get_unique_branch_name(branch_type)
|
||||
|
||||
if "flow.remote" in self.flowconfig and Git.get_tracking_branch(branch):
|
||||
Git("pull").exec(print="Actualizando rama actual")
|
||||
if "flow.remote" in flowconfig and Git.get_tracking_branch(branch):
|
||||
Git("pull").exec(print="Actualizando rama actual")
|
||||
|
||||
if self.confirm(f"¿Crear rama '{new_branch}' sobre la rama actual?"):
|
||||
Git("switch", new_branch, create=True).exec(print="Creando nueva rama")
|
||||
if confirm(f"¿Crear rama '{new_branch}' sobre la rama actual?"):
|
||||
Git("switch", new_branch, create=True).exec(print="Creando nueva rama")
|
||||
|
||||
def _get_unique_branch_name(self, branch_type: str) -> str:
|
||||
self.info(
|
||||
f"Ingrese las palabras clave que describan el cambio de tipo '{branch_type}'."
|
||||
|
||||
def _get_unique_branch_name(branch_type: str) -> str:
|
||||
info(f"Ingrese las palabras clave que describan el cambio de tipo '{branch_type}'.")
|
||||
branch = None
|
||||
branches = Git.get_branches()
|
||||
|
||||
while branch is None:
|
||||
keywords = prompt(
|
||||
"Palabras clave del cambio (por ejemplo: 'create worker form')",
|
||||
persistent=True,
|
||||
)
|
||||
branch = None
|
||||
branches = Git.get_branches()
|
||||
|
||||
while branch is None:
|
||||
keywords = self.prompt(
|
||||
"Palabras clave del cambio (por ejemplo: 'create worker form')",
|
||||
persistent=True,
|
||||
keywords = filter(lambda k: len(k) > 0, keywords.split(" "))
|
||||
branch = branch_type + "/" + "-".join(keywords)
|
||||
|
||||
if branch in branches:
|
||||
error(
|
||||
f"La rama '{branch}' ya existe, cambie las palabras claves para generar otra"
|
||||
)
|
||||
branch = None
|
||||
|
||||
keywords = filter(lambda k: len(k) > 0, keywords.split(" "))
|
||||
branch = branch_type + "/" + "-".join(keywords)
|
||||
|
||||
if branch in branches:
|
||||
self.error(
|
||||
f"La rama '{branch}' ya existe, cambie las palabras claves para generar otra"
|
||||
)
|
||||
branch = None
|
||||
|
||||
return branch
|
||||
return branch
|
||||
|
||||
Reference in New Issue
Block a user