From ccab258ea5f9d3e66c8c97ebbd1579d58055130d Mon Sep 17 00:00:00 2001 From: bryancito1090 Date: Thu, 5 Nov 2026 11:18:55 -0500 Subject: [PATCH] ci: reconocer issues normales en la API de Forgejo 1.21 --- scripts/check_gitflow.py | 4 ++-- tests/test_gitflow.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/check_gitflow.py b/scripts/check_gitflow.py index 0a71e3d..b49982f 100644 --- a/scripts/check_gitflow.py +++ b/scripts/check_gitflow.py @@ -10,6 +10,8 @@ import urllib.request def check_pr(pr, issue, subjects): + if issue.get("pull_request"): + raise ValueError("La referencia debe apuntar a un issue, no a otro PR.") match = re.fullmatch(r"(feature|bugfix|chore)/(\d+)-[a-z0-9]+(?:-[a-z0-9]+)*", pr["head"]["ref"]) if not match: raise ValueError("La rama debe usar /-slug.") @@ -57,8 +59,6 @@ def main(): if current["head"]["sha"] != pr["head"]["sha"]: raise ValueError("La rama cambio durante la ejecucion; validar el HEAD mas reciente.") issue = get(f"/issues/{match.group(1)}") - if "pull_request" in issue: - raise ValueError("La referencia debe apuntar a un issue, no a otro PR.") subjects = subprocess.check_output( ["git", "log", "--format=%s", f"{pr['base']['sha']}..{pr['head']['sha']}"], text=True ).splitlines() diff --git a/tests/test_gitflow.py b/tests/test_gitflow.py index 5f33806..eaafe94 100644 --- a/tests/test_gitflow.py +++ b/tests/test_gitflow.py @@ -14,11 +14,15 @@ class GitflowTest(unittest.TestCase): "head": {"ref": "feature/1-ansible-portal"}, "base": {"ref": "develop"}, "body": "Implementar portal. Closes #1", "labels": [{"name": "type::feature"}], "milestone": {"id": 2}, } - self.issue = {"state": "open", "labels": [{"name": "type::feature"}], "milestone": {"id": 2}} + self.issue = {"state": "open", "labels": [{"name": "type::feature"}], "milestone": {"id": 2}, "pull_request": None} def test_valid_pr(self): gitflow.check_pr(self.pr, self.issue, ["feat: configurar portal con Ansible"]) + def test_rejects_a_pull_request_used_as_issue(self): + with self.assertRaisesRegex(ValueError, "issue, no a otro PR"): + gitflow.check_pr(self.pr, {**self.issue, "pull_request": {"url": "/pulls/1"}}, ["feat: configurar portal con Ansible"]) + def test_rejects_invalid_metadata_and_commits(self): for mutation in [ {"base": {"ref": "main"}}, {"head": {"ref": "feature/ansible"}},