From 7e9cdb4fc67b087e2329e7ded320fe68853ab7b7 Mon Sep 17 00:00:00 2001 From: Miroslav Franc Date: Jun 19 2025 13:35:31 +0000 Subject: scripts/python/dispatch-cves: add autoCCing and --no-cc-self option --- diff --git a/scripts/python/dispatch-cves b/scripts/python/dispatch-cves index 8701220..952b7c9 100755 --- a/scripts/python/dispatch-cves +++ b/scripts/python/dispatch-cves @@ -131,7 +131,7 @@ def update_bug_metadata(bzapi, todo): elif b.original_email != QUEUE_EMAIL: b.already_dispatched = True -def handle_file(bzapi, path, to_dispatch, remove_file, is_interactive=True): +def handle_file(bzapi, path, to_dispatch, remove_file, is_interactive=True, cc_us=None): with open(path, 'r') as f: decided = False bug = 0 @@ -139,6 +139,8 @@ def handle_file(bzapi, path, to_dispatch, remove_file, is_interactive=True): candidates = [] candidate_emails = [] cc_list = [] + if cc_us: + cc_list.append(cc_us) needinfo_list = [] for l in f: should_go_out = True @@ -222,20 +224,20 @@ def handle_file(bzapi, path, to_dispatch, remove_file, is_interactive=True): to_add = '' to_dispatch.append(BugUpdate(path if remove_file else None, bug, comment_lines, to_add, email, 'developer', cc_list, needinfo_list)) -def single_dispatch(bzapi, path, remove_file, yes, force): +def single_dispatch(bzapi, path, remove_file, yes, force, cc_us): to_dispatch = [] - handle_file(bzapi, path, to_dispatch, remove_file, is_interactive=not yes) + handle_file(bzapi, path, to_dispatch, remove_file, is_interactive=not yes, cc_us=cc_us) update_bug_metadata(bzapi, to_dispatch) ask_user(bzapi, to_dispatch, yes, force) -def multiple_dispatch(bzapi, path, remove_file, yes, force): +def multiple_dispatch(bzapi, path, remove_file, yes, force, cc_us): to_dispatch = [] nfiles = 0 for subdir, dirs, files in os.walk(path): for ckf in files: nfiles += 1 opath = subdir + os.sep + ckf - handle_file(bzapi, opath, to_dispatch, remove_file, is_interactive=False) + handle_file(bzapi, opath, to_dispatch, remove_file, is_interactive=False, cc_us=cc_us) if not nfiles: sys.exit(0) update_bug_metadata(bzapi, to_dispatch) @@ -265,21 +267,28 @@ The bugzilla comment will always contain copy of the ./scripts/check-kernel-fix parser.add_argument("-r", "--remove-file", help="Remove file after dispatching CVE", default=None, action="store_true") parser.add_argument("-y", "--yes", help="Dispatch without asking; never use :-)", default=None, action="store_true") parser.add_argument("--force", help="Bypass already dispatched check", default=None, action="store_true") + parser.add_argument("--no-cc-self", help="Do not CC yourself", default=None, action="store_true") return parser.parse_args() if __name__ == "__main__": try: args = parse_args() + cc_us = None + if not args.no_cc_self: + cc_us = os.environ.get('BUGZILLA_ACCOUNT_EMAIL', None) + if not cc_us: + print("WARNING: The BUGZILLA_ACCOUNT_EMAIL is not set, the autoCCing will not work!", file=sys.stderr) + bzapi = bugzilla.Bugzilla(DEFAULT_BZ) check_being_logged_in(bzapi) if args.file and os.path.isfile(args.file): - single_dispatch(bzapi, args.file, args.remove_file, args.yes, args.force) + single_dispatch(bzapi, args.file, args.remove_file, args.yes, args.force, cc_us) sys.exit(0) if args.dir and os.path.isdir(args.dir): - multiple_dispatch(bzapi, args.dir, args.remove_file, args.yes, args.force) + multiple_dispatch(bzapi, args.dir, args.remove_file, args.yes, args.force, cc_us) sys.exit(0) print(f"{args.file or args.dir} must be either regular file or a directory", file=sys.stderr)