def health_summary()

in treeherder/webapp/api/push.py [0:0]


    def health_summary(self, request, project):
        """
        Return a calculated summary of the health of this push.
        """
        revision = request.query_params.get("revision")
        author = request.query_params.get("author")
        count = request.query_params.get("count")
        all_repos = request.query_params.get("all_repos")
        with_history = request.query_params.get("with_history")
        with_in_progress_tests = request.query_params.get("with_in_progress_tests", False)

        if revision:
            try:
                pushes = Push.objects.filter(
                    revision__in=revision.split(","), repository__name=project
                )
            except Push.DoesNotExist:
                return Response(f"No push with revision: {revision}", status=HTTP_404_NOT_FOUND)
        else:
            try:
                pushes = (
                    Push.objects.filter(author=author)
                    .select_related("repository")
                    .prefetch_related("commits")
                    .order_by("-time")
                )

                if not all_repos:
                    pushes = pushes.filter(repository__name=project)

                pushes = pushes[: int(count)]

            except Push.DoesNotExist:
                return Response(f"No pushes found for author: {author}", status=HTTP_404_NOT_FOUND)

        data = []
        commit_history = None

        for push in list(pushes):
            result_status, jobs = get_test_failure_jobs(push)

            test_result, push_health_test_failures = get_test_failures(
                push,
                jobs,
                result_status,
            )

            build_result, push_health_build_failures, builds_in_progress_count = get_build_failures(
                push
            )

            lint_result, push_health_lint_failures, linting_in_progress_count = get_lint_failures(
                push
            )

            test_failure_count = len(push_health_test_failures["needInvestigation"])
            build_failure_count = len(push_health_build_failures)
            lint_failure_count = len(push_health_lint_failures)
            test_in_progress_count = 0

            status = push.get_status()
            total_failures = test_failure_count + build_failure_count + lint_failure_count
            # Override the testfailed value added in push.get_status so that it aligns with how we detect lint, build and test failures
            # for the push health API's (total_failures doesn't include known intermittent failures)
            status["testfailed"] = total_failures

            if with_history:
                serializer = PushSerializer([push], many=True)
                commit_history = serializer.data
            if with_in_progress_tests:
                test_in_progress_count = get_test_in_progress_count(push)

            data.append(
                {
                    "revision": push.revision,
                    "repository": push.repository.name,
                    "testFailureCount": test_failure_count,
                    "testInProgressCount": test_in_progress_count,
                    "buildFailureCount": build_failure_count,
                    "buildInProgressCount": builds_in_progress_count,
                    "lintFailureCount": lint_failure_count,
                    "lintingInProgressCount": linting_in_progress_count,
                    "needInvestigation": test_failure_count
                    + build_failure_count
                    + lint_failure_count,
                    "status": status,
                    "history": commit_history,
                    "metrics": {
                        "linting": {
                            "name": "Linting",
                            "result": lint_result,
                        },
                        "tests": {
                            "name": "Tests",
                            "result": test_result,
                        },
                        "builds": {
                            "name": "Builds",
                            "result": build_result,
                        },
                    },
                }
            )

        return Response(data)