From 2785443794d1a181bd1efef1db208f30767e3b38 Mon Sep 17 00:00:00 2001 From: h Date: Thu, 10 Sep 2026 16:07:02 +0000 Subject: [PATCH] fix(gitea): check labels before creating, Gitea allows duplicates --- templates.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/templates.py b/templates.py index baa91ff..185dc13 100644 --- a/templates.py +++ b/templates.py @@ -156,16 +156,16 @@ def gitea(args: argparse.Namespace) -> None: raw = response.read() return json.loads(raw) if raw else None + # Gitea happily creates a second label with the same name, so the only way to + # stay idempotent is to look first. + existing = {label["name"] for label in call("GET", f"/repos/{args.repo}/labels?limit=100") or []} for name, color, description in RENOVATE_LABELS: - try: - call("POST", f"/repos/{args.repo}/labels", - {"name": name, "color": color, "description": description}) - print(f"label {name}: created") - except urllib.error.HTTPError as error: - if error.code in (409, 422): - print(f"label {name}: already there") - else: - sys.exit(f"label {name}: {error.code} {error.read()[:200]!r}") + if name in existing: + print(f"label {name}: already there") + continue + call("POST", f"/repos/{args.repo}/labels", + {"name": name, "color": color, "description": description}) + print(f"label {name}: created") try: call("GET", f"/repos/{args.repo}/contents/{RENOVATE_FILE}")