diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..24d7f18 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.direnv/ +**/__pycache__/* +result diff --git a/nixprstatus/__main__.py b/nixprstatus/__main__.py index 2990604..eaf4821 100644 --- a/nixprstatus/__main__.py +++ b/nixprstatus/__main__.py @@ -1,11 +1,48 @@ import typer +import requests +from rich.console import Console app = typer.Typer() +DEFAULT_HEADERS = { + "Accept": "application/vnd.github.text+json", +} + +BRANCHES = [ "nixos-unstable-small", "nixos-unstable", "nixos-24.05" ] + @app.command() -def pr(status: str): +def pr(pr: str): """Get status of pull request""" - typer.echo(f"Pull Request Status: {status}") + url = f"https://api.github.com/repos/NixOS/nixpkgs/pulls/{pr}" + + pr_response = requests.get(url, headers=DEFAULT_HEADERS) + pr_response.raise_for_status() + + pr_data = pr_response.json() + + console = Console() + + if pr_data["merged"] == False: + console.print(f":x: master", highlight=False) + for branch in BRANCHES: + console.print(f":x: {branch}", highlight=False) + return + + console.print(f":white_check_mark: master", highlight=False) + + + commit_sha = pr_data["merge_commit_sha"] + + for branch in BRANCHES: + url = f"https://api.github.com/repos/NixOS/nixpkgs/compare/{branch}...{commit_sha}" + commit_response = requests.get(url, headers=DEFAULT_HEADERS) + commit_response.raise_for_status() + status = commit_response.json().get("status") + + if status in [ "identical", "behind" ]: + console.print(f":white_check_mark: {branch}", highlight=False) + else: + console.print(f":x: {branch}", highlight=False) def main(): app()