Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/release.py
# Copyright (C) 2017-2019 The Software Heritage developers | # Copyright (C) 2017-2019 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 django.shortcuts import render | from django.shortcuts import render | ||||
import sentry_sdk | |||||
from swh.web.common import service | from swh.web.common import service | ||||
from swh.web.common.utils import ( | from swh.web.common.utils import ( | ||||
reverse, format_utc_iso_date | reverse, format_utc_iso_date | ||||
) | ) | ||||
from swh.web.common.exc import NotFoundExc, handle_view_exception | from swh.web.common.exc import NotFoundExc, handle_view_exception | ||||
from swh.web.browse.browseurls import browse_route | from swh.web.browse.browseurls import browse_route | ||||
from swh.web.browse.utils import ( | from swh.web.browse.utils import ( | ||||
Show All 22 Lines | try: | ||||
if not origin_url: | if not origin_url: | ||||
origin_url = request.GET.get('origin', None) | origin_url = request.GET.get('origin', None) | ||||
timestamp = request.GET.get('timestamp', None) | timestamp = request.GET.get('timestamp', None) | ||||
visit_id = request.GET.get('visit_id', None) | visit_id = request.GET.get('visit_id', None) | ||||
if origin_url: | if origin_url: | ||||
try: | try: | ||||
snapshot_context = get_snapshot_context( | snapshot_context = get_snapshot_context( | ||||
snapshot_id, origin_url, timestamp, visit_id) | snapshot_id, origin_url, timestamp, visit_id) | ||||
except Exception: | except NotFoundExc: | ||||
raw_rel_url = reverse('browse-release', | raw_rel_url = reverse('browse-release', | ||||
url_args={'sha1_git': sha1_git}) | url_args={'sha1_git': sha1_git}) | ||||
error_message = \ | error_message = \ | ||||
('The Software Heritage archive has a release ' | ('The Software Heritage archive has a release ' | ||||
'with the hash you provided but the origin ' | 'with the hash you provided but the origin ' | ||||
'mentioned in your request appears broken: %s. ' | 'mentioned in your request appears broken: %s. ' | ||||
'Please check the URL and try again.\n\n' | 'Please check the URL and try again.\n\n' | ||||
'Nevertheless, you can still browse the release ' | 'Nevertheless, you can still browse the release ' | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if release['target_type'] == 'revision': | ||||
try: | try: | ||||
revision = service.lookup_revision(release['target']) | revision = service.lookup_revision(release['target']) | ||||
vault_cooking = { | vault_cooking = { | ||||
'directory_context': True, | 'directory_context': True, | ||||
'directory_id': revision['directory'], | 'directory_id': revision['directory'], | ||||
'revision_context': True, | 'revision_context': True, | ||||
'revision_id': release['target'] | 'revision_id': release['target'] | ||||
} | } | ||||
except Exception: | except Exception as exc: | ||||
pass | sentry_sdk.capture_exception(exc) | ||||
elif release['target_type'] == 'directory': | elif release['target_type'] == 'directory': | ||||
target_link = gen_directory_link(release['target'], | target_link = gen_directory_link(release['target'], | ||||
snapshot_context=snapshot_context, | snapshot_context=snapshot_context, | ||||
link_text=None, link_attrs=None) | link_text=None, link_attrs=None) | ||||
try: | try: | ||||
revision = service.lookup_directory(release['target']) | revision = service.lookup_directory(release['target']) | ||||
vault_cooking = { | vault_cooking = { | ||||
'directory_context': True, | 'directory_context': True, | ||||
'directory_id': revision['directory'], | 'directory_id': revision['directory'], | ||||
'revision_context': False, | 'revision_context': False, | ||||
'revision_id': None | 'revision_id': None | ||||
} | } | ||||
except Exception: | except Exception as exc: | ||||
pass | sentry_sdk.capture_exception(exc) | ||||
elif release['target_type'] == 'content': | elif release['target_type'] == 'content': | ||||
target_link = gen_content_link(release['target'], | target_link = gen_content_link(release['target'], | ||||
snapshot_context=snapshot_context, | snapshot_context=snapshot_context, | ||||
link_text=None, link_attrs=None) | link_text=None, link_attrs=None) | ||||
elif release['target_type'] == 'release': | elif release['target_type'] == 'release': | ||||
target_link = gen_release_link(release['target'], | target_link = gen_release_link(release['target'], | ||||
snapshot_context=snapshot_context, | snapshot_context=snapshot_context, | ||||
link_text=None, link_attrs=None) | link_text=None, link_attrs=None) | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |