Skip to content

Commit

Permalink
Include the path when grouping images for KeepLatestNVersionImagesByP…
Browse files Browse the repository at this point in the history
…roperty (#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>
  • Loading branch information
kenny-monster and pre-commit-ci[bot] authored Mar 6, 2023
1 parent 785b88f commit 018dcdb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion artifactory_cleanup/rules/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_rules_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand Down

0 comments on commit 018dcdb

Please sign in to comment.