From 78edc12c1b09b84bbea62e33fcf1f492a23db932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 11 May 2022 00:34:12 -0700 Subject: [PATCH] scripts: add make_bugs_pickle.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a simple script which snapshots open bugs in the zephyrproject-rtos/zephyr repository using the GitHub REST API. It relies on the 'github' module, which is a de-facto standard for accessing this API in Python: https://pygithub.readthedocs.io We are already using this package in scripts/release/bug_bash.py, so this is not a new dependency, even though it's a third party package not available in the standard library. The resulting bugs are stored in the standard library's 'pickle' format, as a list of github.Issue.Issue objects. For more on pickle, see: https://docs.python.org/3/library/pickle.html I am choosing pickle because it is standard, easy to use, and we are already using it in the build system to store the edtlib.EDT object created by gen_defines.py. This is also therefore not a new dependency (and even if it were, it's in the standard library). Signed-off-by: Martí Bolívar --- scripts/make_bugs_pickle.py | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 scripts/make_bugs_pickle.py diff --git a/scripts/make_bugs_pickle.py b/scripts/make_bugs_pickle.py new file mode 100755 index 00000000000000..91f6b5b0ceaf50 --- /dev/null +++ b/scripts/make_bugs_pickle.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2022 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +# stdlib +import argparse +import pickle +import sys +from pathlib import Path +from typing import BinaryIO, List + +# third party +from github.Issue import Issue + +# other zephyr/scripts modules +from github_helpers import get_github_object + +# Note that type annotations are not currently statically checked, and +# should only be considered documentation. + +def parse_args() -> argparse.Namespace: + '''Parse command line arguments.''' + parser = argparse.ArgumentParser( + description=''' +A helper script which loads all open bugs in the +zephyrproject-rtos/zephyr repository using the GitHub API, and writes +them to a new pickle file as a list of github.Issue.Issue objects. + +For more information, see: + + - GitHub API: https://docs.github.com/en/rest + - github.Issue.Issue: + https://pygithub.readthedocs.io/en/latest/github_objects/Issue.html + - pickle: https://docs.python.org/3/library/pickle.html +''', + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('out_file', metavar='OUTFILE', type=Path, nargs='?', + help='''file to write pickle data to (default: + stdout)''') + return parser.parse_args() + +def get_open_bugs() -> List[Issue]: + zephyr_repo = get_github_object().get_repo('zephyrproject-rtos/zephyr') + return list(zephyr_repo.get_issues(state='open', labels=['bug'])) + +def open_out_file(args: argparse.Namespace) -> BinaryIO: + if args.out_file is None: + return open(sys.stdout.fileno(), 'wb', closefd=False) + + return open(args.out_file, 'wb') + +def main() -> None: + args = parse_args() + open_bugs = get_open_bugs() + + with open_out_file(args) as out_file: + pickle.dump(open_bugs, out_file) + +if __name__ == '__main__': + main()