feature: tag from ci fetches commits from remote api

This commit is contained in:
Jonathan Teran Carballo
2026-09-20 21:05:21 -03:00
parent 889109bf77
commit 26ab81b175
8 changed files with 195 additions and 31 deletions
+30 -1
View File
@@ -1,9 +1,10 @@
from abc import ABC, abstractmethod
import giturlparse
import requests
from git_flow import SUPPORTED_REMOTE_URL_SCHEMAS, GitFlowError
from git_flow.git import Git
from git_flow.git import Commit, Git
class RemoteAPI(ABC):
@@ -65,6 +66,12 @@ class RemoteAPI(ABC):
def create_tag(self, tag: str, commit: str) -> str:
pass
@abstractmethod
def get_merge_commits(self, merge_commit: str) -> list[Commit]:
"""Busca el PR que generó el merge commit y devuelve sus commits (del más nuevo al más
viejo), sin depender del historial local."""
pass
@abstractmethod
def get_endpoint(self, resource: str) -> str:
pass
@@ -75,3 +82,25 @@ class RemoteAPI(ABC):
"Content-Type": "application/json",
"Authorization": "Bearer " + self.token,
}
def get_json(self, url: str, params: dict | None = None):
response = requests.get(url, headers=self.get_headers(), params=params)
if not response.ok:
raise GitFlowError(f"Ocurrió un error al consultar {url}: {response.text}")
return response
def get_all_pages(self, url: str, page_size: int = 50) -> list:
"""Recorre un endpoint paginado por número de página (page / per_page)."""
items: list = []
page = 1
while True:
batch = self.get_json(url, {"page": page, "per_page": page_size}).json()
items += batch
if len(batch) < page_size:
return items
page += 1