Skip to content

Commit

Permalink
Add --json to save candidates to orphaned_backports.json
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jan 10, 2025
1 parent e6ca62d commit 910c11c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion orphaned_backports.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

# /// script
# requires-python = ">=3.9"
# requires-python = ">=3.11"
# dependencies = [
# "ghapi",
# "rich",
Expand All @@ -15,9 +15,12 @@
from __future__ import annotations

import argparse
import datetime as dt
import json
import os
from typing import Any, TypeAlias

from fastcore.xtras import obj2dict
from ghapi.all import GhApi, paged # pip install ghapi
from rich import print # pip install rich

Expand Down Expand Up @@ -128,6 +131,7 @@ def main() -> None:
),
help="Sort by",
)
parser.add_argument("-j", "--json", action="store_true", help="output to JSON file")
parser.add_argument(
"-x", "--dry-run", action="store_true", help="show but don't open PRs"
)
Expand All @@ -150,6 +154,21 @@ def main() -> None:
if not args.dry_run:
os.system(cmd)

if args.json:
# Use same name as this .py but with .json
filename = os.path.splitext(__file__)[0] + ".json"
now = dt.datetime.now(dt.UTC).isoformat()
with open(filename, "w", encoding="utf-8") as f:
json.dump(
{
"last_update": now,
"candidates": [obj2dict(c) for c in candidates],
},
f,
indent=2,
)
print(f"Saved candidates to {filename}")


if __name__ == "__main__":
main()

0 comments on commit 910c11c

Please sign in to comment.