Compare commits

..
22 Commits
Author SHA1 Message Date
bitbucket-pipelines 9b0d7d6166 chore: bump version and update CHANGELOG.md [skip ci] 2026-05-22 19:20:02 +00:00
JonathanGitFlowandjt f52edf03e0 Merged in bugfix/prevent-close-branch-on-environment-merges (pull request #75)
bugfix: dont close branches on merges between environments

Approved-by: Jonathan Teran
2026-05-22 19:19:30 +00:00
Jonathan Teran 8ee01290ef bugfix: dont close branches on merges between environments 2026-05-22 16:18:56 -03:00
bitbucket-pipelines 9c89f4d638 chore: bump version and update CHANGELOG.md [skip ci] 2026-05-22 19:14:59 +00:00
JonathanGitFlowandjt 8d35610c00 Merged in bugfix/customize-pr-title-on-environment-merges (pull request #74)
bugfix: change pr title on merges between environments

Approved-by: Jonathan Teran
2026-05-22 19:14:19 +00:00
Jonathan Teran de124baf1a bugfix: change pr title on merges between environments 2026-05-22 16:13:39 -03:00
bitbucket-pipelines 2676f41def chore: bump version and update CHANGELOG.md [skip ci] 2026-05-20 20:14:50 +00:00
JonathanGitFlowandjt 22fd68c5b6 Merged in bugfix/dont-push-environment-branches-on-merge (pull request #73)
bugfix: dont push environment branches since they are already created on remote

Approved-by: Jonathan Teran
2026-05-20 20:14:08 +00:00
jt 04c9a4b449 bugfix: dont push environment branches since they are already created on remote 2026-05-20 17:13:34 -03:00
JonathanGitFlowandjt 417021b36e Merged in refactor/unify-flow-environments-usage (pull request #72)
refactor: unify flow branches usage

Approved-by: Jonathan Teran
2026-05-20 20:12:26 +00:00
jt be245114d5 refactor: unify flow branches usage 2026-05-20 17:10:58 -03:00
bitbucket-pipelines 184b135886 chore: bump version and update CHANGELOG.md [skip ci] 2026-05-20 20:01:41 +00:00
JonathanGitFlowandjt acc0e8666a Merged in feature/allow-environment-merges (pull request #71)
feature: allow merges between environments

Approved-by: Jonathan Teran
2026-05-20 20:00:57 +00:00
jt 5806aeab27 feature: allow merges between environments 2026-05-20 17:00:20 -03:00
bitbucket-pipelines 23eb9df482 chore: bump version and update CHANGELOG.md [skip ci] 2026-05-20 12:20:37 +00:00
JonathanGitFlowandjt 538c9130dc Merged in bugfix/pr-title-getter (pull request #70)
bugfix: arreglo split de branch para armar correctamente el titulo del PR

Approved-by: Jonathan Teran
2026-05-20 12:19:58 +00:00
Jonathan Teran Carballo a0d3028904 bugfix: arreglo split de branch para armar correctamente el titulo del PR 2026-05-20 09:19:24 -03:00
bitbucket-pipelines 59b9e1c419 chore: bump version and update CHANGELOG.md [skip ci] 2026-05-20 02:30:52 +00:00
JonathanGitFlowandjt 8793248dbe Merged in feature/add-ticket-support (pull request #69)
feature: agrego soporte para especificar tickets en nombre e rama

Approved-by: Jonathan Teran
2026-05-20 02:30:18 +00:00
jt f389118515 feature: agrego soporte para especificar tickets en nombre e rama 2026-05-19 23:29:22 -03:00
JonathanGitFlowandjt 5a7ed03801 Merged in refactor/move-constants-to-git_flow (pull request #68)
refactor: move constants to git_flow module

Approved-by: Jonathan Teran
2026-05-17 14:48:46 +00:00
Jonathan Teran Carballo 5f7db6cf5d refactor: move constants to git_flow module 2026-05-17 11:48:02 -03:00
13 changed files with 144 additions and 48 deletions
+42
View File
@@ -1,3 +1,45 @@
## v1.17.3 - 2026-05-22
- **bugfix**: dont close branches on merges between environments [[jteran](mailto:jteran@renatre.org.ar)] (8ee0129)
---
## v1.17.2 - 2026-05-22
- **bugfix**: change pr title on merges between environments [[jteran](mailto:jteran@renatre.org.ar)] (de124ba)
---
## v1.17.1 - 2026-05-20
- **bugfix**: dont push environment branches since they are already created on remote [[jonathan.nerat](mailto:jonathan.nerat@gmail.com)] (04c9a4b)
---
## v1.17.0 - 2026-05-20
- **feature**: allow merges between environments [[jonathan.nerat](mailto:jonathan.nerat@gmail.com)] (5806aea)
---
## v1.16.1 - 2026-05-20
- **bugfix**: arreglo split de branch para armar correctamente el titulo del PR [[jteran](mailto:jteran@renatre.org.ar)] (a0d3028)
---
## v1.16.0 - 2026-05-20
- **feature**: agrego soporte para especificar tickets en nombre e rama [[jonathan.nerat](mailto:jonathan.nerat@gmail.com)] (f389118)
---
## v1.15.0 - 2026-05-17 ## v1.15.0 - 2026-05-17
- **feature**: include revlist count in version tag when skipping bump [[jonathan.nerat](mailto:jonathan.nerat@gmail.com)] (d275ac0) - **feature**: include revlist count in version tag when skipping bump [[jonathan.nerat](mailto:jonathan.nerat@gmail.com)] (d275ac0)
+2
View File
@@ -49,3 +49,5 @@ SUPPORTED_REMOTE_APIS = [
] ]
REPOSITORY_TOKEN_FILENAME = ".repository-token" REPOSITORY_TOKEN_FILENAME = ".repository-token"
FLOWCONFIG_FILENAME = ".flowconfig"
+19 -7
View File
@@ -1,9 +1,10 @@
from git_flow import ( from git_flow import (
BRANCH_TYPES, BRANCH_TYPES,
REPOSITORY_TOKEN_FILENAME, REPOSITORY_TOKEN_FILENAME,
FLOWCONFIG_FILENAME,
GitFlowError, GitFlowError,
) )
from git_flow.git import FLOWCONFIG_FILE, Git from git_flow.git import Git
from git_flow.remote.base import RemoteAPI from git_flow.remote.base import RemoteAPI
from git_flow.remote.bitbucket import BitbucketRemoteAPI from git_flow.remote.bitbucket import BitbucketRemoteAPI
from git_flow.remote.github import GithubRemoteAPI from git_flow.remote.github import GithubRemoteAPI
@@ -16,8 +17,8 @@ TYPE_ERROR = 2
TYPE_INFO = 3 TYPE_INFO = 3
flowconfig = Git.get_config(FLOWCONFIG_FILE) if isfile(FLOWCONFIG_FILE) else {} flowconfig = Git.get_config(FLOWCONFIG_FILENAME) if isfile(FLOWCONFIG_FILENAME) else {}
environments = flowconfig["flow.branches"].split(",") if "flow.branches" in flowconfig else []
def ensure_initialized(): def ensure_initialized():
initialized = flowconfig["flow.initialized"] if flowconfig else None initialized = flowconfig["flow.initialized"] if flowconfig else None
@@ -45,7 +46,6 @@ def ensure_right_branch():
def get_branch_env_and_type(branch: str) -> tuple[str, str]: def get_branch_env_and_type(branch: str) -> tuple[str, str]:
components = branch.split("/") components = branch.split("/")
target_branches = flowconfig["flow.branches"].split(",")
if len(components) == 2: if len(components) == 2:
if components[0] not in BRANCH_TYPES: if components[0] not in BRANCH_TYPES:
@@ -53,13 +53,13 @@ def get_branch_env_and_type(branch: str) -> tuple[str, str]:
f"Branch inválida, el tipo '{components[0]}' no es válido." f"Branch inválida, el tipo '{components[0]}' no es válido."
) )
return (target_branches[0], components[0]) return (environments[0], components[0])
elif len(components) == 4: elif len(components) == 4:
target_branches = target_branches[1:] valid_environments = environments[1:]
if ( if (
components[0] != "release" components[0] != "release"
or components[1] not in target_branches or components[1] not in valid_environments
or components[2] not in BRANCH_TYPES or components[2] not in BRANCH_TYPES
): ):
raise GitFlowError( raise GitFlowError(
@@ -112,3 +112,15 @@ def get_remote_api(token: str) -> RemoteAPI:
return GithubRemoteAPI(repository, token) return GithubRemoteAPI(repository, token)
else: else:
raise GitFlowError("El host del repositorio remoto es inválido") raise GitFlowError("El host del repositorio remoto es inválido")
def is_valid_ticket(ticket: str) -> bool:
"""Check if the specified string is a valid ticket number (ABC-123)"""
components = ticket.split("-")
if len(components) != 2:
return False
ticket_project = components[0]
ticket_number = components[1]
return ticket_project.isalpha() and ticket_project.isupper() and ticket_number.isnumeric()
-1
View File
@@ -41,7 +41,6 @@ def branch(
ensure_initialized() ensure_initialized()
current_branch = Git.get_current_branch() current_branch = Git.get_current_branch()
environments = flowconfig["flow.branches"].split(",")
if current_branch in environments: if current_branch in environments:
current_environment = current_branch current_environment = current_branch
+4 -5
View File
@@ -1,7 +1,7 @@
import typer import typer
from git_flow import GitFlowError from git_flow import FLOWCONFIG_FILENAME, GitFlowError
from git_flow.git import FLOWCONFIG_FILE, Git from git_flow.git import Git
from git_flow.command.base import * from git_flow.command.base import *
app = typer.Typer() app = typer.Typer()
@@ -25,8 +25,8 @@ def init():
if remote: if remote:
flowconfig["flow.remote"] = remote flowconfig["flow.remote"] = remote
Git.set_config(flowconfig, FLOWCONFIG_FILE) Git.set_config(flowconfig, FLOWCONFIG_FILENAME)
Git("add", FLOWCONFIG_FILE).exec() Git("add", FLOWCONFIG_FILENAME).exec()
Git("commit", message="feature: initialize git-flow").exec() Git("commit", message="feature: initialize git-flow").exec()
_ensure_all_flow_branches_exist(branches, remote) _ensure_all_flow_branches_exist(branches, remote)
@@ -43,7 +43,6 @@ def _ensure_is_repository():
def _ensure_not_already_initialized(): def _ensure_not_already_initialized():
flowconfig = get_config()
if not flowconfig: if not flowconfig:
return return
elif flowconfig.get("flow.initialized") == "true": elif flowconfig.get("flow.initialized") == "true":
+48 -13
View File
@@ -13,6 +13,21 @@ def merge():
ensure_initialized() ensure_initialized()
branch = ensure_right_branch() branch = ensure_right_branch()
if branch in environments:
if branch == environments[-1]:
raise GitFlowError("No se puede hacer un merge del último entorno.")
panel(
"Merge de entornos",
"""Está por hacer un merge de 2 entornos que puede implicar muchos cambios en el proyecto.""",
)
if not confirm("¿Desea continuar?"):
raise GitFlowError("Ejecución abortada")
target = environments[environments.index(branch) + 1]
else:
target, _ = get_branch_env_and_type(branch) target, _ = get_branch_env_and_type(branch)
if "flow.remote" in flowconfig: if "flow.remote" in flowconfig:
@@ -34,6 +49,7 @@ def run_remote(remote: str, token: str, branch: str, target: str):
show_commits_to_merge(target) show_commits_to_merge(target)
if confirm(f"¿Crear PR de '{branch}' a '{target}'?"): if confirm(f"¿Crear PR de '{branch}' a '{target}'?"):
if branch not in environments:
Git("push", remote, branch, set_upstream=True).exec( Git("push", remote, branch, set_upstream=True).exec(
print="Subiendo rama al remoto para crear PR" print="Subiendo rama al remoto para crear PR"
) )
@@ -83,27 +99,19 @@ def check_merge_conflicts(target: str):
def create_pull_request(token: str, branch: str, target: str): def create_pull_request(token: str, branch: str, target: str):
changelog = Changelog() changelog = Changelog()
commits = Git("log", target + "..", format="%s").lines() commits = Git("log", target + "..", format="%s").lines()
title = commits[0] if len(commits) == 1 else _get_pr_title_from_branch(branch)
if len(commits) == 1: panel("Título del PR", title)
title = commits[0]
else:
title = branch.replace("/", ": ").replace("-", " ")
if title.startswith("release: "): if confirm("¿Desea cambiar el título del PR?", False):
title = title[title.index(" ", title.index(" ") + 1) + 1 :] title = prompt("Título del PR")
info("Título del PR por defecto: " + title)
opt_title = prompt("[Opcional] Ingrese otro titulo para el PR")
if opt_title:
title = opt_title
message = get_remote_api(token).create_pull_request( message = get_remote_api(token).create_pull_request(
branch, branch,
target, target,
title, title,
changelog.generate_content(target, branch), changelog.generate_content(target, branch),
branch not in environments
) )
success(message) success(message)
@@ -111,3 +119,30 @@ def create_pull_request(token: str, branch: str, target: str):
if confirm("¿Desea cambiar a la rama objetivo y bajar los cambios?"): if confirm("¿Desea cambiar a la rama objetivo y bajar los cambios?"):
Git("switch", target).exec(print="Cambiando a rama objetivo") Git("switch", target).exec(print="Cambiando a rama objetivo")
Git("pull").exec(print="Obteniendo cambios") Git("pull").exec(print="Obteniendo cambios")
def _get_pr_title_from_branch(branch: str) -> str:
if branch in environments:
target = environments[environments.index(branch) + 1]
return f"Sincronización de entorno {branch} a {target}"
components = branch.split("/") # <type>/<desc> or release/<env>/<type>/<desc>
branch_type = components[-2]
branch_desc = components[-1]
# detect if branch description has ticket as prefix: <desc> = ABC-123-my-branch-name
branch_ticket = None
first_dash = branch_desc.find("-")
second_dash = branch_desc.find("-", first_dash + 1)
if first_dash >= 0 and second_dash >= 0:
maybe_ticket = branch_desc[:second_dash]
if is_valid_ticket(maybe_ticket):
branch_ticket = maybe_ticket
branch_desc = branch_desc[:second_dash+1]
return " ".join(filter(None, [
f"[Pasaje a {components[1]}]" if len(components) == 4 else None,
branch_type + ":",
branch_ticket,
branch_desc.replace("-", " ")
]))
+16 -5
View File
@@ -2,6 +2,7 @@ import typer
from git_flow import BRANCH_TYPES from git_flow import BRANCH_TYPES
from git_flow.command.base import * from git_flow.command.base import *
from git_flow.git import Git from git_flow.git import Git
from typing import Optional
app = typer.Typer() app = typer.Typer()
@@ -12,16 +13,16 @@ def new():
ensure_initialized() ensure_initialized()
branch = ensure_right_branch() branch = ensure_right_branch()
envs = flowconfig["flow.branches"].split(",")
if branch not in envs: if branch not in environments:
warning("La rama actual no corresponde a un entorno configurado.") warning("La rama actual no corresponde a un entorno configurado.")
info("Se creará una nueva rama de trabajo sobre la rama actual.") info("Se creará una nueva rama de trabajo sobre la rama actual.")
info("Debe seleccionar el tipo de cambio a realizar.") info("Debe seleccionar el tipo de cambio a realizar.")
branch_type = choice("Tipos de cambio", BRANCH_TYPES) branch_type = choice("Tipos de cambio", BRANCH_TYPES)
new_branch = _get_unique_branch_name(branch_type) ticket = _get_optional_ticket()
new_branch = _get_unique_branch_name(branch_type, ticket)
if "flow.remote" in flowconfig and Git.get_tracking_branch(branch): if "flow.remote" in flowconfig and Git.get_tracking_branch(branch):
Git("pull").exec(print="Actualizando rama actual") Git("pull").exec(print="Actualizando rama actual")
@@ -29,8 +30,18 @@ def new():
if confirm(f"¿Crear rama '{new_branch}' sobre la rama actual?"): if confirm(f"¿Crear rama '{new_branch}' sobre la rama actual?"):
Git("switch", new_branch, create=True).exec(print="Creando nueva rama") Git("switch", new_branch, create=True).exec(print="Creando nueva rama")
def _get_optional_ticket() -> Optional[str]:
ticket = prompt("[Opcional] Ticket que respalda el cambio (en formato ABC-123)")
def _get_unique_branch_name(branch_type: str) -> str: if not ticket:
return None
if not is_valid_ticket(ticket):
warning("Formato de ticket inválido, ignorando.")
return None
return ticket
def _get_unique_branch_name(branch_type: str, ticket: Optional[str]) -> str:
info(f"Ingrese las palabras clave que describan el cambio de tipo '{branch_type}'.") info(f"Ingrese las palabras clave que describan el cambio de tipo '{branch_type}'.")
branch = None branch = None
branches = Git.get_branches() branches = Git.get_branches()
@@ -42,7 +53,7 @@ def _get_unique_branch_name(branch_type: str) -> str:
) )
keywords = filter(lambda k: len(k) > 0, keywords.split(" ")) keywords = filter(lambda k: len(k) > 0, keywords.split(" "))
branch = branch_type + "/" + "-".join(keywords) branch = branch_type + "/" + (ticket + "-" if ticket else "") + "-".join(keywords)
if branch in branches: if branch in branches:
error( error(
+2 -3
View File
@@ -13,10 +13,9 @@ def release(group: Optional[str] = None):
ensure_initialized() ensure_initialized()
branch = ensure_right_branch() branch = ensure_right_branch()
envs = flowconfig["flow.branches"].split(",")
env, _ = get_branch_env_and_type(branch) env, _ = get_branch_env_and_type(branch)
if env == envs[-1]: if env == 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."
) )
@@ -25,7 +24,7 @@ def release(group: Optional[str] = None):
ensure_clean_worktree(has_remote) ensure_clean_worktree(has_remote)
next_env = envs[envs.index(env) + 1] next_env = environments[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/")
+1 -2
View File
@@ -20,10 +20,9 @@ def tag(token: Optional[str] = None):
"""Crea un nuevo tag para el último merge.""" """Crea un nuevo tag para el último merge."""
ensure_initialized() ensure_initialized()
envs = flowconfig["flow.branches"].split(",")
target = Git.get_current_branch() target = Git.get_current_branch()
if target not in envs: if target not in environments:
raise GitFlowError("Solo se pueden taggear commits en ramas principales.") raise GitFlowError("Solo se pueden taggear commits en ramas principales.")
branch = Git( branch = Git(
+2 -7
View File
@@ -1,13 +1,8 @@
import subprocess import subprocess
from git_flow import FLOWCONFIG_FILENAME
from git_flow.io import * from git_flow.io import *
FLOWCONFIG_FILE = ".flowconfig"
CHANGELOG_FILE = "CHANGELOG.md"
BUMP_VERSION = "chore: bump version and update CHANGELOG.md [skip ci]"
class Git: class Git:
class Status: class Status:
@@ -42,7 +37,7 @@ class Git:
@staticmethod @staticmethod
def flow_config(*args, **kwargs): def flow_config(*args, **kwargs):
return Git("config", *args, file=FLOWCONFIG_FILE, **kwargs) return Git("config", *args, file=FLOWCONFIG_FILENAME, **kwargs)
@staticmethod @staticmethod
def get_current_branch(): def get_current_branch():
+1
View File
@@ -56,6 +56,7 @@ class RemoteAPI(ABC):
destination: str, destination: str,
title: str | None = None, title: str | None = None,
description: str | None = None, description: str | None = None,
close_source_branch: bool = True
) -> str: ) -> str:
pass pass
+2 -1
View File
@@ -12,6 +12,7 @@ class BitbucketRemoteAPI(RemoteAPI):
destination: str, destination: str,
title: str | None = None, title: str | None = None,
description: str | None = None, description: str | None = None,
close_source_branch: bool = True
): ):
request = requests.post( request = requests.post(
self.get_endpoint("/pullrequests"), self.get_endpoint("/pullrequests"),
@@ -21,7 +22,7 @@ class BitbucketRemoteAPI(RemoteAPI):
"description": description, "description": description,
"source": {"branch": {"name": source}}, "source": {"branch": {"name": source}},
"destination": {"branch": {"name": destination}}, "destination": {"branch": {"name": destination}},
"close_source_branch": True, "close_source_branch": close_source_branch,
}, },
) )
+1
View File
@@ -11,6 +11,7 @@ class GithubRemoteAPI(RemoteAPI):
destination: str, destination: str,
title: str | None = None, title: str | None = None,
description: str | None = None, description: str | None = None,
close_source_branch: bool = True
) -> str: ) -> str:
raise GitFlowError("not implemented yet!") raise GitFlowError("not implemented yet!")