Call the GitHub REST API via the gh CLI and return parsed JSON.
(path: str)
| 116 | |
| 117 | |
| 118 | def gh_api(path: str) -> dict | list: |
| 119 | """Call the GitHub REST API via the gh CLI and return parsed JSON.""" |
| 120 | cmd = ["gh", "api", "-H", "Accept: application/vnd.github+json", path] |
| 121 | try: |
| 122 | result = subprocess.run(cmd, check=True, capture_output=True, text=True) |
| 123 | except FileNotFoundError: |
| 124 | sys.exit("gh CLI not found on PATH. Install: https://cli.github.com/") |
| 125 | except subprocess.CalledProcessError as exc: |
| 126 | sys.exit(f"gh api failed for {path}: {exc.stderr.strip()}") |
| 127 | return json.loads(result.stdout) |
| 128 | |
| 129 | |
| 130 | def parse_iso(value: str | None) -> dt.datetime | None: |
no test coverage detected