[buildinfo.debian.net] 02/03: Add API endpoint to fetch specific .buildinfo files for a certain package/version/architecture (Closes: #25)
Chris Lamb
chris at chris-lamb.co.uk
Wed Oct 25 01:39:55 UTC 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository buildinfo.debian.net.
commit 3637b1a8cb8d54cae31364b0452465cea5e8c836
Author: Chris Lamb <lamby at debian.org>
Date: Tue Oct 24 20:12:51 2017 -0400
Add API endpoint to fetch specific .buildinfo files for a certain package/version/architecture (Closes: #25)
eg. /api/v1/sources/redis/3:3.2.5-6/amd64
---
bidb/packages/urls.py | 4 ++++
bidb/packages/views.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/bidb/packages/urls.py b/bidb/packages/urls.py
index b5c0967..17e9437 100644
--- a/bidb/packages/urls.py
+++ b/bidb/packages/urls.py
@@ -15,4 +15,8 @@ urlpatterns = (
name='source-version'),
url(r'^binaries/(?P<name>[^/]+)$', views.binary,
name='binary'),
+
+ url(r'^api/v1/sources/(?P<name>[^/]+)/(?P<version>[^/]+)/(?P<architecture>[^/]+)$',
+ views.api_source_version_architecture,
+ name='api-source-version-architecture'),
)
diff --git a/bidb/packages/views.py b/bidb/packages/views.py
index 7bb3514..5f755d6 100644
--- a/bidb/packages/views.py
+++ b/bidb/packages/views.py
@@ -1,9 +1,12 @@
-from django.http import Http404
+from django.conf import settings
+from django.http import Http404, JsonResponse
from django.shortcuts import render, get_object_or_404
from bidb.utils.itertools import groupby
from bidb.utils.paginator import AutoPaginator
+from bidb.buildinfo.buildinfo_submissions.models import Submission
+
from .models import Binary, Source
@@ -91,3 +94,45 @@ def binary(request, name):
'binary': binary,
'versions': versions,
})
+
+
+def api_source_version_architecture(request, name, version, architecture):
+ source = get_object_or_404(Source, name=name)
+
+ if not source.buildinfos.filter(version=version).exists():
+ raise Http404()
+
+ qs = Submission.objects.filter(
+ buildinfo__version=version,
+ buildinfo__architecture__name=architecture,
+ ).select_related(
+ 'key',
+ 'buildinfo',
+ ).order_by(
+ 'buildinfo__sha1',
+ 'created',
+ )
+
+ by_sha1 = [
+ {
+ 'uri': '{}{}'.format(
+ settings.SITE_URL,
+ xs[0].get_absolute_url(),
+ ),
+ 'sha1': sha1,
+ 'submissions': [{
+ 'key': {
+ 'uid': x.key.uid,
+ 'name': x.key.name,
+ },
+ 'created': x.created,
+ } for x in xs],
+ }
+ for sha1, xs in groupby(
+ qs,
+ lambda x: x.buildinfo.sha1,
+ lambda x: x.created,
+ )
+ ]
+
+ return JsonResponse({'by_sha1': by_sha1})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/buildinfo.debian.net.git
More information about the Reproducible-commits
mailing list