Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/revision.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 typing import Optional | from typing import Optional | ||||
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from rest_framework.request import Request | from rest_framework.request import Request | ||||
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.api.views.utils import api_lookup | ||||
from swh.web.utils import archive | from swh.web.utils import archive, graphql | ||||
DOC_RETURN_REVISION = """ | DOC_RETURN_REVISION = """ | ||||
:>json object author: information about the author of the revision | :>json object author: information about the author of the revision | ||||
:>json object committer: information about the committer of the | :>json object committer: information about the committer of the | ||||
revision | revision | ||||
:>json string committer_date: RFC3339 representation of the commit date | :>json string committer_date: RFC3339 representation of the commit date | ||||
:>json string date: RFC3339 representation of the revision date | :>json string date: RFC3339 representation of the revision date | ||||
:>json string directory: the unique identifier that revision points to | :>json string directory: the unique identifier that revision points to | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | .. http:get:: /api/1/revision/(sha1_git)/ | ||||
:statuscode 404: requested revision can not be found in the archive | :statuscode 404: requested revision can not be found in the archive | ||||
**Example:** | **Example:** | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`revision/aafb16d69fd30ff58afdd69036a26047f3aebdc6/` | :swh_web_api:`revision/aafb16d69fd30ff58afdd69036a26047f3aebdc6/` | ||||
""" | """ | ||||
return api_lookup( | query = """ | ||||
archive.lookup_revision, | query GetRevision($swhid: SWHID!) { | ||||
sha1_git, | revision(swhid: $swhid) { | ||||
notfound_msg="Revision with sha1_git {} not found.".format(sha1_git), | date | ||||
enrich_fn=utils.enrich_revision, | id | ||||
} | |||||
} | |||||
""" | |||||
return graphql.get_one( | |||||
query, | |||||
{"swhid": f"swh:1:rev:{sha1_git}"}, | |||||
query_root="revision", | |||||
enrich=utils.enrich_revision, | |||||
error_msg=f"Revision with sha1_git {sha1_git} not found.", | |||||
request=request, | request=request, | ||||
) | ) | ||||
@api_route( | @api_route( | ||||
r"/revision/(?P<sha1_git>[0-9a-f]+)/raw/", | r"/revision/(?P<sha1_git>[0-9a-f]+)/raw/", | ||||
"api-1-revision-raw-message", | "api-1-revision-raw-message", | ||||
checksum_args=["sha1_git"], | checksum_args=["sha1_git"], | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |