diff --git a/swh/web/browse/views/release.py b/swh/web/browse/views/release.py --- a/swh/web/browse/views/release.py +++ b/swh/web/browse/views/release.py @@ -94,6 +94,7 @@ vault_cooking = None + rev_directory = None target_link = None if release['target_type'] == 'revision': target_link = gen_revision_link(release['target'], @@ -101,9 +102,10 @@ link_text=None, link_attrs=None) try: revision = service.lookup_revision(release['target']) + rev_directory = revision['directory'] vault_cooking = { 'directory_context': True, - 'directory_id': revision['directory'], + 'directory_id': rev_directory, 'revision_context': True, 'revision_id': release['target'] } @@ -114,10 +116,10 @@ snapshot_context=snapshot_context, link_text=None, link_attrs=None) try: - revision = service.lookup_directory(release['target']) + service.lookup_directory(release['target']) vault_cooking = { 'directory_context': True, - 'directory_id': revision['directory'], + 'directory_id': release['target'], 'revision_context': False, 'revision_id': None } @@ -132,6 +134,27 @@ snapshot_context=snapshot_context, link_text=None, link_attrs=None) + rev_directory_url = None + if rev_directory is not None: + if origin_info: + rev_directory_url = reverse( + 'browse-origin-directory', + url_args={'origin_url': origin_info['url']}, + query_params={'release': release['name']}) + elif snapshot_id: + rev_directory_url = reverse( + 'browse-snapshot-directory', + url_args={'snapshot_id': snapshot_id}, + query_params={'release': release['name']}) + else: + rev_directory_url = reverse( + 'browse-directory', + url_args={'sha1_git': rev_directory}) + + directory_link = None + if rev_directory_url is not None: + directory_link = gen_link(rev_directory_url, rev_directory) + release['directory_link'] = directory_link release['target_link'] = target_link if snapshot_context: diff --git a/swh/web/templates/browse/release.html b/swh/web/templates/browse/release.html --- a/swh/web/templates/browse/release.html +++ b/swh/web/templates/browse/release.html @@ -21,5 +21,10 @@
Target: {{ release.target_link}} + {% if release.directory_link %} +
+ Directory: + {{ release.directory_link}} + {% endif %}
{% endblock %} diff --git a/swh/web/tests/browse/views/test_release.py b/swh/web/tests/browse/views/test_release.py --- a/swh/web/tests/browse/views/test_release.py +++ b/swh/web/tests/browse/views/test_release.py @@ -25,7 +25,7 @@ resp = client.get(url) - _release_browse_checks(resp, release_data) + _release_browse_checks(resp, release_data, archive_data) @given(origin_with_releases()) @@ -41,7 +41,7 @@ resp = client.get(url) - _release_browse_checks(resp, release_data, origin) + _release_browse_checks(resp, release_data, archive_data, origin) @given(unknown_release()) @@ -69,7 +69,7 @@ assert resp['location'] == redirect_url -def _release_browse_checks(resp, release_data, origin_info=None): +def _release_browse_checks(resp, release_data, archive_data, origin_info=None): query_params = {} if origin_info: query_params['origin'] = origin_info['url'] @@ -102,3 +102,16 @@ swh_rel_id_url = reverse('browse-swh-id', url_args={'swh_id': swh_rel_id}) assert_contains(resp, swh_rel_id) assert_contains(resp, swh_rel_id_url) + + if release_data['target_type'] == 'revision': + if origin_info: + directory_url = reverse( + 'browse-origin-directory', + url_args={'origin_url': origin_info['url']}, + query_params={'release': release_data['name']}) + else: + rev = archive_data.revision_get(release_data['target']) + directory_url = reverse( + 'browse-directory', + url_args={'sha1_git': rev['directory']}) + assert_contains(resp, directory_url)