From d93332b3bb4c1ec340cb602150832eefab8d6fd0 Mon Sep 17 00:00:00 2001 From: Jose Javier Merchante Date: Thu, 7 Mar 2024 09:29:23 +0100 Subject: [PATCH] Add search_fields attribute to Summary class 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 --- perceval/backend.py | 3 +++ .../include-recovery-mode-for-git-backend.yml | 12 ++++++++++++ tests/test_backend.py | 7 ++++++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 releases/unreleased/include-recovery-mode-for-git-backend.yml diff --git a/perceval/backend.py b/perceval/backend.py index 555303d76..43e67e520 100644 --- a/perceval/backend.py +++ b/perceval/backend.py @@ -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): @@ -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. diff --git a/releases/unreleased/include-recovery-mode-for-git-backend.yml b/releases/unreleased/include-recovery-mode-for-git-backend.yml new file mode 100644 index 000000000..d5113c473 --- /dev/null +++ b/releases/unreleased/include-recovery-mode-for-git-backend.yml @@ -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 `. + + The last commit can be obtained from the summary object + of the last execution or the last item. diff --git a/tests/test_backend.py b/tests/test_backend.py index 01803789b..f673327ce 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -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""" @@ -1899,7 +1900,8 @@ def test_update(self): }, { "updated_on": 1483228700.0, - "uuid": "0fa16dc4edab9130a14914a8d797f634d13b4bb4" + "uuid": "0fa16dc4edab9130a14914a8d797f634d13b4bb4", + "search_fields": {"item_id": "08c2fc9c870c704a9e778db582f1ac98063f3198"} } ] @@ -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) @@ -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) @@ -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"""