From 018dcdb9c637db5210fa1d8f15a7df5288a2fee1 Mon Sep 17 00:00:00 2001 From: kenny-monster <92762804+kenny-monster@users.noreply.github.com> Date: Mon, 6 Mar 2023 15:00:38 +1100 Subject: [PATCH] Include the path when grouping images for KeepLatestNVersionImagesByProperty (#97) * fix: consider path when grouping * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test: add a second image * test: use the correct order --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- artifactory_cleanup/rules/docker.py | 5 ++++- tests/test_rules_docker.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/artifactory_cleanup/rules/docker.py b/artifactory_cleanup/rules/docker.py index 14756ad..d0cadf8 100644 --- a/artifactory_cleanup/rules/docker.py +++ b/artifactory_cleanup/rules/docker.py @@ -229,7 +229,10 @@ def filter(self, artifacts): def _groupby(artifact): """Group by major/minor/patch version""" - return self.get_version(artifact)[: self.number_of_digits_in_version] + return ( + artifact["path"], + self.get_version(artifact)[: self.number_of_digits_in_version], + ) # Group artifacts by major/minor or patch grouped = pydash.group_by(artifacts, iteratee=_groupby) diff --git a/tests/test_rules_docker.py b/tests/test_rules_docker.py index b8315a7..23e53be 100644 --- a/tests/test_rules_docker.py +++ b/tests/test_rules_docker.py @@ -48,6 +48,21 @@ def test_filter(self): "path": "foobar/2.1.1", "name": "manifest.json", }, + { + "properties": {"docker.manifest": "0.1.86"}, + "path": "baz/0.1.86", + "name": "manifest.json", + }, + { + "properties": {"docker.manifest": "0.1.87"}, + "path": "baz/0.1.87", + "name": "manifest.json", + }, + { + "properties": {"docker.manifest": "0.1.83"}, + "path": "baz/0.1.83", + "name": "manifest.json", + }, ] artifacts = ArtifactsList.from_response(data) policy = CleanupPolicy( @@ -60,6 +75,12 @@ def test_filter(self): ), ) assert policy.filter(artifacts) == [ + { + "name": "0.1.83", + "path": "baz", + "properties": {"docker.manifest": "0.1.83"}, + "stats": {}, + }, { "name": "0.1.99", "path": "foobar",