diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py --- a/swh/web/browse/snapshot_context.py +++ b/swh/web/browse/snapshot_context.py @@ -30,6 +30,7 @@ get_directory_entries, gen_directory_link, gen_revision_link, + gen_revision_url, request_content, gen_content_link, prepare_content_for_display, @@ -588,7 +589,24 @@ browse_view_name, url_args=url_args, query_params=release_query_params, ) - return SnapshotContext( + revision_info = None + if revision_id: + try: + revision_info = service.lookup_revision(revision_id) + except NotFoundExc: + pass + else: + revision_info["date"] = format_utc_iso_date(revision_info["date"]) + revision_info["committer_date"] = format_utc_iso_date( + revision_info["committer_date"] + ) + if revision_info["message"]: + message_lines = revision_info["message"].split("\n") + revision_info["message_header"] = message_lines[0] + else: + revision_info["message_header"] = "" + + snapshot_context = SnapshotContext( branch=branch_name, branches=branches, branches_url=branches_url, @@ -601,6 +619,7 @@ releases=releases, releases_url=releases_url, revision_id=revision_id, + revision_info=revision_info, root_directory=root_directory, snapshot_id=snapshot_id, snapshot_sizes=snapshot_sizes, @@ -609,6 +628,11 @@ visit_info=visit_info, ) + if revision_info: + revision_info["revision_url"] = gen_revision_url(revision_id, snapshot_context) + + return snapshot_context + def _build_breadcrumbs(snapshot_context: SnapshotContext, path: str): origin_info = snapshot_context["origin_info"] diff --git a/swh/web/common/typing.py b/swh/web/common/typing.py --- a/swh/web/common/typing.py +++ b/swh/web/common/typing.py @@ -75,7 +75,7 @@ class SnapshotContext(TypedDict): branch: Optional[str] - """optional branch name set when browsing snapshot int that scope""" + """optional branch name set when browsing snapshot in that scope""" branches: List[SnapshotBranchInfo] """list of snapshot branches (possibly truncated)""" branches_url: str @@ -89,15 +89,17 @@ query_params: QueryParameters """common query parameters when browsing snapshot content""" release: Optional[str] - """optional release name set when browsing snapshot int that scope""" + """optional release name set when browsing snapshot in that scope""" release_id: Optional[str] - """optional release identifier set when browsing snapshot int that scope""" + """optional release identifier set when browsing snapshot in that scope""" releases: List[SnapshotReleaseInfo] """list of snapshot releases (possibly truncated)""" releases_url: str """snapshot releases list browse URL""" revision_id: Optional[str] - """optional revision identifier set when browsing snapshot int that scope""" + """optional revision identifier set when browsing snapshot in that scope""" + revision_info: Optional[Dict[str, Any]] + """optional revision info set when browsing snapshot in that scope""" root_directory: Optional[str] """optional root directory identifier set when browsing snapshot content""" snapshot_id: str diff --git a/swh/web/templates/includes/content-display.html b/swh/web/templates/includes/content-display.html --- a/swh/web/templates/includes/content-display.html +++ b/swh/web/templates/includes/content-display.html @@ -1,5 +1,5 @@ {% comment %} -Copyright (C) 2017-2019 The Software Heritage developers +Copyright (C) 2017-2020 The Software Heritage developers See the AUTHORS file at the top-level directory of this distribution License: GNU Affero General Public License version 3, or any later version See top-level LICENSE file for more information @@ -7,6 +7,8 @@ {% load swh_templatetags %} +{% include "includes/revision-info.html" %} + {% if snapshot_context and snapshot_context.is_empty %} {% include "includes/empty-snapshot.html" %} {% else %} diff --git a/swh/web/templates/includes/directory-display.html b/swh/web/templates/includes/directory-display.html --- a/swh/web/templates/includes/directory-display.html +++ b/swh/web/templates/includes/directory-display.html @@ -1,10 +1,12 @@ {% comment %} -Copyright (C) 2017-2019 The Software Heritage developers +Copyright (C) 2017-2020 The Software Heritage developers See the AUTHORS file at the top-level directory of this distribution License: GNU Affero General Public License version 3, or any later version See top-level LICENSE file for more information {% endcomment %} +{% include "includes/revision-info.html" %} + {% if snapshot_context and snapshot_context.is_empty %} {% include "includes/empty-snapshot.html" %} {% elif dirs|length > 0 or files|length > 0 %} diff --git a/swh/web/templates/includes/revision-info.html b/swh/web/templates/includes/revision-info.html new file mode 100644 --- /dev/null +++ b/swh/web/templates/includes/revision-info.html @@ -0,0 +1,35 @@ +{% comment %} +Copyright (C) 2020 The Software Heritage developers +See the AUTHORS file at the top-level directory of this distribution +License: GNU Affero General Public License version 3, or any later version +See top-level LICENSE file for more information +{% endcomment %} + +{% if snapshot_context and snapshot_context.revision_id %} +
+
+ +
+ Tip revision: + + {{ snapshot_context.revision_id }} + + authored by {{ snapshot_context.revision_info.author.name }} + on {{ snapshot_context.revision_info.date }} +
+ {{ snapshot_context.revision_info.message_header }} +
+
+
+
+
+ + +
+
+{% endif %} \ No newline at end of file diff --git a/swh/web/tests/browse/test_snapshot_context.py b/swh/web/tests/browse/test_snapshot_context.py --- a/swh/web/tests/browse/test_snapshot_context.py +++ b/swh/web/tests/browse/test_snapshot_context.py @@ -13,6 +13,7 @@ get_snapshot_context, _get_release, ) +from swh.web.browse.utils import gen_revision_url from swh.web.common.identifiers import get_swh_persistent_id from swh.web.common.origin_visits import get_origin_visit, get_origin_visits from swh.web.common.typing import ( @@ -140,6 +141,7 @@ releases=releases, releases_url=releases_url, revision_id=revision_id, + revision_info=_get_revision_info(archive_data, revision_id), root_directory=root_directory, snapshot_id=snapshot, snapshot_sizes=snapshot_sizes, @@ -148,6 +150,11 @@ visit_info=None, ) + if revision_id: + expected["revision_info"]["revision_url"] = gen_revision_url( + revision_id, snapshot_context + ) + assert snapshot_context == expected _check_branch_release_revision_parameters( @@ -233,6 +240,7 @@ releases=releases, releases_url=releases_url, revision_id=revision_id, + revision_info=_get_revision_info(archive_data, revision_id), root_directory=root_directory, snapshot_id=snapshot, snapshot_sizes=snapshot_sizes, @@ -241,6 +249,11 @@ visit_info=visit_info, ) + if revision_id: + expected["revision_info"]["revision_url"] = gen_revision_url( + revision_id, snapshot_context + ) + assert snapshot_context == expected _check_branch_release_revision_parameters( @@ -269,8 +282,14 @@ expected_branch = dict(base_expected_context) expected_branch["branch"] = branch["name"] expected_branch["revision_id"] = branch["revision"] + expected_branch["revision_info"] = _get_revision_info( + archive_data, branch["revision"] + ) expected_branch["root_directory"] = branch["directory"] expected_branch["query_params"] = {"branch": branch["name"], **query_params} + expected_branch["revision_info"]["revision_url"] = gen_revision_url( + branch["revision"], expected_branch + ) assert snapshot_context == expected_branch @@ -288,8 +307,14 @@ expected_release["release_id"] = release["id"] if release["target_type"] == "revision": expected_release["revision_id"] = release["target"] + expected_release["revision_info"] = _get_revision_info( + archive_data, release["target"] + ) expected_release["root_directory"] = release["directory"] expected_release["query_params"] = {"release": release["name"], **query_params} + expected_release["revision_info"]["revision_url"] = gen_revision_url( + release["target"], expected_release + ) assert snapshot_context == expected_release @@ -328,8 +353,14 @@ expected_revision["branch"] = revision["id"] expected_revision["branches"] = branches expected_revision["revision_id"] = revision["id"] + expected_revision["revision_info"] = _get_revision_info( + archive_data, revision["id"] + ) expected_revision["root_directory"] = revision["directory"] expected_revision["query_params"] = {"revision": revision["id"], **query_params} + expected_revision["revision_info"]["revision_url"] = gen_revision_url( + revision["id"], expected_revision + ) assert snapshot_context == expected_revision @@ -353,3 +384,15 @@ assert release_data["name"] == release["name"] assert release_data["id"] == release["id"] + + +def _get_revision_info(archive_data, revision_id): + revision_info = None + if revision_id: + revision_info = archive_data.revision_get(revision_id) + revision_info["message_header"] = revision_info["message"].split("\n")[0] + revision_info["date"] = format_utc_iso_date(revision_info["date"]) + revision_info["committer_date"] = format_utc_iso_date( + revision_info["committer_date"] + ) + return revision_info