feature: cambio merge y tag para que el changelog se genere al crear un tag nuevo

This commit is contained in:
jt
2025-11-19 20:43:22 -03:00
parent 30c6c36beb
commit be87c2098b
15 changed files with 1036 additions and 233 deletions
+75
View File
@@ -0,0 +1,75 @@
from abc import ABC, abstractmethod
from git_flow import SUPPORTED_REMOTE_APIS, GitFlowError
from git_flow.git import Git
class RemoteAPI(ABC):
def __init__(self, repository: str, token: str) -> None:
self.repository = repository
self.token = token
@staticmethod
def parse(remote: str):
url = Git("remote", "get-url", remote).firstline()
invalid_url_error = GitFlowError(f"La URL del remoto {remote} es inválida: {url}")
url_type = None
if url.startswith("git@"):
url_type = "ssh"
elif url.startswith("https://"):
url_type = "https"
else:
raise invalid_url_error
if url_type == "ssh":
# git@host:user/repo[.git]
at_pos = url.index("@")
colon_pos = url.index(":")
host = url[at_pos+1:colon_pos]
repository = url[colon_pos+1:]
else:
# https://host/user/repo[.git]
host_start = url.index("://") + 3
uri_start = url.index("/", host_start)
host = url[host_start:uri_start]
repository = url[uri_start+1:]
# Esto permite configurar hosts "imaginarios" para permitir el uso de multiples claves ssh
if host.endswith(".bitbucket.org"):
host = "bitbucket.org"
elif host.endswith(".github.com"):
host = "github.com"
if host not in SUPPORTED_REMOTE_APIS:
raise GitFlowError("El host del repositorio remoto es inválido")
repository.removesuffix(".git")
return [host, repository]
@abstractmethod
def create_pull_request(
self,
source: str,
destination: str,
title: str | None = None,
description: str | None = None,
) -> str:
pass
@abstractmethod
def create_tag(self, tag: str, commit: str) -> str:
pass
@abstractmethod
def get_endpoint(self, resource: str) -> str:
pass
def get_headers(self):
return {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer " + self.token,
}
+47
View File
@@ -0,0 +1,47 @@
import requests
from git_flow import GitFlowError
from git_flow.remote.base import RemoteAPI
class BitbucketRemoteAPI(RemoteAPI):
API_ENDPOINT = "https://api.bitbucket.org/2.0/repositories"
def create_pull_request(
self,
source: str,
destination: str,
title: str | None = None,
description: str | None = None,
):
request = requests.post(
self.get_endpoint("/pullrequests"),
headers=self.get_headers(),
json={
"title": title,
"description": description,
"source": {"branch": {"name": source}},
"destination": {"branch": {"name": destination}},
"close_source_branch": True,
},
)
if request.ok:
json = request.json()
return "PR creado exitosamente: " + json["links"]["html"]["href"]
else:
raise GitFlowError("Ocurrió un error al crear el PR: " + request.text)
def create_tag(self, tag: str, commit: str):
response = requests.post(
self.get_endpoint("/refs/tags"),
headers=self.get_headers(),
json={"name": tag, "target": {"hash": commit}},
)
if response.ok:
return "Tag creado exitosamente: " + tag
else:
raise GitFlowError("Ocurrió un error al crear el tag: " + response.text)
def get_endpoint(self, resource: str) -> str:
return f"{BitbucketRemoteAPI.API_ENDPOINT}/{self.repository}/{resource}"
+21
View File
@@ -0,0 +1,21 @@
from git_flow import GitFlowError
from git_flow.remote.base import RemoteAPI
class GithubRemoteAPI(RemoteAPI):
API_ENDPOINT = "https://github.com"
def create_pull_request(
self,
source: str,
destination: str,
title: str | None = None,
description: str | None = None,
) -> str:
raise GitFlowError("not implemented yet!")
def create_tag(self, tag: str, commit: str) -> str:
raise GitFlowError("not implemented yet!")
def get_endpoint(self, resource: str) -> str:
return GithubRemoteAPI.API_ENDPOINT