Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a rule for removing artifacts by regex #118

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion artifactory_cleanup/rules/delete.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -102,3 +103,22 @@ def filter(self, artifacts):
repositories = utils.build_repositories(artifacts)
folders = utils.get_empty_folders(repositories)
return folders


class DeleteByRegexpName(Rule):
"""
Remove artifacts by regex pattern.
Hardar3 marked this conversation as resolved.
Show resolved Hide resolved
"""

def __init__(self, regex_pattern):
self.regex_pattern = rf"{regex_pattern}"

def aql_add_filter(self, filters):
print("Here's filters that we get\n", filters)
return filters

def filter(self, artifacts: ArtifactsList) -> ArtifactsList:
for artifact in artifacts[:]:
if re.match(self.regex_pattern, artifact["name"]) is None:
artifacts.remove(artifact)
return artifacts
Loading