in treeherder/webapp/api/push.py [0:0]
def health(self, request, project):
"""
Return a calculated assessment of the health of this push.
"""
revision = request.query_params.get("revision")
try:
repository = Repository.objects.get(name=project)
push = Push.objects.get(revision=revision, repository=repository)
except Push.DoesNotExist:
return Response(f"No push with revision: {revision}", status=HTTP_404_NOT_FOUND)
commit_history_details = None
result_status, jobs = get_test_failure_jobs(push)
# Parent compare only supported for Hg at this time.
# Bug https://bugzilla.mozilla.org/show_bug.cgi?id=1612645
if repository.dvcs_type == "hg":
commit_history_details = get_commit_history(repository, revision, push)
test_result, push_health_test_failures = get_test_failures(
push,
jobs,
result_status,
)
build_result, build_failures, _unused = get_build_failures(push)
lint_result, lint_failures, _unused = get_lint_failures(push)
push_result = "pass"
for metric_result in [test_result, lint_result, build_result]:
if (
metric_result == "indeterminate"
or metric_result == "unknown"
and push_result != "fail"
):
push_result = metric_result
elif metric_result == "fail":
push_result = metric_result
status = push.get_status()
total_failures = (
len(push_health_test_failures["needInvestigation"])
+ len(build_failures)
+ len(lint_failures)
)
# 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
newrelic.agent.record_custom_event(
"push_health_need_investigation",
{
"revision": revision,
"repo": repository.name,
"needInvestigation": len(push_health_test_failures["needInvestigation"]),
"author": push.author,
},
)
return Response(
{
"revision": revision,
"id": push.id,
"result": push_result,
"jobs": jobs,
"metrics": {
"commitHistory": {
"name": "Commit History",
"result": "none",
"details": commit_history_details,
},
"linting": {
"name": "Linting",
"result": lint_result,
"details": lint_failures,
},
"tests": {
"name": "Tests",
"result": test_result,
"details": push_health_test_failures,
},
"builds": {
"name": "Builds",
"result": build_result,
"details": build_failures,
},
},
"status": status,
}
)