<commit_before>from __future__ import absolute_import, division, unicode_literals

import itertools

from flask import Response
from sqlalchemy.orm import joinedload

from changes.api.base import APIView
from changes.models import Project, Build, Revision


class ProjectCommitIndexAPIView(APIView):
    def _get_project(self, project_id):
        project = Project.query.options(
            joinedload(Project.repository),
        ).filter_by(slug=project_id).first()
        if project is None:
            project = Project.query.options(
                joinedload(Project.repository),
            ).get(project_id)
        return project

    def get(self, project_id):
        project = self._get_project(project_id)
        if not project:
            return Response(status=404)

        repo = project.repository
        vcs = repo.get_vcs()

        if vcs:
            vcs_log = list(vcs.log())

            revisions_qs = Revision.query.filter(
                Revision.repository_id == repo.id,
                Revision.sha.in_(c.id for c in vcs_log)
            ).join(Revision.author)

            revisions_map = dict(
                (c.sha, d)
                for c, d in itertools.izip(revisions_qs, self.serialize(revisions_qs))
            )

            commits = []
            for commit in vcs_log:
                if commit.id in revisions_map:<commit_msg>Coerce revisions to list<commit_after>from __future__ import absolute_import, division, unicode_literals

import itertools

from flask import Response
from sqlalchemy.orm import joinedload

from changes.api.base import APIView
from changes.models import Project, Build, Revision


class ProjectCommitIndexAPIView(APIView):
    def _get_project(self, project_id):
        project = Project.query.options(
            joinedload(Project.repository),
        ).filter_by(slug=project_id).first()
        if project is None:
            project = Project.query.options(
                joinedload(Project.repository),
            ).get(project_id)
        return project

    def get(self, project_id):
        project = self._get_project(project_id)
        if not project:
            return Response(status=404)

        repo = project.repository
        vcs = repo.get_vcs()

        if vcs:
            vcs_log = list(vcs.log())

            revisions_qs = list(Revision.query.filter(
                Revision.repository_id == repo.id,
                Revision.sha.in_(c.id for c in vcs_log)
            ).join(Revision.author))

            revisions_map = dict(
                (c.sha, d)
                for c, d in itertools.izip(revisions_qs, self.serialize(revisions_qs))
            )

            commits = []
            for commit in vcs_log:
                if commit.id in revisions_map:
{'fraction_non_alphanumeric': 0.08120733021918793, 'fraction_numerical': 0.0021559468199784403, 'mean_word_length': 2.066079295154185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5377189', 'n_tokens_mistral': 812, 'n_tokens_neox': 765, 'n_words': 186}