nixpkgs-tools/newModuleTagger/find_prs.py

55 lines
1.2 KiB
Python
Executable File

#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 gh
from pathlib import Path
import subprocess
import json
def _gh(args: list[str]) -> str | None:
try:
return subprocess.check_output(["gh", *args], text=True)
except subprocess.CalledProcessError:
return None
JSON_FIELDS = ','.join([
"files",
"author",
"title",
"number",
"labels",
"url"
])
def print_pr(pr):
print(f'[{pr["number"]}] {pr["author"]["login"]} - {pr["title"]}')
print(pr["url"])
print(f'Files:')
for file in pr["files"]:
print(f' {file}')
print()
def find_prs_without_new_module_tag():
prs = _gh(["pr", "list", "--json", JSON_FIELDS, "--limit", "50", "--label", "8.has: module (update)"])
if prs is None:
print("gh exited with error")
exit(1)
prs = json.loads(prs)
for pr in reversed(prs):
if any(label["name"] == "8.has: module (new)" for label in pr["labels"]):
continue
if not any(file['path'].startswith("nixos/modules/") and not Path(file['path']).exists() for file in pr['files']):
continue
print_pr(pr)
if __name__ == "__main__":
find_prs_without_new_module_tag()