in treeherder/webapp/api/intermittents_view.py [0:0]
def list(self, request):
query_params = FailuresQueryParamsSerializer(
data=request.query_params, context="requireBug"
)
if not query_params.is_valid():
return Response(data=query_params.errors, status=HTTP_400_BAD_REQUEST)
startday = query_params.validated_data["startday"]
endday = get_end_of_day(query_params.validated_data["endday"])
repo = query_params.validated_data["tree"]
bugzilla_id = query_params.validated_data["bug"]
self.queryset = (
BugJobMap.failures.by_date(startday, endday)
.by_repo(repo)
.by_bug(bugzilla_id)
.values(
"job__repository__name",
"job__machine_platform__platform",
"bug__bugzilla_id",
"job_id",
"job__push__time",
"job__push__revision",
"job__signature__job_type_name",
"job__option_collection_hash",
"job__machine__name",
)
.order_by("-job__push__time")
)
task_ids = TaskclusterMetadata.objects.filter(
job_id__in=self.queryset.values_list("job_id", flat=True),
).values_list("job_id", "task_id")
for item in self.queryset:
match = [x[1] for x in task_ids if x[0] == item["job_id"]]
if match:
item["task_id"] = match[0]
else:
item["task_id"] = "unknown"
lines = TextLogError.objects.filter(
job_id__in=self.queryset.values_list("job_id", flat=True),
line__contains="TEST-UNEXPECTED-FAIL",
).values_list("job_id", "line")
grouped_lines = defaultdict(list)
for job_id, line in lines:
if line is not None:
grouped_lines[job_id].append(line)
hash_list = set()
for item in self.queryset:
item["lines"] = grouped_lines.get(item["job_id"], [])
hash_list.add(item["job__option_collection_hash"])
hash_query = (
OptionCollection.objects.filter(option_collection_hash__in=hash_list)
.select_related("option")
.values("option__name", "option_collection_hash")
)
for item in self.queryset:
match = [
x["option__name"]
for x in hash_query
if x["option_collection_hash"] == item["job__option_collection_hash"]
]
if match:
item["build_type"] = match[0]
else:
item["build_type"] = "unknown"
serializer = self.get_serializer(self.queryset, many=True)
return Response(data=serializer.data)