From 910c11c495a6b829ae05c0a2dd130569b120a482 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 10 Jan 2025 18:41:11 +0200 Subject: [PATCH] Add --json to save candidates to orphaned_backports.json --- orphaned_backports.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/orphaned_backports.py b/orphaned_backports.py index a8e7f60..44693fd 100644 --- a/orphaned_backports.py +++ b/orphaned_backports.py @@ -5,7 +5,7 @@ """ # /// script -# requires-python = ">=3.9" +# requires-python = ">=3.11" # dependencies = [ # "ghapi", # "rich", @@ -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 @@ -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" ) @@ -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()