Example #1
0
    def text_log_summary(self, request, project, jm, pk=None):
        """
        Get a list of test failure lines for the job
        """
        job = jm.get_job(pk)
        if not job:
            return Response("No job with id: {0}".format(pk),
                            status=HTTP_404_NOT_FOUND)

        job = job[0]
        summary = TextLogSummary.objects.filter(
            job_guid=job['job_guid']).prefetch_related("lines").all()

        if len(summary) > 1:
            raise ValueError("Got multiple TextLogSummaries for the same job")

        if not summary:
            return Response(
                "No text_log_summary generated for job with id: {0}".format(
                    pk),
                status=HTTP_404_NOT_FOUND)

        with ArtifactsModel(project) as am:
            artifacts = am.get_job_artifact_list(
                offset=0,
                limit=2,
                conditions={
                    "job_id": set([("=", pk)]),
                    "name":
                    set([("IN", ("Bug suggestions", "text_log_summary"))]),
                    "type": set([("=", "json")])
                })
            artifacts_by_name = {item["name"]: item for item in artifacts}

        text_log_summary = artifacts_by_name.get("text_log_summary", {})
        error_lines = text_log_summary.get("blob",
                                           {}).get("step_data",
                                                   {}).get("all_errors", [])
        bug_suggestions = artifacts_by_name.get("Bug suggestions",
                                                {}).get("blob")

        summary = summary[0]

        text_log_summary = artifacts_by_name.get("text_log_summary", {})
        lines_by_number = {
            line["linenumber"]: line["line"]
            for line in error_lines
        }

        rv = serializers.TextLogSummarySerializer(summary).data
        rv["bug_suggestions"] = bug_suggestions

        for line in rv["lines"]:
            line["line"] = lines_by_number[line["line_number"]]

        return Response(rv)
Example #2
0
    def text_log_summary(self, request, project, pk=None):
        """
        Get a list of test failure lines for the job
        """
        try:
            job = Job.objects.get(repository__name=project,
                                  project_specific_id=pk)
        except ObjectDoesNotExist:
            return Response("No job with id: {0}".format(pk),
                            status=HTTP_404_NOT_FOUND)

        summary = TextLogSummary.objects.filter(
            job_guid=job.guid).prefetch_related("lines").all()

        if len(summary) > 1:
            raise ValueError("Got multiple TextLogSummaries for the same job")

        if not summary:
            return Response(
                "No text_log_summary generated for job with id: {0}".format(
                    pk),
                status=HTTP_404_NOT_FOUND)

        summary = summary[0]

        lines_by_number = {
            error.line_number: error.line
            for error in TextLogError.objects.filter(step__job=job)
        }

        rv = serializers.TextLogSummarySerializer(summary).data
        rv["bug_suggestions"] = get_error_summary(job)

        for line in rv["lines"]:
            line["line"] = lines_by_number[line["line_number"]]

        return Response(rv)