Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
542c629489 | ||
|
|
3c271be415 | ||
|
|
c74f1a3093 | ||
|
|
eafb3f1b31 | ||
|
|
82b9a70400 | ||
|
|
6f90a37ba2 | ||
|
|
5a641938c0 |
@@ -1,3 +1,13 @@
|
||||
## v1.4.0 - 2025-11-23
|
||||
|
||||
### Commits
|
||||
|
||||
- **feature**: agrego comando branch para listar ramas [[jonathan.nerat](mailto:jonathan.nerat@gmail.com)] (c74f1a3)
|
||||
- **feature**: agrego soporte para parametros repetidos en llamadas a Git [[jonathan.nerat](mailto:jonathan.nerat@gmail.com)] (eafb3f1)
|
||||
|
||||
---
|
||||
|
||||
|
||||
## v1.3.0 - 2025-11-23
|
||||
|
||||
### Commits
|
||||
|
||||
@@ -7,6 +7,30 @@ Herramienta para establecer un workflow siguiendo [Conventional Commits
|
||||
Esta diseñada para facilitar la creación de commits y branches en un formato estandar, que permite
|
||||
derivar versiones automaticamente de los merges sobre ramas principales.
|
||||
|
||||
## Instalación
|
||||
|
||||
Para instalar Git Flow, se sugiere utilizar [pipx](https://github.com/pypa/pipx) (seguir la
|
||||
documentación para instalarlo). Una vez instalado `pipx`, simplemente clonamos el repositorio en una
|
||||
carpeta local, y lo instalamos:
|
||||
|
||||
```sh
|
||||
cd ~/Downloads
|
||||
git clone git@bitbucket.org:sushi2717/git-flow.git
|
||||
cd git-flow
|
||||
pipx install .
|
||||
```
|
||||
|
||||
Luego podemos verificar que se haya instalado correctamente ejecutando: `git-flow -h`
|
||||
|
||||
Para actualizarlo, hacemos un pull de los cambios recientes del repositorio, y hacemos el upgrade
|
||||
mediante `pipx`:
|
||||
|
||||
```sh
|
||||
cd ~/Downloads/git-flow
|
||||
git pull
|
||||
pipx upgrade git-flow
|
||||
```
|
||||
|
||||
## Configuración
|
||||
|
||||
Para poder usar la herramienta en un repositorio, necesitamos inicializarlo:
|
||||
@@ -22,18 +46,15 @@ El comando solicitará 2 opciones:
|
||||
- **Remoto** (opcional): Nombre del remoto que se usará para crear PRs, y taggear merges
|
||||
automáticamente. Por el momento, se soportan los siguientes remotos:
|
||||
|
||||
- [x] Bitbucket
|
||||
- [ ] Github: planeado
|
||||
- [x] Bitbucket
|
||||
- [ ] Github: planeado
|
||||
|
||||
La configuración del remoto requiere tener un API Token para poder crear los PRs automáticamente.
|
||||
El mismo se puede crear desde: *"Atlassian Account Settings" > "Security" > "Create and Manage API
|
||||
Tokens" > "Create API Tokens with scopes"*. El token necesita el scope `write:pullrequest:bitbucket`
|
||||
|
||||
- `write:repository:bitbucket`
|
||||
|
||||
Luego se debe guardar el token dentro del repositorio a configurar, en el archivo `.repository-token`.
|
||||
|
||||
De no especificarse, los merges y tags se harán de forma local.
|
||||
Luego se debe guardar el token dentro del repositorio a configurar, en el archivo
|
||||
`.repository-token`. De no especificarse, los merges y tags se harán de forma local.
|
||||
|
||||
## Utilización
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
from argparse import ArgumentParser, Namespace
|
||||
from git_flow import GitFlowError
|
||||
from git_flow.command.base import COLOR_GREEN, COLOR_RED, COLOR_RESET, Command
|
||||
from git_flow.git import Git
|
||||
|
||||
|
||||
BRANCH_FORMAT = "%(refname:short)"
|
||||
|
||||
|
||||
class BranchCommand(Command):
|
||||
def name(self) -> str:
|
||||
return "branch"
|
||||
|
||||
def description(self) -> str:
|
||||
return """Lista ramas del repositorio, agrupandolas por entorno objetivo"""
|
||||
|
||||
def setup_parser(self, parser: ArgumentParser) -> ArgumentParser:
|
||||
parser.add_argument(
|
||||
"environment",
|
||||
nargs="?",
|
||||
help="Entorno de las ramas a listar. Puede ser vacio para listar ramas de todos los entornos, un entorno válido, o 'trash' para listar las ramas eliminadas.",
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def run(self, args: Namespace = Namespace()):
|
||||
self.ensure_initialized()
|
||||
|
||||
self.current_branch = Git.get_current_branch()
|
||||
self.environments = self.flowconfig["flow.branches"].split(",")
|
||||
|
||||
if args.environment is None:
|
||||
self.show_all_branches()
|
||||
elif args.environment == "trash":
|
||||
self.show_trash_branches()
|
||||
elif args.environment in self.environments:
|
||||
self.show_env_branches(args.environment)
|
||||
else:
|
||||
raise GitFlowError(f"'{args.environment}' no es un entorno válido.")
|
||||
|
||||
def show_trash_branches(self):
|
||||
branches = self.get_trash_branches()
|
||||
|
||||
for branch in branches:
|
||||
prefix = (COLOR_RED + "*") if branch == self.current_branch else " "
|
||||
print(prefix + " " + branch + COLOR_RESET)
|
||||
|
||||
def get_trash_branches(self):
|
||||
return Git("for-each-ref", "refs/heads/trash/", format=BRANCH_FORMAT).lines()
|
||||
|
||||
def show_all_branches(self):
|
||||
for environment in self.environments:
|
||||
self.show_env_branches(environment)
|
||||
|
||||
trash = len(self.get_trash_branches())
|
||||
print("\nTrash: " + str(trash) + " rama" + ("" if trash == 1 else "s"))
|
||||
|
||||
def show_env_branches(self, environment: str):
|
||||
is_first_env = environment == self.environments[0]
|
||||
branches = (
|
||||
Git(
|
||||
"for-each-ref",
|
||||
"refs/heads/",
|
||||
exclude=["refs/heads/trash/", "refs/heads/release/"],
|
||||
format=BRANCH_FORMAT,
|
||||
).lines()
|
||||
if is_first_env
|
||||
else Git(
|
||||
"for-each-ref",
|
||||
"refs/heads/release/" + environment + "/",
|
||||
format=BRANCH_FORMAT,
|
||||
).lines()
|
||||
)
|
||||
|
||||
for branch in branches:
|
||||
prefix = (COLOR_GREEN + "*") if branch == self.current_branch else " "
|
||||
print(prefix + " " + branch + COLOR_RESET)
|
||||
|
||||
|
||||
+4
-1
@@ -89,7 +89,7 @@ class Git:
|
||||
def is_repository() -> bool:
|
||||
return Git("rev-parse", is_inside_work_tree=True).code() == 0
|
||||
|
||||
def __init__(self, subcommand: str, *args: str, **kwargs: str | int | bool | None) -> None:
|
||||
def __init__(self, subcommand: str, *args: str, **kwargs: str | int | bool | list[str] | None) -> None:
|
||||
self.command = ["git", subcommand]
|
||||
|
||||
for option, value in kwargs.items():
|
||||
@@ -103,6 +103,9 @@ class Git:
|
||||
self.command.append(prefix + option)
|
||||
elif value is None:
|
||||
continue
|
||||
elif isinstance(value, list):
|
||||
for v in value:
|
||||
self.command.append("--" + option + "=" + v)
|
||||
else:
|
||||
value = value if isinstance(value, str) else str(value)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from argparse import Namespace, ArgumentParser
|
||||
|
||||
from git_flow import GitFlowError
|
||||
from git_flow.command.base import Command
|
||||
from git_flow.command.branch import BranchCommand
|
||||
from git_flow.command.commit import CommitCommand
|
||||
from git_flow.command.init import InitCommand
|
||||
from git_flow.command.merge import MergeCommand
|
||||
@@ -70,6 +71,7 @@ def main():
|
||||
MergeCommand(),
|
||||
TagCommand(),
|
||||
ReleaseCommand(),
|
||||
BranchCommand()
|
||||
)
|
||||
try:
|
||||
command.run()
|
||||
|
||||
Reference in New Issue
Block a user