[PATCH] REST: allow fetching of subject prefixes (categories)

Stephen Finucane stephen at that.guru
Tue Feb 14 01:51:25 AEDT 2017


On Sat, 2017-02-11 at 21:55 +1100, Daniel Axtens wrote:
> Some mailing lists accept patches for multiple projects, and use
> a subject prefix to differentiate the projects.

A couple of comments on this starting with this one: should we not be
considering patches like this as belonging to a different 'Project' in
Patchwork? If we don't do already support something, maybe we should?

Could you provide an example of a mailing list that does this?

> Therefore, for snowpatch, it's useful to be able to fetch the
> subject prefixes. Snowpatch calls these 'categories', so lets
> adopt their terminology.
> 
> Export categeories in the REST API.
> 
> Signed-off-by: Daniel Axtens <dja at axtens.net>
> ---
>  patchwork/api/patch.py | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
> index 1a7be584d0be..5536c41079b8 100644
> --- a/patchwork/api/patch.py
> +++ b/patchwork/api/patch.py
> @@ -31,6 +31,7 @@ from patchwork.api.base import PatchworkPermission
>  from patchwork.api.filters import PatchFilter
>  from patchwork.models import Patch
>  from patchwork.models import State
> +from patchwork.parser import clean_subject
>  
>  
>  def format_state_name(state):
> @@ -76,6 +77,10 @@ class
> PatchListSerializer(HyperlinkedModelSerializer):
>      tags = SerializerMethodField()
>      check = SerializerMethodField()
>      checks = SerializerMethodField()
> +    categories = SerializerMethodField()
> +
> +    def get_categories(self, instance):
> +        return clean_subject(instance.name)[1]

This is going to run for 'page_size' patches on the list operation. I
don't know how expensive each run is but seeing as there are regexes
involved I doubt it's free. I wonder if we should access this via a
'cached_property' field on 'Submission'?

>      def get_mbox(self, instance):
>          request = self.context.get('request')
> @@ -100,10 +105,10 @@ class
> PatchListSerializer(HyperlinkedModelSerializer):
>          fields = ('id', 'url', 'project', 'msgid', 'date', 'name',
>                    'commit_ref', 'pull_url', 'state', 'archived',
> 'hash',
>                    'submitter', 'delegate', 'mbox', 'series',
> 'check', 'checks',
> -                  'tags')
> +                  'tags', 'categories')

I'm not sure about 'categories' - this will also return things like the
version ('v2') and the number of the patch if it's in a series ('1/5'),
correct? Labels might be more valid, if so (though I had planned to use
that name for a more significant feature in v2.1 or so [1]).

>          read_only_fields = ('project', 'msgid', 'date', 'name',
> 'hash',
>                              'submitter', 'mbox', 'mbox', 'series',
> 'check',
> -                            'checks', 'tags')
> +                            'checks', 'tags', 'categories')

Do we want to be able to filter on these? I don't know if you can do
this for non-model fields though...

>          extra_kwargs = {
>              'url': {'view_name': 'api-patch-detail'},
>              'project': {'view_name': 'api-project-detail'},

Stephen

[1] https://github.com/getpatchwork/patchwork/issues/22


More information about the Patchwork mailing list