diff --git a/osv-followup/__pycache__/followup.cpython-314.pyc b/osv-followup/__pycache__/followup.cpython-314.pyc index 9f229e6..35521e3 100644 Binary files a/osv-followup/__pycache__/followup.cpython-314.pyc and b/osv-followup/__pycache__/followup.cpython-314.pyc differ diff --git a/osv-followup/followup.py b/osv-followup/followup.py index e184bad..9d1ff79 100644 --- a/osv-followup/followup.py +++ b/osv-followup/followup.py @@ -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,7 +602,13 @@ 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)) - 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) 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", "")))