nixprstatus/nixprstatus/__main__.py
Torjus Håkestad 9ee3ec2018
All checks were successful
test / test (pull_request) Successful in 53s
build / build (pull_request) Successful in 2m11s
Add title to pr command output
2024-10-07 16:02:45 +02:00

71 lines
1.6 KiB
Python

import typer
import json
from typing import Annotated
from rich.console import Console
from nixprstatus.pr import pr_merge_status
from nixprstatus.pr import commits_since
app = typer.Typer()
DEFAULT_HEADERS = {
"Accept": "application/vnd.github.text+json",
}
BRANCHES = ["nixos-unstable-small", "nixos-unstable", "nixos-24.05"]
@app.command()
def pr(
pr: int,
branches: Annotated[
list[str] | None, typer.Option(help="Check specific branch")
] = None,
):
"""Get status of pull request"""
console = Console()
if branches:
status = pr_merge_status(pr, branches)
else:
status = pr_merge_status(pr)
console.print(f"{status.title}\n", highlight=False)
merged = ":white_check_mark: merged" if status.merged else ":x: merged"
console.print(merged, highlight=False)
for branch in status.branches:
output = (
f":white_check_mark: {branch}"
if status.branches[branch]
else f":x: {branch}"
)
console.print(output, highlight=False)
@app.command()
def since(
commit_sha: str,
target: str = "nixos-unstable",
waybar_format: Annotated[
bool, typer.Option(help="Output in format expected by waybar")
] = False,
):
"""
Return the count of commits that has happened between the two refs.
"""
count = commits_since(target, commit_sha)
if waybar_format:
output = {"text": str(count), "tooltip": f"{target}: {count}"}
typer.echo(json.dumps(output))
return
typer.echo(count)
def main():
app()
if __name__ == "__main__":
main()