Skip to content

Commit

Permalink
api: Expose events
Browse files Browse the repository at this point in the history
One interesting thing to be doing is polling for new events on a
project. Right now, the only event is series-new-revision, so listening
to events is really just listening to series creation and update.

This is quite useful for testing infrastructures, knowing when a series
is ready to be tested so a bot can retrieve its patches and test them.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
  • Loading branch information
Damien Lespiau committed Oct 20, 2015
1 parent 7f201e2 commit fc695d5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
51 changes: 51 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,60 @@ Patches
"content": "<diff content>"
}

Events
~~~~~~

.. http:get:: /api/1.0/projects/(string: linkname)/events/
.. http:get:: /api/1.0/projects/(int: project_id)/events/
List of events for this project.

.. sourcecode:: http

GET /api/1.0/patches/120/ HTTP/1.1
Accept: application/json

.. sourcecode:: http

HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept
Allow: GET, HEAD, OPTIONS

{
"count": 23,
"next": "http://127.0.0.1:8000/api/1.0/events/?page=2",
"previous": null,
"results": [
{
"name": "series-new-revision",
"event_time": "2015-10-20T19:49:49.494",
"series": 23,
"user": null
},
{
"name": "series-new-revision",
"event_time": "2015-10-20T19:49:43.895",
"series": 22,
"user": null
}
]
}

At the moment, only one event is listed:

- **series-new-revision**: This event corresponds to patchwork receiving a
full new revision of a series, should it be the initial submission of
subsequent updates. The difference can be made by looking at the version of
the series.

API Revisions
~~~~~~~~~~~~~

**Revision 1**

- Add /projects/${linkname}/events/ entry point.

**Revision 0**

- Initial revision. Basic objects exposed: api root, projects, series,
Expand Down
8 changes: 7 additions & 1 deletion patchwork/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from django.contrib.auth.models import User
from patchwork.models import Project, Series, SeriesRevision, Patch, Person, \
State
State, EventLog
from rest_framework import serializers
from enum import Enum

Expand Down Expand Up @@ -131,3 +131,9 @@ class Meta:
expand_serializers = {
'patches': PatchSerializer,
}

class EventLogSerializer(serializers.ModelSerializer):
name = serializers.CharField(source='event.name', read_only=True)
class Meta:
model = EventLog
fields = ('name', 'event_time', 'series', 'user')
5 changes: 5 additions & 0 deletions patchwork/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
series_list_router = routers.NestedSimpleRouter(project_router, 'projects',
lookup='project')
series_list_router.register(r'series', api.SeriesListViewSet)
# /projects/$project/events/
event_router = routers.NestedSimpleRouter(project_router, 'projects',
lookup='project')
event_router.register(r'events', api.EventLogViewSet)
# /series/$id/
series_router = routers.SimpleRouter()
series_router.register(r'series', api.SeriesViewSet)
Expand All @@ -56,6 +60,7 @@
(r'^api/1.0/', include(series_router.urls)),
(r'^api/1.0/', include(revisions_router.urls)),
(r'^api/1.0/', include(patches_router.urls)),
(r'^api/1.0/', include(event_router.urls)),

# project view:
(r'^$', 'patchwork.views.projects'),
Expand Down
23 changes: 20 additions & 3 deletions patchwork/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

from patchwork.models import Project, Series, SeriesRevision, Patch
from patchwork.models import Project, Series, SeriesRevision, Patch, EventLog
from rest_framework import views, viewsets, mixins, generics, filters, permissions
from rest_framework.decorators import api_view, renderer_classes, \
permission_classes
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
from rest_framework.generics import get_object_or_404
from patchwork.serializers import ProjectSerializer, SeriesSerializer, \
RevisionSerializer, PatchSerializer
RevisionSerializer, PatchSerializer, \
EventLogSerializer


API_REVISION = 0
API_REVISION = 1

class MaintainerPermission(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
Expand Down Expand Up @@ -125,3 +126,19 @@ class PatchViewSet(mixins.ListModelMixin,
permission_classes = (MaintainerPermission, )
queryset = Patch.objects.all()
serializer_class = PatchSerializer

class EventLogViewSet(mixins.ListModelMixin,
ListMixin,
viewsets.GenericViewSet):
permission_classes = (MaintainerPermission, )
queryset = EventLog.objects.all()
serializer_class = EventLogSerializer

def get_queryset(self):

pk = self.kwargs['project_pk']
if is_integer(pk):
queryset = self.queryset.filter(series__project__pk=pk)
else:
queryset = self.queryset.filter(series__project__linkname=pk)
return queryset

0 comments on commit fc695d5

Please sign in to comment.