Beispiel #1
0
def _get_commits_committer(commits, author_id):
    result = serialize(
        [commit for commit, score in commits if commit.author.id == author_id],
        serializer=CommitSerializer(exclude=['author']))
    for idx, row in enumerate(result):
        row['score'] = commits[idx][1]
    return result
Beispiel #2
0
def get_serialized_event_file_committers(project, event, frame_limit=25):
    committers = get_event_file_committers(project,
                                           event,
                                           frame_limit=frame_limit)
    commits = [
        commit for committer in committers for commit in committer["commits"]
    ]
    serialized_commits = serialize(
        [c for (c, score) in commits],
        serializer=CommitSerializer(exclude=["author"]))

    serialized_commits_by_id = {}

    for (commit, score), serialized_commit in zip(commits, serialized_commits):
        serialized_commit["score"] = score
        serialized_commits_by_id[commit.id] = serialized_commit

    for committer in committers:
        commit_ids = [commit.id for (commit, _) in committer["commits"]]
        committer["commits"] = [
            serialized_commits_by_id[commit_id] for commit_id in commit_ids
        ]

    metrics.incr(
        "feature.owners.has-committers",
        instance="hit" if committers else "miss",
        skip_internal=False,
    )
    return committers
Beispiel #3
0
def get_serialized_event_file_committers(project, event, frame_limit=25):
    committers = get_event_file_committers(project,
                                           event,
                                           frame_limit=frame_limit)
    commits = [
        commit for committer in committers for commit in committer['commits']
    ]
    serialized_commits = serialize(
        [c for (c, score) in commits],
        serializer=CommitSerializer(exclude=['author']),
    )

    serialized_commits_by_id = {}

    for (commit, score), serialized_commit in zip(commits, serialized_commits):
        serialized_commit['score'] = score
        serialized_commits_by_id[commit.id] = serialized_commit

    for committer in committers:
        commit_ids = [commit.id for (commit, _) in committer['commits']]
        committer['commits'] = [
            serialized_commits_by_id[commit_id] for commit_id in commit_ids
        ]

    metrics.incr(
        'feature.owners.has-committers',
        instance='hit' if committers else 'miss',
        skip_internal=False,
    )
    return committers
Beispiel #4
0
    def test_simple(self):
        self.create_member(
            user=self.user,
            organization=self.organization,
            role='owner',
            teams=[self.team],
        )
        self.login_as(self.user)
        release = self.create_release(project=self.project, version='v12')

        self.repo = Repository.objects.create(
            organization_id=self.organization.id,
            name=self.organization.id,
        )
        commit_id = 'a' * 40
        release.set_commits([{
            'id':
            commit_id,
            'repository':
            self.repo.name,
            'author_email':
            '*****@*****.**',
            'author_name':
            'Bob',
            'message':
            'i fixed a bug',
            'patch_set': [{
                'path': 'src/sentry/models/release.py',
                'type': 'M'
            }]
        }])
        incident = self.create_incident(self.organization)
        commit = Commit.objects.get(releasecommit__release=release)
        IncidentSuspectCommit.objects.create(incident=incident,
                                             commit=commit,
                                             order=1)

        with self.feature('organizations:incidents'):
            resp = self.get_valid_response(
                self.organization.slug,
                incident.identifier,
            )
        assert len(resp.data) == 1
        suspect = resp.data[0]
        assert suspect['type'] == 'commit'
        assert suspect['data'] == serialize(commit,
                                            self.user,
                                            serializer=CommitSerializer())
    def test_simple(self):
        self.create_member(user=self.user,
                           organization=self.organization,
                           role="owner",
                           teams=[self.team])
        self.login_as(self.user)
        release = self.create_release(project=self.project, version="v12")

        self.repo = Repository.objects.create(
            organization_id=self.organization.id, name=self.organization.id)
        commit_id = "a" * 40
        release.set_commits([{
            "id":
            commit_id,
            "repository":
            self.repo.name,
            "author_email":
            "*****@*****.**",
            "author_name":
            "Bob",
            "message":
            "i fixed a bug",
            "patch_set": [{
                "path": "src/sentry/models/release.py",
                "type": "M"
            }],
        }])
        incident = self.create_incident(self.organization)
        commit = Commit.objects.get(releasecommit__release=release)
        IncidentSuspectCommit.objects.create(incident=incident,
                                             commit=commit,
                                             order=1)

        with self.feature("organizations:incidents"):
            resp = self.get_valid_response(self.organization.slug,
                                           incident.identifier)
        assert len(resp.data) == 1
        suspect = resp.data[0]
        assert suspect["type"] == "commit"
        assert suspect["data"] == serialize(commit,
                                            self.user,
                                            serializer=CommitSerializer())
Beispiel #6
0
    def get(self, request, organization, incident):
        """
        Fetches potential causes of an Incident.
        ````````````````````````````````````````
        Fetches potential causes of an Incident. Currently this is just suspect
        commits for all related Groups.
        :auth: required
        """

        # Only fetch suspects for projects that the user has access to
        projects = [
            project
            for project in incident.projects.all()
            if request.access.has_project_access(project)
        ]
        commits = list(get_incident_suspects(incident, projects))
        # These are just commits for the moment, just serialize them directly
        serialized_suspects = serialize(commits, request.user, serializer=CommitSerializer())

        # TODO: For now just hard coding this format. As we add in more formats
        # we'll handle this in a more robust way.
        return self.respond(
            [{"type": "commit", "data": suspect} for suspect in serialized_suspects]
        )