def ignore_task()

in treeherder/etl/taskcluster_pulse/handler.py [0:0]


def ignore_task(task, task_id, root_url, project):
    ignore = False
    # This logic is useful to reduce the number of tasks we ingest and requirying
    # less dynos and less database writes. You can adjust PROJECTS_TO_INGEST on the app to meet your needs
    if projects_to_ingest and project not in projects_to_ingest.split(","):
        logger.debug("Ignoring tasks not matching PROJECTS_TO_INGEST (Task id: %s)", task_id)
        return True

    mobile_repos = (
        "reference-browser",
        "mozilla-vpn-client",
        "mozilla-vpn-client-release",
    )
    if project in mobile_repos:
        envs = task["payload"].get("env", {})
        if envs.get("MOBILE_BASE_REPOSITORY"):
            try:
                base_repo = envs["MOBILE_BASE_REPOSITORY"].rsplit("/", 1)[1]
                if base_repo in mobile_repos:
                    # Ignore tasks that are associated to a pull request
                    if envs["MOBILE_BASE_REPOSITORY"] != envs["MOBILE_HEAD_REPOSITORY"]:
                        logger.debug(
                            "Task: %s belong to a pull request OR branch which we ignore.", task_id
                        )
                        ignore = True
                    # Bug 1587542 - Temporary change to ignore Github tasks not associated to 'master'
                    if envs["MOBILE_HEAD_REF"] not in (
                        "refs/heads/master",
                        "master",
                        "refs/heads/main",
                        "main",
                    ):
                        logger.info("Task: %s is not for the `master` branch.", task_id)
                        ignore = True
            except KeyError:
                pass
        else:
            # The decision task is the ultimate source for determining this information
            queue = taskcluster.Queue({"rootUrl": root_url})
            decision_task = queue.task(task["taskGroupId"])
            scopes = decision_task["metadata"].get("source")
            ignore = True
            for scope in scopes:
                # e.g. assume:repo:github.com/mozilla-mobile/fenix:branch:master
                if scope.find("branch:master") != -1 or scope.find("branch:main") != -1:
                    ignore = False
                    break

            # This handles nightly tasks
            # e.g. index.mobile.v2.fenix.branch.master.latest.taskgraph.decision-nightly
            for route in decision_task["routes"]:
                if route.find("master") != -1 or route.find("main") != -1:
                    ignore = False
                    break

    if ignore:
        logger.debug(f"Task to be ignored ({task_id})")

    return ignore