def autoclassify_failures()

in treeherder/etl/classification_loader.py [0:0]


    def autoclassify_failures(self, failures, classification):
        for tasks in failures.values():
            for task in tasks:
                # Keeping only the tasks that should be autoclassified
                if not task.get("autoclassify"):
                    continue

                bugs = []
                for failing_test_name in task.get("tests", []):
                    try:
                        bugs.append(
                            Bugscache.objects.get(
                                summary__endswith=f"{failing_test_name} | single tracking bug"
                            )
                        )
                    except Bugscache.DoesNotExist:
                        logger.info(
                            "No single tracking Bugzilla bug found for test name: %s",
                            failing_test_name,
                        )

                if not bugs:
                    # No associated Bugzilla bug exists, skipping the autoclassification
                    continue

                # Retrieving the relevant Job
                try:
                    job = Job.objects.get(taskcluster_metadata__task_id=task["task_id"])
                except Job.DoesNotExist:
                    logger.error(
                        "Job associated to the TC task %s does not exist and could not be autoclassified.",
                        task["task_id"],
                    )
                    raise

                # Skipping it if it was already classified either by Sheriffs or by mozci
                if JobNote.objects.filter(job=job).exists():
                    logger.info("Job %s is already associated to a JobNote.", job)
                    continue

                # Adding an "autoclassified intermittent" classification on it
                JobNote.objects.create(
                    job=job,
                    failure_classification=classification,
                    text="Autoclassified by mozci bot as an intermittent failure",
                )

                # Linking it to the relevant Bugzilla single tracking bugs
                BugJobMap.objects.bulk_create(
                    [BugJobMap(job=job, bug_id=bug.id) for bug in bugs], ignore_conflicts=True
                )