Skip to content

Commit

Permalink
Do not split by dot, use version as is
Browse files Browse the repository at this point in the history
fix #83
  • Loading branch information
allburov committed Oct 21, 2022
1 parent 1603b92 commit 0d61e5f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
4 changes: 1 addition & 3 deletions artifactory_cleanup/rules/keep.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ def filter(self, artifacts):
artifacts.keep(artifact)

for artifactory_with_version in artifacts_by_path_and_name.values():
artifactory_with_version.sort(
key=lambda x: [int(x) for x in x[0].split(".")]
)
artifactory_with_version.sort()

artifact_count = len(artifactory_with_version)
good_artifact_count = artifact_count - self.count
Expand Down
36 changes: 36 additions & 0 deletions tests/test_rules_keep.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,40 @@ def test_regexp_fail_to_parse__must_keep_unmatched_files(self):
1, "[^\\d][\\._]((\\d+\\.)+\\d+)"
).filter(artifacts)
expected = []
assert remove_these == expected

def test_regexp_with_hyphen(self):
data = [
# bootstrap-gui
{
"path": "folder1",
"name": "bootstrap-gui-3.10-39.src.rpm",
"created": "2021-03-20T13:54:52.383+02:00",
},
{
"path": "folder1",
"name": "bootstrap-gui-3.10-33.src.rpm",
"created": "2021-03-20T13:54:52.383+02:00",
},
{
"path": "folder1",
"name": "bootstrap-gui-3.11-33.src.rpm",
"created": "2021-03-19T13:53:52.383+02:00",
},
{
"path": "folder1",
"name": "bootstrap-gui-4.11-33.src.rpm",
"created": "2021-03-20T13:54:52.383+02:00",
},
]

artifacts = ArtifactsList.from_response(data)

remove_these = KeepLatestVersionNFilesInFolder(
2, "bootstrap-gui-([\\d]+\\.[\\d]+\\-[\\d]+).*\\.rpm"
).filter(artifacts)
expected = [
{"name": "bootstrap-gui-3.10-39.src.rpm", "path": "folder1"},
{"name": "bootstrap-gui-3.10-33.src.rpm", "path": "folder1"},
]
assert makeas(remove_these, expected) == expected

0 comments on commit 0d61e5f

Please sign in to comment.