def ingest_hg_push()

in treeherder/etl/management/commands/ingest.py [0:0]


def ingest_hg_push(options):
    # get reference to repo and ingest this particular revision for this project
    project = options["project"]
    commit = options["commit"]

    if not options["last_n_pushes"] and not commit:
        raise CommandError("must specify --last-n-pushes or a positional commit argument")
    elif options["last_n_pushes"] and options["ingest_all_tasks"]:
        raise CommandError("Can't specify last_n_pushes and ingest_all_tasks at same time")
    elif options["last_n_pushes"] and options["commit"]:
        raise CommandError("Can't specify last_n_pushes and commit/revision at the same time")
    repo = Repository.objects.get(name=project, active_status="active")
    fetch_push_id = None

    if options["last_n_pushes"]:
        last_push_id = last_push_id_from_server(repo)
        fetch_push_id = max(1, last_push_id - options["last_n_pushes"])
        logger.info(
            "last server push id: %d; fetching push %d and newer",
            last_push_id,
            fetch_push_id,
        )
    elif options["ingest_all_tasks"]:
        gecko_decision_task = get_decision_task_id(project, commit, repo.tc_root_url)
        logger.info("## START ##")
        loop = asyncio.get_event_loop()
        loop.run_until_complete(process_tasks(gecko_decision_task, repo.tc_root_url))
        logger.info("## END ##")
    else:
        logger.info("You can ingest all tasks for a push with -a/--ingest-all-tasks.")

    _ingest_hg_push(project, commit, fetch_push_id)