fix(gitea): check labels before creating, Gitea allows duplicates
This commit is contained in:
+9
-9
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user