osv-followup: survive label-less API answers and an existing prune branch
This commit is contained in:
1 parent
7f264b64fa
commit
14f3aadfb5
2 files changed
+11
-3
No files matched your search
Binary file not shown.
@@ -126,7 +126,8 @@ class Gitea:
|
|||||||
self.repo_path("/labels"),
|
self.repo_path("/labels"),
|
||||||
{"name": name, "color": palette.get(name, "#6b7280")},
|
{"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:
|
except RuntimeError as e:
|
||||||
warn(f"could not create label {name!r}: {e}")
|
warn(f"could not create label {name!r}: {e}")
|
||||||
if name in existing:
|
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)
|
e.update(env_extra)
|
||||||
proc = subprocess.run(["git", *args], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=e)
|
proc = subprocess.run(["git", *args], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=e)
|
||||||
if check and proc.returncode != 0:
|
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()
|
return proc.stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
@@ -600,7 +602,13 @@ def do_recheck(gitea: Gitea, cfg: dict) -> None:
|
|||||||
config.write_text(updated)
|
config.write_text(updated)
|
||||||
git("add", str(config))
|
git("add", str(config))
|
||||||
git("commit", "-m", title, "-m", "No dependency matches:\n" + "\n".join(f"- {e['id']}" for e in stale))
|
git("commit", "-m", title, "-m", "No dependency matches:\n" + "\n".join(f"- {e['id']}" for e in stale))
|
||||||
push_branch(cfg, gitea, branch)
|
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)
|
pr = gitea.create_pull(title, body, branch, cfg["base"], labels)
|
||||||
log(f"Opened prune PR #{pr.get('number')}: {pr.get('html_url')}")
|
log(f"Opened prune PR #{pr.get('number')}: {pr.get('html_url')}")
|
||||||
discord(f"{cfg['repo']}: osv-scanner.toml prune PR #{pr.get('number')}", str(pr.get("html_url", "")))
|
discord(f"{cfg['repo']}: osv-scanner.toml prune PR #{pr.get('number')}", str(pr.get("html_url", "")))
|
||||||
|
|||||||
Reference in new issue
Block a user