Skip to content

Commit 3eae8f5

Browse files
authored
API: add ?full_name= icontains filter on RemoteRepository (#10551)
* API: add `?full_name=` icontains filter on RemoteRepository This allows to perform queries like: * http://devthedocs.org/api/v3/remote/repositories/?full_name=getnikola * http://devthedocs.org/api/v3/remote/repositories/?full_name=readthedocs&expand=projects Closes #10513 * API: add test case for `?full_name=` filter * Docs: update APIv3 query parameters to add `full_name`
1 parent 28274b4 commit 3eae8f5

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

docs/user/api/v3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,7 @@ Remote repository listing
18521852
The ``results`` in response is an array of remote repositories data.
18531853

18541854
:query string name: return remote repositories containing the name
1855+
:query string full_name: return remote repositories containing the full name (it inclues the username/organization the project belongs to)
18551856
:query string vcs_provider: return remote repositories for specific vcs provider (``github``, ``gitlab`` or ``bitbucket``)
18561857
:query string organization: return remote repositories for specific remote organization (using remote organization ``slug``)
18571858
:query string expand: allows to add/expand some extra fields in the response.

readthedocs/api/v3/filters.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,17 @@ def get_running(self, queryset, name, value):
6060

6161

6262
class RemoteRepositoryFilter(filters.FilterSet):
63-
name = filters.CharFilter(field_name='name', lookup_expr='icontains')
64-
organization = filters.CharFilter(field_name='organization__slug')
63+
name = filters.CharFilter(field_name="name", lookup_expr="icontains")
64+
full_name = filters.CharFilter(field_name="full_name", lookup_expr="icontains")
65+
organization = filters.CharFilter(field_name="organization__slug")
6566

6667
class Meta:
6768
model = RemoteRepository
6869
fields = [
69-
'name',
70-
'vcs_provider',
71-
'organization',
70+
"name",
71+
"full_name",
72+
"vcs_provider",
73+
"organization",
7274
]
7375

7476

readthedocs/api/v3/tests/test_remoterepositories.py

+16
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,19 @@ def test_remote_repository_list_name_filter(self):
103103
response_data,
104104
self._get_response_dict('remoterepositories-list'),
105105
)
106+
107+
def test_remote_repository_list_full_name_filter(self):
108+
self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}")
109+
response = self.client.get(
110+
reverse("remoterepositories-list"),
111+
{"expand": ("projects," "remote_organization"), "full_name": "proj"},
112+
)
113+
self.assertEqual(response.status_code, 200)
114+
115+
response_data = response.json()
116+
self.assertEqual(len(response_data["results"]), 1)
117+
118+
self.assertDictEqual(
119+
response_data,
120+
self._get_response_dict("remoterepositories-list"),
121+
)

0 commit comments

Comments
 (0)