Skip to content

Commit

Permalink
Add search_fields attribute to Summary class
Browse files Browse the repository at this point in the history
This commit adds the `search_fields` attribute to the Summary class.
The `search_fields` attribute can be accessed to retrieve the last item
search related fields.

Signed-off-by: Jose Javier Merchante <jjmerchante@bitergia.com>
  • Loading branch information
jjmerchante committed Mar 12, 2024
1 parent 7d2f566 commit d93332b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions perceval/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ def __init__(self):
self.max_offset = None
self.last_offset = None
self.extras = None
self.last_search_fields = None

@property
def total(self):
Expand All @@ -1061,6 +1062,8 @@ def update(self, item):
self.min_offset = offset if self.min_offset is None else min(self.min_offset, offset)
self.max_offset = offset if self.max_offset is None else max(self.max_offset, offset)

self.last_search_fields = item.get('search_fields', None)


def uuid(*args):
"""Generate a UUID based on the given parameters.
Expand Down
12 changes: 12 additions & 0 deletions releases/unreleased/include-recovery-mode-for-git-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Include recovery mode for Git backend
category: added
author: null
issue: null
notes: >
Include a new option in Git that allows continuing
to fetch commits from the previous execution using the last
commit. The option is `--recovery <commit>`.
The last commit can be obtained from the summary object
of the last execution or the last item.
7 changes: 6 additions & 1 deletion tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,7 @@ def test_init(self):
self.assertIsNone(summary.max_offset)
self.assertIsNone(summary.last_offset)
self.assertIsNone(summary.extras)
self.assertIsNone(summary.last_search_fields)

def test_update(self):
"""Test whether the method update properly works"""
Expand All @@ -1899,7 +1900,8 @@ def test_update(self):
},
{
"updated_on": 1483228700.0,
"uuid": "0fa16dc4edab9130a14914a8d797f634d13b4bb4"
"uuid": "0fa16dc4edab9130a14914a8d797f634d13b4bb4",
"search_fields": {"item_id": "08c2fc9c870c704a9e778db582f1ac98063f3198"}
}
]

Expand All @@ -1917,6 +1919,7 @@ def test_update(self):
self.assertIsNone(summary.min_offset)
self.assertIsNone(summary.max_offset)
self.assertIsNone(summary.last_offset)
self.assertIsNone(summary.last_search_fields)

item = items[1]
summary.update(item)
Expand All @@ -1930,6 +1933,7 @@ def test_update(self):
self.assertIsNone(summary.min_offset)
self.assertIsNone(summary.max_offset)
self.assertIsNone(summary.last_offset)
self.assertIsNone(summary.last_search_fields)

item = items[2]
summary.update(item)
Expand All @@ -1943,6 +1947,7 @@ def test_update(self):
self.assertIsNone(summary.min_offset)
self.assertIsNone(summary.max_offset)
self.assertIsNone(summary.last_offset)
self.assertDictEqual(summary.last_search_fields, item['search_fields'])

def test_update_offset(self):
"""Test whether the method update properly works on offset attributes"""
Expand Down

0 comments on commit d93332b

Please sign in to comment.