In the process of fixing the previous bug, I realised that:
a) /api/patches/msgid is a perfectly reasonable thing to attempt
b) We have no way of finding a patch by message id in the API
We can't actualy make /api/patches/msgid work because it may not
be unique, but we can add a filter.
I'm shoehorning this into stable/2.2, even though it's technically
an API change: it's minor, not incompatible and in hindsight a
glaring hole.
Cc: Michael Ellerman <mpe@ellerman.id.au>
Tested-by: Jeremy Kerr <jk@ozlabs.org>
Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
(cherry picked from commit
d08b6c72964898c9997a62e4ab6a721f166a56ca)
schema:
title: ''
type: string
+ - in: query
+ name: msgid
+ description: >
+ The cover message-id as a case-sensitive string, without leading or
+ trailing angle brackets, to filter by.
+ schema:
+ title: ''
+ type: string
responses:
'200':
description: ''
schema:
title: ''
type: string
+ - in: query
+ name: msgid
+ description: >
+ The patch message-id as a case-sensitive string, without leading or
+ trailing angle brackets, to filter by.
+ schema:
+ title: ''
+ type: string
responses:
'200':
description: ''
schema:
title: ''
type: string
+{% if version >= (1, 2) %}
+ - in: query
+ name: msgid
+ description: >
+ The cover message-id as a case-sensitive string, without leading or
+ trailing angle brackets, to filter by.
+ schema:
+ title: ''
+ type: string
+{% endif %}
responses:
'200':
description: ''
schema:
title: ''
type: string
+ - in: query
+ name: msgid
+ description: >
+ The patch message-id as a case-sensitive string, without leading or
+ trailing angle brackets, to filter by.
+ schema:
+ title: ''
+ type: string
{% endif %}
responses:
'200':
schema:
title: ''
type: string
+ - in: query
+ name: msgid
+ description: >
+ The cover message-id as a case-sensitive string, without leading or
+ trailing angle brackets, to filter by.
+ schema:
+ title: ''
+ type: string
responses:
'200':
description: ''
schema:
title: ''
type: string
+ - in: query
+ name: msgid
+ description: >
+ The patch message-id as a case-sensitive string, without leading or
+ trailing angle brackets, to filter by.
+ schema:
+ title: ''
+ type: string
responses:
'200':
description: ''
fields = ('submitter', 'project')
+def msgid_filter(queryset, name, value):
+ return queryset.filter(**{name: '<' + value + '>'})
+
+
class CoverLetterFilterSet(TimestampMixin, BaseFilterSet):
project = ProjectFilter(queryset=Project.objects.all(), distinct=False)
series = BaseFilter(queryset=Project.objects.all(),
widget=MultipleHiddenInput, distinct=False)
submitter = PersonFilter(queryset=Person.objects.all(), distinct=False)
+ msgid = CharFilter(method=msgid_filter)
class Meta:
model = CoverLetter
delegate = UserFilter(queryset=User.objects.all(), distinct=False)
state = StateFilter(queryset=State.objects.all(), distinct=False)
hash = CharFilter(lookup_expr='iexact')
+ msgid = CharFilter(method=msgid_filter)
class Meta:
model = Patch
- # NOTE(dja): ideally we want to version the hash field, but I cannot
- # find a way to do that which is reliable and not extremely ugly.
+ # NOTE(dja): ideally we want to version the hash/msgid field, but I
+ # can't find a way to do that which is reliable and not extremely ugly.
# The best I can come up with is manually working with request.GET
# which seems to rather defeat the point of using django-filters.
fields = ('project', 'series', 'submitter', 'delegate',
- 'state', 'archived', 'hash')
+ 'state', 'archived', 'hash', 'msgid')
versioned_fields = {
- '1.2': ('hash', ),
+ '1.2': ('hash', 'msgid'),
}
'submitter': 'test@example.org'})
self.assertEqual(0, len(resp.data))
+ def test_list_filter_msgid(self):
+ """Filter covers by msgid."""
+ cover = create_cover()
+
+ resp = self.client.get(self.api_url(), {'msgid': cover.url_msgid})
+ self.assertEqual([cover.id], [x['id'] for x in resp.data])
+
+ # empty response if nothing matches
+ resp = self.client.get(self.api_url(), {
+ 'msgid': 'fishfish@fish.fish'})
+ self.assertEqual(0, len(resp.data))
+
@utils.store_samples('cover-list-1-0')
def test_list_version_1_0(self):
create_cover()
{'hash': 'garbagevalue'})
self.assertEqual(1, len(resp.data))
+ def test_list_filter_msgid(self):
+ """Filter patches by msgid."""
+ patch = self._create_patch()
+
+ resp = self.client.get(self.api_url(), {'msgid': patch.url_msgid})
+ self.assertEqual([patch.id], [x['id'] for x in resp.data])
+
+ # empty response if nothing matches
+ resp = self.client.get(self.api_url(), {
+ 'msgid': 'fishfish@fish.fish'})
+ self.assertEqual(0, len(resp.data))
+
@utils.store_samples('patch-list-1-0')
def test_list_version_1_0(self):
"""List patches using API v1.0."""
--- /dev/null
+---
+api:
+ - |
+ The REST API now supports filtering patches and cover letters by message
+ ID, using the ``msgid`` query parameter. Don't include leading or trailing
+ angle brackets.