Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7124279
D39.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D39.diff
View Options
diff --git a/swh/web/ui/backend.py b/swh/web/ui/backend.py
--- a/swh/web/ui/backend.py
+++ b/swh/web/ui/backend.py
@@ -183,6 +183,36 @@
return main.storage().revision_log([sha1_git_bin], limit)
+def revision_log_by(origin_id, branch_name, ts, limit=100):
+ """Return information about the revision matching the timestamp
+ ts, from origin origin_id, in branch branch_name.
+
+ Args:
+ origin_id: origin of the revision
+ - branch_name: revision's branch.
+ - timestamp: revision's time frame.
+
+ Returns:
+ Information for the revision matching the criterions.
+
+ """
+ # Disable pending RemoteStorage opening revision_log_by
+ """
+ if not ts and branch_name == 'refs/heads/master':
+ return main.storage().revision_log_by(origin_id)
+ """
+
+ rev = main.storage().revision_get_by(origin_id,
+ branch_name,
+ timestamp=ts,
+ limit=1)
+ if not rev:
+ return None
+
+ rev_sha1s_bin = [revision['id'] for revision in rev]
+ return main.storage().revision_log(rev_sha1s_bin, limit)
+
+
def stat_counters():
"""Return the stat counters for Software Heritage
diff --git a/swh/web/ui/tests/test_backend.py b/swh/web/ui/tests/test_backend.py
--- a/swh/web/ui/tests/test_backend.py
+++ b/swh/web/ui/tests/test_backend.py
@@ -454,6 +454,62 @@
self.storage.revision_log.assert_called_with([sha1_bin], 100)
@istest
+ def revision_log_by(self):
+ # given
+ # given
+ sha1_bin = hashutil.hex_to_hash(
+ '28d8be353ed3480476f032475e7c233eff7371d5')
+ stub_revision_log = [{
+ 'id': sha1_bin,
+ 'directory': hashutil.hex_to_hash(
+ '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6'),
+ 'author': {
+ 'name': b'bill & boule',
+ 'email': b'bill@boule.org',
+ },
+ 'committer': {
+ 'name': b'boule & bill',
+ 'email': b'boule@bill.org',
+ },
+ 'message': b'elegant fix for bug 31415957',
+ 'date': datetime.datetime(2000, 1, 17, 11, 23, 54),
+ 'date_offset': 0,
+ 'committer_date': datetime.datetime(2000, 1, 17, 11, 23, 54),
+ 'committer_date_offset': 0,
+ 'synthetic': False,
+ 'type': 'git',
+ 'parents': [],
+ 'metadata': [],
+ }]
+
+ self.storage.revision_get_by = MagicMock(return_value=[
+ {'id': sha1_bin}])
+ self.storage.revision_log = MagicMock(return_value=stub_revision_log)
+
+ # when
+ actual_log = backend.revision_log_by(1, 'refs/heads/master', None)
+
+ # then
+ self.assertEqual(actual_log, stub_revision_log)
+ self.storage.revision_log.assert_called_with([sha1_bin], 100)
+
+ @istest
+ def revision_log_by_norev(self):
+ # given
+ # given
+ sha1_bin = hashutil.hex_to_hash(
+ '28d8be353ed3480476f032475e7c233eff7371d5')
+
+ self.storage.revision_get_by = MagicMock(return_value=None)
+
+ # when
+ actual_log = backend.revision_log_by(1, 'refs/heads/master', None)
+
+ # then
+ self.assertEqual(actual_log, None)
+ self.storage.revision_log.assert_called_with([sha1_bin], 100)
+
+ @istest
def stat_counters(self):
# given
input_stats = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Dec 21 2024, 4:26 AM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218639
Attached To
D39: T288 - Open /api/1/revision/origin/<origin_id>/[branch/<branch_name>][ts/<ts>]/log/
Event Timeline
Log In to Comment