1#!/usr/bin/env python3 2 3# Copyright (c) 2022 Nordic Semiconductor ASA 4# 5# SPDX-License-Identifier: Apache-2.0 6 7# stdlib 8import argparse 9import pickle 10from pathlib import Path 11from typing import List 12 13# third party 14from github.Issue import Issue 15 16def parse_args() -> argparse.Namespace: 17 parser = argparse.ArgumentParser( 18 formatter_class=argparse.RawDescriptionHelpFormatter, allow_abbrev=False) 19 20 parser.add_argument('pickle_file', metavar='PICKLE-FILE', type=Path, 21 help='pickle file containing list of issues') 22 23 return parser.parse_args() 24 25def issue_has_label(issue: Issue, label: str) -> bool: 26 for lbl in issue.labels: 27 if lbl.name == label: 28 return True 29 return False 30 31def is_open_bug(issue: Issue) -> bool: 32 return (issue.pull_request is None and 33 issue.state == 'open' and 34 issue_has_label(issue, 'bug')) 35 36def get_bugs(args: argparse.Namespace) -> List[Issue]: 37 '''Get the bugs to use for analysis, given command line arguments.''' 38 with open(args.pickle_file, 'rb') as f: 39 return [issue for issue in pickle.load(f) if 40 is_open_bug(issue)] 41 42def main() -> None: 43 args = parse_args() 44 bugs = get_bugs(args) 45 for bug in sorted(bugs, key=lambda bug: bug.number): 46 title = bug.title.strip() 47 print(f'- :github:`{bug.number}` - {title}') 48 49if __name__ == '__main__': 50 main() 51