Skip to content

Commit

Permalink
Merge pull request #4831 from rtfd/filter-builds-by-commit
Browse files Browse the repository at this point in the history
Allow filtering builds by commit.
  • Loading branch information
ericholscher committed Oct 31, 2018
2 parents b9dfe95 + 85c4e50 commit 521afbe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/api/v2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Build list
:>json array results: Array of ``Build`` objects.

:query string project__slug: Narrow to builds for a specific ``Project``
:query string commit: Narrow to builds for a specific ``commit``

Build detail
++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/restapi/views/model_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class BuildViewSetBase(UserSelectViewSet):
serializer_class = BuildSerializer
admin_serializer_class = BuildAdminSerializer
model = Build
filter_fields = ('project__slug',)
filter_fields = ('project__slug', 'commit')


class BuildViewSet(SettingsOverrideObject):
Expand Down
16 changes: 16 additions & 0 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,22 @@ def test_get_invalid_raw_log(self):
resp = client.get('/api/v2/build/{0}.txt'.format(404))
self.assertEqual(resp.status_code, status.HTTP_404_NOT_FOUND)

def test_build_filter_by_commit(self):
"""
Create a build with commit
Should return the list of builds according to the
commit query params
"""
get(Build, project_id=1, version_id=1, builder='foo', commit='test')
get(Build, project_id=2, version_id=1, builder='foo', commit='other')
client = APIClient()
api_user = get(User, staff=False, password='test')
client.force_authenticate(user=api_user)
resp = client.get('/api/v2/build/', {'commit': 'test'}, format='json')
self.assertEqual(resp.status_code, 200)
build = resp.data
self.assertEqual(len(build['results']), 1)


class APITests(TestCase):
fixtures = ['eric.json', 'test_data.json']
Expand Down

0 comments on commit 521afbe

Please sign in to comment.