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
+23
View File
@@ -2,6 +2,7 @@ from urllib.parse import quote
import requests
from git_flow import GitFlowError
from git_flow.git import Commit
from git_flow.remote.base import RemoteAPI
@@ -47,6 +48,28 @@ class GitlabRemoteAPI(RemoteAPI):
else:
raise GitFlowError("Ocurrió un error al crear el tag para repositorio " + quote(self.repository, safe="") + ": " + response.text)
def get_merge_commits(self, merge_commit: str) -> list[Commit]:
mrs = self.get_json(
self.get_endpoint(f"/repository/commits/{merge_commit}/merge_requests")
).json()
mr = next((m for m in mrs if m.get("merge_commit_sha") == merge_commit), None)
if not mr:
raise GitFlowError(f"No se encontró un MR para el commit {merge_commit}")
items = self.get_all_pages(self.get_endpoint(f"/merge_requests/{mr['iid']}/commits"), 100)
# GitLab ya los devuelve del más nuevo al más viejo
return [
Commit(
c["short_id"][:7],
c["title"],
c["author_email"],
len(c["parent_ids"]) > 1,
)
for c in items
]
def get_endpoint(self, resource: str) -> str:
project_id = quote(self.repository, safe="")
return f"{self.base_url}/api/v4/projects/{project_id}{resource}"