osv-followup: survive label-less API answers and an existing prune branch

This commit is contained in:
janhouse committed 2026-11-19 17:40:03 +02:00
1 parent 7f264b64fa
commit 14f3aadfb5
2 files changed
+10 -2

No files matched your search

Binary file not shown.
+10 -2
View File
@@ -126,7 +126,8 @@ class Gitea:
self.repo_path("/labels"),
{"name": name, "color": palette.get(name, "#6b7280")},
)
existing[name] = created["id"] # type: ignore[index]
if isinstance(created, dict) and created.get("id"):
existing[name] = created["id"]
except RuntimeError as e:
warn(f"could not create label {name!r}: {e}")
if name in existing:
@@ -516,7 +517,8 @@ def git(*args: str, check: bool = True, env_extra: dict | None = None) -> str:
e.update(env_extra)
proc = subprocess.run(["git", *args], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=e)
if check and proc.returncode != 0:
raise RuntimeError(f"git {args[0]} failed: {proc.stderr.strip()[:500]}")
sub = next((a for i, a in enumerate(args) if not a.startswith("-") and (i == 0 or args[i - 1] != "-c")), "?")
raise RuntimeError(f"git {sub} failed: {proc.stderr.strip()[:500]}")
return proc.stdout.strip()
@@ -600,6 +602,12 @@ def do_recheck(gitea: Gitea, cfg: dict) -> None:
config.write_text(updated)
git("add", str(config))
git("commit", "-m", title, "-m", "No dependency matches:\n" + "\n".join(f"- {e['id']}" for e in stale))
try:
push_branch(cfg, gitea, branch)
except RuntimeError as e:
# A branch of that name exists already (an earlier, closed PR today).
warn(f"push to {branch} failed ({e}); retrying under a new name")
branch = f"{branch}-{dt.datetime.now(dt.UTC).strftime('%H%M%S')}"
push_branch(cfg, gitea, branch)
pr = gitea.create_pull(title, body, branch, cfg["base"], labels)
log(f"Opened prune PR #{pr.get('number')}: {pr.get('html_url')}")