Example #1
0
    def test_simple(self):
        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",
        }])
        incident = self.create_incident(self.organization)
        commit = Commit.objects.get(releasecommit__release=release)
        IncidentSuspectCommit.objects.create(incident=incident,
                                             commit=commit,
                                             order=1)
        assert [commit] == list(get_incident_suspects(incident,
                                                      [self.project]))
        assert [] == list(get_incident_suspects(incident, []))
Example #2
0
    def test_simple(self):
        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',
            },
        ])
        incident = self.create_incident(self.organization)
        commit = Commit.objects.get(releasecommit__release=release)
        IncidentSuspectCommit.objects.create(incident=incident,
                                             commit=commit,
                                             order=1)
        assert [commit] == list(get_incident_suspects(incident,
                                                      [self.project]))
        assert [] == list(get_incident_suspects(incident, []))
Example #3
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)
        ]
        suspects = islice(get_incident_suspects(incident, projects), 10)

        # 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 suspects])
Example #4
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]
        )
Example #5
0
    def test_simple(self):
        release = self.create_release(project=self.project, version='v12')

        included_commits = set(
            [letter * 40 for letter in ('a', 'b', 'c', 'd')])
        commit_iter = iter(included_commits)

        event = self.store_event(
            data={
                'fingerprint': ['group-1'],
                'message': 'Kaboom!',
                'platform': 'python',
                'stacktrace': {
                    'frames': [{
                        "function": "handle_set_commits",
                        "abs_path": "/usr/src/sentry/src/sentry/tasks.py",
                        "module": "sentry.tasks",
                        "in_app": True,
                        "lineno": 30,
                        "filename": "sentry/tasks.py",
                    }, {
                        "function": "set_commits",
                        "abs_path":
                        "/usr/src/sentry/src/sentry/models/release.py",
                        "module": "sentry.models.release",
                        "in_app": True,
                        "lineno": 39,
                        "filename": "sentry/models/release.py",
                    }]
                },
                'release': release.version,
            },
            project_id=self.project.id,
        )
        group = event.group
        self.repo = Repository.objects.create(
            organization_id=self.organization.id,
            name=self.organization.id,
        )
        release.set_commits([
            {
                'id':
                next(commit_iter),
                'repository':
                self.repo.name,
                'author_email':
                '*****@*****.**',
                'author_name':
                'Bob',
                'message':
                'i fixed a bug',
                'patch_set': [
                    {
                        'path': 'src/sentry/models/release.py',
                        'type': 'M',
                    },
                ]
            },
            {
                'id':
                next(commit_iter),
                'repository':
                self.repo.name,
                'author_email':
                '*****@*****.**',
                'author_name':
                'Bob',
                'message':
                'i fixed a bug',
                'patch_set': [
                    {
                        'path': 'src/sentry/models/release.py',
                        'type': 'M',
                    },
                ]
            },
            {
                'id':
                next(commit_iter),
                'repository':
                self.repo.name,
                'author_email':
                '*****@*****.**',
                'author_name':
                'Ross',
                'message':
                'i fixed a bug',
                'patch_set': [
                    {
                        'path': 'src/sentry/models/release.py',
                        'type': 'M',
                    },
                ]
            },
        ])
        release_2 = self.create_release(project=self.project, version='v13')
        event_2 = self.store_event(
            data={
                'fingerprint': ['group-2'],
                'message': 'Kaboom!',
                'platform': 'python',
                'stacktrace': {
                    'frames': [
                        {
                            "function": "handle_set_commits",
                            "abs_path": "/usr/src/sentry/src/sentry/tasks.py",
                            "module": "sentry.tasks",
                            "in_app": True,
                            "lineno": 30,
                            "filename": "sentry/tasks.py",
                        },
                        {
                            "function": "set_commits",
                            "abs_path":
                            "/usr/src/sentry/src/sentry/models/group.py",
                            "module": "sentry.models.group",
                            "in_app": True,
                            "lineno": 39,
                            "filename": "sentry/models/group.py",
                        },
                    ],
                },
                'release': release_2.version,
            },
            project_id=self.project.id,
        )
        group_2 = event_2.group
        release_2.set_commits([
            {
                'id':
                next(commit_iter),
                'repository':
                self.repo.name,
                'author_email':
                '*****@*****.**',
                'author_name':
                'Hello',
                'message':
                'i fixed a bug',
                'patch_set': [
                    {
                        'path': 'src/sentry/models/group.py',
                        'type': 'M',
                    },
                ]
            },
        ])

        excluded_project = self.create_project()
        excluded_event = self.store_event(
            data={
                'fingerprint': ['group-3'],
                'message': 'Kaboom!',
                'platform': 'python',
                'stacktrace': {
                    'frames': [
                        {
                            "function": "set_commits",
                            "abs_path":
                            "/usr/src/sentry/src/sentry/models/event.py",
                            "module": "sentry.models.event",
                            "in_app": True,
                            "lineno": 39,
                            "filename": "sentry/models/event.py",
                        },
                    ],
                },
                'release': release_2.version,
            },
            project_id=excluded_project.id,
        )
        excluded_release = self.create_release(project=self.project,
                                               version='v9000')

        excluded_commit = 'e' * 40
        excluded_group = excluded_event.group
        excluded_release.set_commits([
            {
                'id':
                excluded_commit,
                'repository':
                self.repo.name,
                'author_email':
                '*****@*****.**',
                'author_name':
                'Hello',
                'message':
                'i fixed a bug',
                'patch_set': [
                    {
                        'path': 'src/sentry/models/event.py',
                        'type': 'M',
                    },
                ]
            },
        ])

        incident = self.create_incident(
            self.organization,
            groups=[group, group_2, excluded_group],
        )

        assert set(suspect['id'] for suspect in get_incident_suspects(
            incident,
            incident.projects.exclude(id=excluded_project.id),
        )) == included_commits