From 250d542e2665f4d9265d576c7513f0b9515bcc33 Mon Sep 17 00:00:00 2001 From: Igor Raits Date: Jul 21 2020 17:18:51 +0000 Subject: ftbfs-fti: Move bugkeeping to the separate function Signed-off-by: Igor Raits --- diff --git a/scripts/ftbfs-fti/follow-policy.py b/scripts/ftbfs-fti/follow-policy.py index b7bf447..5e87781 100755 --- a/scripts/ftbfs-fti/follow-policy.py +++ b/scripts/ftbfs-fti/follow-policy.py @@ -13,6 +13,7 @@ import solv TEMPLATE_DIR = os.path.dirname(os.path.realpath(__file__)) +NOW = datetime.datetime.now() TRACKERS = { "F30FailsToInstall": 1700323, "F31FailsToInstall": 1700324, @@ -29,6 +30,96 @@ def _bzdate_to_python(date): return datetime.datetime.strptime(str(date), "%Y%m%dT%H:%M:%S") +def handle_orphaning(bug): + bz = bug.bugzilla + creation_time = _bzdate_to_python(bug.creation_time) + diff = NOW - creation_time + if diff < datetime.timedelta(weeks=1): + print( + f"Skipping because week did not pass yet since creation time ({creation_time})", + file=sys.stderr, + ) + return + + # Only reliable way to get whether needinfos were set is go through history + history = bug.get_history_raw()["bugs"][0]["history"] + needinfos = [ + u + for u in history + for c in u["changes"] + if f"needinfo?({bug.assigned_to})" in c["added"] + ] + bzupdate = None + flag = {"name": "needinfo", "status": "?", "requestee": bug.assigned_to} + if not needinfos: + print("Asking for a first needinfo") + bzupdate = bz.build_update( + comment="""Hello, + +This is the first reminder (step 3 from https://docs.fedoraproject.org/en-US/fesco/Fails_to_build_from_source_Fails_to_install/#_package_removal_for_long_standing_ftbfs_and_fti_bugs).""", + flags=[flag], + ) + else: + try: + needinfo_after_week = next( + _bzdate_to_python(n["when"]) + for n in needinfos + if NOW - _bzdate_to_python(n["when"]) >= datetime.timedelta(weeks=1) + ) + except StopIteration: + print( + f"No needinfo older than 1 week (oldest is from {_bzdate_to_python(needinfos[0]['when'])})", + file=sys.stderr, + ) + return + try: + needinfo_after_four_weeks = next( + _bzdate_to_python(n["when"]) + for n in needinfos + if _bzdate_to_python(n["when"]) - needinfo_after_week + >= datetime.timedelta(weeks=3) + ) + except StopIteration: + print( + f"No needinfo older than 3 weeks starting from first needinfo ({needinfo_after_week})", + file=sys.stderr, + ) + if NOW - needinfo_after_week >= datetime.timedelta(weeks=3): + print("Asking for another needinfo") + # RHBZ can have multiple needinfo flags, but python-bugzilla does not like it much + # https://github.com/python-bugzilla/python-bugzilla/issues/118 + flags = [f for f in bug.flags if f["name"] == "needinfo"] + if flags: + # If there are any needinfos, we will drop all of them and then create a new one + bz.update_bugs( + [bug.id], + bz.build_update( + flags=[ + {"name": "needinfo", "id": f["id"], "status": "X"} + for f in flags + ] + ), + ) + bzupdate = bz.build_update( + comment="""Hello, + +This is the second reminder (step 4 from https://docs.fedoraproject.org/en-US/fesco/Fails_to_build_from_source_Fails_to_install/#_package_removal_for_long_standing_ftbfs_and_fti_bugs).""", + flags=[flag], + ) + # TODO: Implement + if NOW - needinfo_after_four_weeks >= datetime.timedelta(weeks=4): + print("Opening releng ticket") + # TODO: Implement + else: + print( + f"No needinfo older than 4 weeks starting from second needinfo ({needinfo_after_four_weeks})", + file=sys.stderr, + ) + + if bzupdate is not None: + bz.update_bugs([bug.id], bzupdate) + + def find_broken_packages(pool): solver = pool.Solver() solver.set_flag(solv.Solver.SOLVER_FLAG_IGNORE_RECOMMENDED, True) @@ -204,95 +295,9 @@ def follow_policy(): # Now we care only about bugs in NEW state current_ftis = {src: b for src, b in current_ftis.items() if b.status == "NEW"} - now = datetime.datetime.now() for src, b in current_ftis.items(): print(f"Checking {b.id} ({src})…") - creation_time = _bzdate_to_python(b.creation_time) - diff = now - creation_time - if diff < datetime.timedelta(weeks=1): - print( - f"Skipping because week did not pass yet since creation time ({creation_time})", - file=sys.stderr, - ) - continue - - # Only reliable way to get whether needinfos were set is go through history - history = b.get_history_raw()["bugs"][0]["history"] - needinfos = [ - u - for u in history - for c in u["changes"] - if f"needinfo?({b.assigned_to})" in c["added"] - ] - bzupdate = None - flag = {"name": "needinfo", "status": "?", "requestee": b.assigned_to} - if not needinfos: - print("Asking for a first needinfo") - bzupdate = bz.build_update( - comment="""Hello, - -This is the first reminder (step 3 from https://docs.fedoraproject.org/en-US/fesco/Fails_to_build_from_source_Fails_to_install/#_package_removal_for_long_standing_ftbfs_and_fti_bugs).""", - flags=[flag], - ) - else: - try: - needinfo_after_week = next( - _bzdate_to_python(n["when"]) - for n in needinfos - if now - _bzdate_to_python(n["when"]) >= datetime.timedelta(weeks=1) - ) - except StopIteration: - print( - f"No needinfo older than 1 week (oldest is from {_bzdate_to_python(needinfos[0]['when'])})", - file=sys.stderr, - ) - continue - try: - needinfo_after_four_weeks = next( - _bzdate_to_python(n["when"]) - for n in needinfos - if _bzdate_to_python(n["when"]) - needinfo_after_week - >= datetime.timedelta(weeks=3) - ) - except StopIteration: - print( - f"No needinfo older than 3 weeks starting from first needinfo ({needinfo_after_week})", - file=sys.stderr, - ) - if now - needinfo_after_week >= datetime.timedelta(weeks=3): - print("Asking for another needinfo") - # RHBZ can have multiple needinfo flags, but python-bugzilla does not like it much - # https://github.com/python-bugzilla/python-bugzilla/issues/118 - flags = [f for f in b.flags if f["name"] == "needinfo"] - if flags: - # If there are any needinfos, we will drop all of them and then create a new one - bz.update_bugs( - [b.id], - bz.build_update( - flags=[ - {"name": "needinfo", "id": f["id"], "status": "X"} - for f in flags - ] - ), - ) - bzupdate = bz.build_update( - comment="""Hello, - -This is the second reminder (step 4 from https://docs.fedoraproject.org/en-US/fesco/Fails_to_build_from_source_Fails_to_install/#_package_removal_for_long_standing_ftbfs_and_fti_bugs).""", - flags=[flag], - ) - # TODO: Implement - if now - needinfo_after_four_weeks >= datetime.timedelta(weeks=4): - print("Opening releng ticket") - # TODO: Implement - else: - print( - f"No needinfo older than 4 weeks starting from second needinfo ({needinfo_after_four_weeks})", - file=sys.stderr, - ) - - if bzupdate is not None: - bz.update_bugs([b.id], bzupdate) + handle_orphaning(b) if __name__ == "__main__":