Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9347001
D8814.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Subscribers
None
D8814.diff
View Options
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
@@ -1202,7 +1202,7 @@
snapshot_context["snapshot_id"],
branches_from,
PER_PAGE + 1,
- target_types=["revision", "alias"],
+ target_types=["content", "directory", "revision", "alias"],
branch_name_include_substring=branch_name_include,
)
displayed_branches: List[Dict[str, Any]] = []
@@ -1211,23 +1211,33 @@
displayed_branches = [dict(branch) for branch in branches]
for branch in displayed_branches:
- rev_query_params = {}
+ query_params = {"snapshot": snapshot_id, "branch": branch["name"]}
if origin_info:
- rev_query_params["origin_url"] = origin_info["url"]
+ query_params["origin_url"] = origin_info["url"]
- revision_url = reverse(
- "browse-revision",
- url_args={"sha1_git": branch["target"]},
- query_params=query_params,
- )
-
- query_params["branch"] = branch["name"]
directory_url = reverse(
browse_view_name, url_args=url_args, query_params=query_params
)
- del query_params["branch"]
- branch["revision_url"] = revision_url
branch["directory_url"] = directory_url
+ del query_params["branch"]
+
+ if branch["target_type"] in ("directory", "revision"):
+ target_url = reverse(
+ f"browse-{branch['target_type']}",
+ url_args={"sha1_git": branch["target"]},
+ query_params=query_params,
+ )
+ elif branch["target_type"] == "content":
+ target_url = reverse(
+ "browse-content",
+ url_args={"query_string": f"sha1_git:{branch['target']}"},
+ query_params=query_params,
+ )
+ branch["target_url"] = target_url
+ branch["tooltip"] = (
+ f"The branch {branch['name']} targets "
+ f"{branch['target_type']} {branch['target']}"
+ )
if origin_info:
browse_view_name = "browse-origin-branches"
diff --git a/swh/web/browse/templates/browse-branches.html b/swh/web/browse/templates/browse-branches.html
--- a/swh/web/browse/templates/browse-branches.html
+++ b/swh/web/browse/templates/browse-branches.html
@@ -19,7 +19,7 @@
<thead>
<tr>
<th><i class="{{ swh_object_icons.branch }} mdi-fw" aria-hidden="true"></i>Name</th>
- <th>Revision</th>
+ <th>Target</th>
<th>Message</th>
<th>Date</th>
</tr>
@@ -38,9 +38,10 @@
{{ branch.name }}
</a>
</td>
- <td>
- <a href="{{ branch.revision_url }}">
- {{ branch.revision|slice:":7" }}
+ <td class="swh-branch-target">
+ <a href="{{ branch.target_url }}">
+ <i class="{{ swh_object_icons|key_value:branch.target_type }} mdi-fw"
+ aria-hidden="true" title="{{ branch.tooltip }}"></i>{{ branch.target|slice:":7" }}
</a>
</td>
<td class="swh-branch-message swh-table-cell-text-overflow" title="{{ branch.message }}">
diff --git a/swh/web/tests/browse/views/test_snapshot.py b/swh/web/tests/browse/views/test_snapshot.py
--- a/swh/web/tests/browse/views/test_snapshot.py
+++ b/swh/web/tests/browse/views/test_snapshot.py
@@ -125,25 +125,60 @@
)
-def test_snapshot_browse_branches(client, archive_data, origin):
- snapshot = archive_data.snapshot_get_latest(origin["url"])
+def test_snapshot_browse_branches_targeting_revisions(client, archive_data, origin):
+ _origin_branches_test_helper(client, archive_data, origin["url"])
- snapshot_sizes = archive_data.snapshot_count_branches(snapshot["id"])
- snapshot_content = process_snapshot_branches(snapshot)
- _origin_branches_test_helper(
- client, origin, snapshot_content, snapshot_sizes, snapshot_id=snapshot["id"]
+def test_snapshot_browse_branches_targeting_multiple_types(
+ client, archive_data, content_text, directory, revision
+):
+ snapshot = Snapshot(
+ branches={
+ b"content": SnapshotBranch(
+ target=hash_to_bytes(content_text["sha1_git"]),
+ target_type=TargetType.CONTENT,
+ ),
+ b"directory": SnapshotBranch(
+ target=hash_to_bytes(directory),
+ target_type=TargetType.DIRECTORY,
+ ),
+ b"revision": SnapshotBranch(
+ target=hash_to_bytes(revision),
+ target_type=TargetType.REVISION,
+ ),
+ },
+ )
+ archive_data.snapshot_add([snapshot])
+
+ origin_url = "https://git.example.org/user/project"
+ archive_data.origin_add([Origin(url=origin_url)])
+ date = now()
+ visit = OriginVisit(origin=origin_url, date=date, type="git")
+ visit = archive_data.origin_visit_add([visit])[0]
+ visit_status = OriginVisitStatus(
+ origin=origin_url,
+ visit=visit.visit,
+ date=date,
+ status="full",
+ snapshot=snapshot.id,
)
+ archive_data.origin_visit_status_add([visit_status])
+ _origin_branches_test_helper(client, archive_data, origin_url)
-def _origin_branches_test_helper(
- client, origin_info, origin_snapshot, snapshot_sizes, snapshot_id
-):
- query_params = {"origin_url": origin_info["url"], "snapshot": snapshot_id}
+
+def _origin_branches_test_helper(client, archive_data, origin_url):
+
+ snapshot = archive_data.snapshot_get_latest(origin_url)
+
+ snapshot_sizes = archive_data.snapshot_count_branches(snapshot["id"])
+ snapshot_content = process_snapshot_branches(snapshot)
+
+ query_params = {"origin_url": origin_url, "snapshot": snapshot["id"]}
url = reverse(
"browse-snapshot-branches",
- url_args={"snapshot_id": snapshot_id},
+ url_args={"snapshot_id": snapshot["id"]},
query_params=query_params,
)
@@ -151,12 +186,12 @@
client, url, status_code=200, template_used="browse-branches.html"
)
- origin_branches = origin_snapshot[0]
- origin_releases = origin_snapshot[1]
+ origin_branches = snapshot_content[0]
+ origin_releases = snapshot_content[1]
origin_branches_url = reverse("browse-origin-branches", query_params=query_params)
assert_contains(resp, f'href="{escape(origin_branches_url)}"')
- assert_contains(resp, f"Branches ({snapshot_sizes['revision']})")
+ assert_contains(resp, f"Branches ({snapshot_sizes['branch']})")
origin_releases_url = reverse("browse-origin-releases", query_params=query_params)
@@ -174,14 +209,29 @@
)
assert_contains(resp, '<a href="%s">' % escape(browse_branch_url))
- browse_revision_url = reverse(
- "browse-revision",
- url_args={"sha1_git": branch["target"]},
- query_params=query_params,
- )
- assert_contains(resp, '<a href="%s">' % escape(browse_revision_url))
+ if branch["target_type"] == "revision":
+ browse_revision_url = reverse(
+ "browse-revision",
+ url_args={"sha1_git": branch["target"]},
+ query_params=query_params,
+ )
+ assert_contains(resp, '<a href="%s">' % escape(browse_revision_url))
+ elif branch["target_type"] == "directory":
+ browse_directory_url = reverse(
+ "browse-directory",
+ url_args={"sha1_git": branch["target"]},
+ query_params=query_params,
+ )
+ assert_contains(resp, '<a href="%s">' % escape(browse_directory_url))
+ elif branch["target_type"] == "content":
+ browse_content_url = reverse(
+ "browse-content",
+ url_args={"query_string": f"sha1_git:{branch['target']}"},
+ query_params=query_params,
+ )
+ assert_contains(resp, '<a href="%s">' % escape(browse_content_url))
- _check_origin_link(resp, origin_info["url"])
+ _check_origin_link(resp, origin_url)
def _check_origin_link(resp, origin_url):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 3, 4:48 PM (3 w, 13 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221392
Attached To
D8814: browse: Update snapshot branches list view to display all target types
Event Timeline
Log In to Comment