def main()

in fog-updater/src/fog_update.py [0:0]


def main(argv, repo, author, debug=False, dry_run=False):
    if len(argv) < 1:
        print(USAGE)
        sys.exit(1)

    release_branch_name = "main"
    short_version = "main"

    metrics_index = get_latest_metrics_index()
    data = eval_extract(metrics_index)
    gecko_metrics = sorted(data["gecko_metrics"])
    gecko_pings = sorted(data["gecko_pings"])
    firefox_desktop_metrics = sorted(data["firefox_desktop_metrics"])
    firefox_desktop_pings = sorted(data["firefox_desktop_pings"])
    background_update_metrics = sorted(data["background_update_metrics"])
    background_update_pings = sorted(data["background_update_pings"])
    background_tasks_metrics = sorted(data["background_tasks_metrics"])
    background_tasks_pings = sorted(data["background_tasks_pings"])

    data = [
        # Name, metrics/pings, library?, files
        ["gecko", "metrics", True, gecko_metrics],
        ["gecko", "pings", True, gecko_pings],
        ["firefox_desktop", "metrics", False, firefox_desktop_metrics],
        ["firefox_desktop", "pings", False, firefox_desktop_pings],
        [
            "firefox_desktop_background_update",
            "metrics",
            False,
            background_update_metrics,
        ],
        ["firefox_desktop_background_update", "pings", False, background_update_pings],
        [
            "firefox_desktop_background_tasks",
            "metrics",
            False,
            background_tasks_metrics,
        ],
        ["firefox_desktop_background_tasks", "pings", False, background_tasks_pings],
    ]

    print(f"{ts()} Updating repositories.yaml")
    try:
        new_content = _rewrite_repositories_yaml(
            repo, release_branch_name, data, debug=dry_run or debug
        )
    except UnmodifiedException as e:
        print(f"{ts()} {e}")
        return
    except Exception as e:
        print(f"{ts()} {e}")
        raise

    if dry_run:
        print(f"{ts()} Dry-run so not continuing.")
        return

    # Create a non unique PR branch name for work on this ac release branch.
    pr_branch_name = f"fog-update/update-metrics-index-{short_version}"

    try:
        pr_branch = repo.get_branch(pr_branch_name)
        if pr_branch:
            print(f"{ts()} The PR branch {pr_branch_name} already exists. Exiting.")
            return
    except GithubException:
        # TODO Only ignore a 404 here, fail on others
        pass

    release_branch = repo.get_branch(release_branch_name)
    print(f"{ts()} Last commit on {release_branch_name} is {release_branch.commit.sha}")

    print(f"{ts()} Creating branch {pr_branch_name} on {release_branch.commit.sha}")
    repo.create_git_ref(
        ref=f"refs/heads/{pr_branch_name}", sha=release_branch.commit.sha
    )
    print(f"{ts()} Created branch {pr_branch_name} on {release_branch.commit.sha}")

    _commit_repositories_yaml(repo, pr_branch_name, author, new_content)

    print(f"{ts()} Creating pull request")
    pr = repo.create_pull(
        title=f"Update to latest metrics_index list on {release_branch_name}",
        body=BODY_TEMPLATE,
        head=pr_branch_name,
        base=release_branch_name,
    )
    print(f"{ts()} Pull request at {pr.html_url}")