feat: configurar portal y CloudWatch con Ansible y CI en Forgejo #2
|
|
@ -10,6 +10,8 @@ import urllib.request
|
||||||
|
|
||||||
|
|
||||||
def check_pr(pr, issue, subjects):
|
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"])
|
match = re.fullmatch(r"(feature|bugfix|chore)/(\d+)-[a-z0-9]+(?:-[a-z0-9]+)*", pr["head"]["ref"])
|
||||||
if not match:
|
if not match:
|
||||||
raise ValueError("La rama debe usar <feature|bugfix|chore>/<issue>-slug.")
|
raise ValueError("La rama debe usar <feature|bugfix|chore>/<issue>-slug.")
|
||||||
|
|
@ -57,8 +59,6 @@ def main():
|
||||||
if current["head"]["sha"] != pr["head"]["sha"]:
|
if current["head"]["sha"] != pr["head"]["sha"]:
|
||||||
raise ValueError("La rama cambio durante la ejecucion; validar el HEAD mas reciente.")
|
raise ValueError("La rama cambio durante la ejecucion; validar el HEAD mas reciente.")
|
||||||
issue = get(f"/issues/{match.group(1)}")
|
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(
|
subjects = subprocess.check_output(
|
||||||
["git", "log", "--format=%s", f"{pr['base']['sha']}..{pr['head']['sha']}"], text=True
|
["git", "log", "--format=%s", f"{pr['base']['sha']}..{pr['head']['sha']}"], text=True
|
||||||
).splitlines()
|
).splitlines()
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,15 @@ class GitflowTest(unittest.TestCase):
|
||||||
"head": {"ref": "feature/1-ansible-portal"}, "base": {"ref": "develop"},
|
"head": {"ref": "feature/1-ansible-portal"}, "base": {"ref": "develop"},
|
||||||
"body": "Implementar portal. Closes #1", "labels": [{"name": "type::feature"}], "milestone": {"id": 2},
|
"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):
|
def test_valid_pr(self):
|
||||||
gitflow.check_pr(self.pr, self.issue, ["feat: configurar portal con Ansible"])
|
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):
|
def test_rejects_invalid_metadata_and_commits(self):
|
||||||
for mutation in [
|
for mutation in [
|
||||||
{"base": {"ref": "main"}}, {"head": {"ref": "feature/ansible"}},
|
{"base": {"ref": "main"}}, {"head": {"ref": "feature/ansible"}},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue