diff --git a/repo_cloner/lib/detector.py b/repo_cloner/lib/detector.py index 55f0ce0..b1b9db2 100644 --- a/repo_cloner/lib/detector.py +++ b/repo_cloner/lib/detector.py @@ -75,6 +75,7 @@ class Detector: _executed: DiskStoredList = None _branches: DiskStoredRefs = None _tags: DiskStoredRefs = None + _project: str = None def __init__(self, repo_path: Path, cache_dir: Path, project: str): log.debug(f"Initializing detector...") @@ -87,6 +88,8 @@ class Detector: log.debug(f"Creating detector dir") self._detector_dir.mkdir() + self._project = project + log.debug(f"Detector cache: {self._detector_dir}") self._executed = DiskStoredList(self._detector_dir.joinpath("detectorExecuted").as_posix()) log.debug(f"Detector executed: {len(self._executed)} commits") @@ -225,7 +228,17 @@ class Detector: 'log': commit.message, } env = DetectedCommit(env) + log.info(f"Executing CI: commit {self._project}: {env.commit} @ {env.date} by {env.author}") + if env.is_tag or env.is_branch: + log.info(f"Additional info: branch: {env.branches}; tag(s) {env.tags}") executed_count += 1 callback(env) + # mark commit done + self._executed.append(commit.hexsha) + for item in special_branch: + self._branches.update(item, commit.hexsha) + for item in special_tag: + self._tags.update(item, commit.hexsha) + self.persist_fingerprint() return executed_count diff --git a/tests/lib/test_detector.py b/tests/lib/test_detector.py index df2e6df..8bc860d 100644 --- a/tests/lib/test_detector.py +++ b/tests/lib/test_detector.py @@ -1,6 +1,6 @@ import logging -from repo_cloner.lib import Detector, DetectedCommit +from repo_cloner.lib import Detector, DetectedCommit, DiskStoredList, DiskStoredRefs import pytest from unittest.mock import patch, MagicMock, PropertyMock from git import Actor @@ -368,3 +368,13 @@ def test_run(tmp_path, caplog): assert any(ex.tags == 'v1001' for ex in executed) assert any(ex.branches == 'master' for ex in executed) assert all(ex.commit not in commits_old or ex.is_tag for ex in executed) + + # new commits persisted? + commits = DiskStoredList(cache_dir.joinpath("detector", "detectorExecuted").as_posix()) + for commit in commits_new: + assert commit in commits + + refs = DiskStoredRefs(cache_dir.joinpath("detector", "tags")) + for tag, commit in tags_new.items(): + assert commit == refs.get(tag) +