Simplify printing
This commit is contained in:
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user