Simplify printing
All checks were successful
test / test (pull_request) Successful in 36s
build / build (pull_request) Successful in 2m53s

This commit is contained in:
2024-10-10 00:59:43 +02:00
parent 5c73d55d91
commit 3064d0231c
6 changed files with 61 additions and 30 deletions

View File

@@ -1,5 +1,8 @@
import requests
from pydantic import BaseModel
from rich.console import Console
from nixprstatus.output import OutputFormat
DEFAULT_HEADERS = {
"Accept": "application/vnd.github.text+json",
@@ -13,6 +16,26 @@ class PRStatus(BaseModel):
merged: bool
branches: dict[str, bool]
def print(self, format: OutputFormat = OutputFormat.CONSOLE):
match format:
case OutputFormat.JSON:
print(self.model_dump_json())
case OutputFormat.CONSOLE:
console = Console(highlight=False)
console.print(f"{self.title}\n")
merged = ":white_check_mark: merged" if self.merged else ":x: merged"
console.print(merged)
for branch in self.branches:
output = (
f":white_check_mark: {branch}"
if self.branches[branch]
else f":x: {branch}"
)
console.print(output)
case _:
raise ValueError(f"Unknown format: {format}")
def commit_in_branch(commit_sha: str, branch: str) -> bool:
url = f"https://api.github.com/repos/NixOS/nixpkgs/compare/{branch}...{commit_sha}"