def update_triage_bugs()

in sync/notify/bugupdate.py [0:0]


def update_triage_bugs(git_gecko, comment=True):
    triage_bugs = TriageBugs(git_gecko)

    run_time = datetime.now()
    meta_links = triage_bugs.meta_links()

    updates = {}

    for bug in triage_bugs.updated_bugs(list(meta_links.keys())):
        if bug.resolution == "INVALID":
            updates[bug.id] = None
        elif bug.resolution == "DUPLICATE":
            duped_to = bug._bug["dupe_of"]
            while duped_to:
                final_bug = duped_to
                duped_to = env.bz.get_dupe(final_bug)
            updates[bug.id] = final_bug

        # TODO: handle some more cases here. Notably where the bug is marked as
        # FIXED, but the tests don't actually pass

    removed_by_bug = {}

    with ProcLock.for_process(TriageBugs.process_name) as lock:
        with triage_bugs.as_mut(lock):
            for old_bug, new_bug in updates.items():
                links = meta_links[old_bug]
                if new_bug is None:
                    removed_by_bug[old_bug] = links
                    for item in links:
                        item.delete()
                else:
                    new_url = env.bz.bugzilla_url(new_bug)
                    for link in links:
                        link.url = new_url
            triage_bugs.last_update = run_time

    # Now that the above change is commited, add some comments to bugzilla for the
    # case where we removed URLs
    comments = {}
    for bug, old_links in removed_by_bug.items():
        comments[bug] = comment_removed(bug, old_links, submit_comment=comment)

    return updates, comments