From 9dbdfdccdc8c8a55ecd7d291dc6337abd1b601fb Mon Sep 17 00:00:00 2001 From: root Date: Sat, 23 Sep 2023 19:37:12 +0300 Subject: [PATCH 1/3] Added a rule for removing artifacts by redex --- artifactory_cleanup/rules/delete.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/artifactory_cleanup/rules/delete.py b/artifactory_cleanup/rules/delete.py index 4c48989..e3f0621 100644 --- a/artifactory_cleanup/rules/delete.py +++ b/artifactory_cleanup/rules/delete.py @@ -1,7 +1,8 @@ from datetime import timedelta +import re from artifactory_cleanup.rules import utils -from artifactory_cleanup.rules.base import Rule +from artifactory_cleanup.rules.base import ArtifactsList, Rule class DeleteOlderThan(Rule): @@ -102,3 +103,23 @@ def filter(self, artifacts): repositories = utils.build_repositories(artifacts) folders = utils.get_empty_folders(repositories) return folders + + +class DeleteByRegex(Rule): + """ + Remove artifacts by regex pattern. + """ + + def __init__(self, regex_pattern): + self.regex_pattern = rf"{regex_pattern}" + + def aql_add_filter(self, filters): + print(filters) + print(type(filters)) + return filters + + def filter(self, artifacts: ArtifactsList) -> ArtifactsList: + for val in artifacts[:]: + if re.match(self.regex_pattern, val["name"]) is None: + artifacts.remove(val) + return artifacts \ No newline at end of file From 2e52de276cdc5db8967ebcde37f01f5b1e2fd6ca Mon Sep 17 00:00:00 2001 From: Hardar Date: Sat, 30 Sep 2023 22:52:18 +0300 Subject: [PATCH 2/3] Fix conversations --- README.md | 7 +++++++ artifactory_cleanup/rules/delete.py | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e724dd..62bcb3d 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,13 @@ policies: - rule: DeleteEmptyFolders ``` +- `DeleteByRegexpName` - delete artifacts whose name matches the specified regexp + +```yaml +- rule: DeleteByRegexpName + regex_pattern: "\d" +``` + ## Keep - `KeepLatestNFiles` - Leaves the last (by creation time) files in the amount of N pieces. WITHOUT accounting diff --git a/artifactory_cleanup/rules/delete.py b/artifactory_cleanup/rules/delete.py index e3f0621..0392a71 100644 --- a/artifactory_cleanup/rules/delete.py +++ b/artifactory_cleanup/rules/delete.py @@ -105,7 +105,7 @@ def filter(self, artifacts): return folders -class DeleteByRegex(Rule): +class DeleteByRegexpName(Rule): """ Remove artifacts by regex pattern. """ @@ -114,8 +114,7 @@ def __init__(self, regex_pattern): self.regex_pattern = rf"{regex_pattern}" def aql_add_filter(self, filters): - print(filters) - print(type(filters)) + print("Here's filters that we get\n", filters) return filters def filter(self, artifacts: ArtifactsList) -> ArtifactsList: From 8546f832eb94fd337a41297f013e4bc9b8808cf5 Mon Sep 17 00:00:00 2001 From: Hardar Date: Sat, 30 Sep 2023 22:55:37 +0300 Subject: [PATCH 3/3] Fix artifact naming --- artifactory_cleanup/rules/delete.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/artifactory_cleanup/rules/delete.py b/artifactory_cleanup/rules/delete.py index 0392a71..fa76994 100644 --- a/artifactory_cleanup/rules/delete.py +++ b/artifactory_cleanup/rules/delete.py @@ -118,7 +118,7 @@ def aql_add_filter(self, filters): return filters def filter(self, artifacts: ArtifactsList) -> ArtifactsList: - for val in artifacts[:]: - if re.match(self.regex_pattern, val["name"]) is None: - artifacts.remove(val) + for artifact in artifacts[:]: + if re.match(self.regex_pattern, artifact["name"]) is None: + artifacts.remove(artifact) return artifacts \ No newline at end of file