Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move release commits endpoint to organization path (#4863)
* move release commits endpoint to organization path * update changes * update changes * fix changes
- Loading branch information
Showing
6 changed files
with
112 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import absolute_import | ||
|
||
from sentry.api.base import DocSection | ||
from sentry.api.bases.organization import OrganizationReleasesBaseEndpoint | ||
from sentry.api.exceptions import ResourceDoesNotExist | ||
from sentry.api.serializers import serialize | ||
from sentry.models import Release, ReleaseCommit | ||
|
||
|
||
class OrganizationReleaseCommitsEndpoint(OrganizationReleasesBaseEndpoint): | ||
doc_section = DocSection.RELEASES | ||
|
||
def get(self, request, organization, version): | ||
""" | ||
List an Organization Release's Commits | ||
`````````````````````````````````````` | ||
Retrieve a list of commits for a given release. | ||
:pparam string organization_slug: the slug of the organization the | ||
release belongs to. | ||
:pparam string version: the version identifier of the release. | ||
:auth: required | ||
""" | ||
try: | ||
release = Release.objects.get( | ||
organization_id=organization.id, | ||
projects=self.get_allowed_projects(request, organization), | ||
version=version, | ||
) | ||
except Release.DoesNotExist: | ||
raise ResourceDoesNotExist | ||
|
||
queryset = ReleaseCommit.objects.filter( | ||
release=release, | ||
).select_related('commit', 'commit__author') | ||
|
||
return self.paginate( | ||
request=request, | ||
queryset=queryset, | ||
order_by='order', | ||
on_results=lambda x: serialize([rc.commit for rc in x], request.user), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/sentry/api/endpoints/test_organization_release_commits.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import absolute_import | ||
|
||
from django.core.urlresolvers import reverse | ||
|
||
from sentry.models import Commit, Release, ReleaseCommit, Repository | ||
from sentry.testutils import APITestCase | ||
|
||
|
||
class ReleaseCommitsListTest(APITestCase): | ||
def test_simple(self): | ||
project = self.create_project( | ||
name='foo', | ||
) | ||
release = Release.objects.create( | ||
organization_id=project.organization_id, | ||
version='1', | ||
) | ||
release.add_project(project) | ||
repo = Repository.objects.create( | ||
organization_id=project.organization_id, | ||
name=project.name, | ||
) | ||
commit = Commit.objects.create( | ||
organization_id=project.organization_id, | ||
repository_id=repo.id, | ||
key='a' * 40, | ||
) | ||
commit2 = Commit.objects.create( | ||
organization_id=project.organization_id, | ||
repository_id=repo.id, | ||
key='b' * 40, | ||
) | ||
ReleaseCommit.objects.create( | ||
organization_id=project.organization_id, | ||
release=release, | ||
commit=commit, | ||
order=1, | ||
) | ||
ReleaseCommit.objects.create( | ||
organization_id=project.organization_id, | ||
release=release, | ||
commit=commit2, | ||
order=0, | ||
) | ||
url = reverse('sentry-api-0-organization-release-commits', kwargs={ | ||
'organization_slug': project.organization.slug, | ||
'version': release.version, | ||
}) | ||
|
||
self.login_as(user=self.user) | ||
|
||
response = self.client.get(url) | ||
|
||
assert response.status_code == 200, response.content | ||
assert len(response.data) == 2 | ||
assert response.data[0]['id'] == commit2.key | ||
assert response.data[1]['id'] == commit.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters