fix(gitea): check labels before creating, Gitea allows duplicates
This commit is contained in:
+6
-6
@@ -156,16 +156,16 @@ def gitea(args: argparse.Namespace) -> None:
|
|||||||
raw = response.read()
|
raw = response.read()
|
||||||
return json.loads(raw) if raw else None
|
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:
|
for name, color, description in RENOVATE_LABELS:
|
||||||
try:
|
if name in existing:
|
||||||
|
print(f"label {name}: already there")
|
||||||
|
continue
|
||||||
call("POST", f"/repos/{args.repo}/labels",
|
call("POST", f"/repos/{args.repo}/labels",
|
||||||
{"name": name, "color": color, "description": description})
|
{"name": name, "color": color, "description": description})
|
||||||
print(f"label {name}: created")
|
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}")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
call("GET", f"/repos/{args.repo}/contents/{RENOVATE_FILE}")
|
call("GET", f"/repos/{args.repo}/contents/{RENOVATE_FILE}")
|
||||||
|
|||||||
Reference in New Issue
Block a user