Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/release.py
# Copyright (C) 2015-2022 The Software Heritage developers | # Copyright (C) 2015-2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from rest_framework.request import Request | from rest_framework.request import Request | ||||
from swh.model.hashutil import hash_to_bytes | |||||
from swh.model.swhids import CoreSWHID, ObjectType | |||||
from swh.web.api import utils | from swh.web.api import utils | ||||
from swh.web.api.apidoc import api_doc, format_docstring | from swh.web.api.apidoc import api_doc, format_docstring | ||||
from swh.web.api.apiurls import api_route | from swh.web.api.apiurls import api_route | ||||
from swh.web.api.views.utils import api_lookup | from swh.web.utils import graphql | ||||
from swh.web.utils import archive | |||||
@api_route( | @api_route( | ||||
r"/release/(?P<sha1_git>[0-9a-f]+)/", "api-1-release", checksum_args=["sha1_git"] | r"/release/(?P<sha1_git>[0-9a-f]+)/", "api-1-release", checksum_args=["sha1_git"] | ||||
) | ) | ||||
@api_doc("/release/", category="Archive") | @api_doc("/release/", category="Archive") | ||||
@format_docstring() | @format_docstring() | ||||
def api_release(request: Request, sha1_git: str): | def api_release(request: Request, sha1_git: str): | ||||
Show All 26 Lines | .. http:get:: /api/1/release/(sha1_git)/ | ||||
:statuscode 404: requested release can not be found in the archive | :statuscode 404: requested release can not be found in the archive | ||||
**Example:** | **Example:** | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`release/208f61cc7a5dbc9879ae6e5c2f95891e270f09ef/` | :swh_web_api:`release/208f61cc7a5dbc9879ae6e5c2f95891e270f09ef/` | ||||
""" | """ | ||||
error_msg = "Release with sha1_git %s not found." % sha1_git | query = """ | ||||
return api_lookup( | query GetRelease($swhid: SWHID!) { | ||||
archive.lookup_release, | release(swhid: $swhid) { | ||||
sha1_git, | date | ||||
notfound_msg=error_msg, | id | ||||
enrich_fn=utils.enrich_release, | } | ||||
} | |||||
""" | |||||
return graphql.get_one( | |||||
query, | |||||
{"swhid": f"swh:1:rel:{sha1_git}"}, | |||||
query_root="release", | |||||
enrich=utils.enrich_release, | |||||
error_msg=f"Release with {sha1_git} not found.", | |||||
request=request, | request=request, | ||||
) | ) |