Skip to content

Commit

Permalink
add: FilterByRegexpPath (#158)
Browse files Browse the repository at this point in the history
* add: FilterByRegexpPath

* Apply suggestions from code review

---------

Co-authored-by: allburov <allburov@gmail.com>
  • Loading branch information
Stunkymonkey and allburov authored Feb 6, 2025
1 parent 4a3cf4b commit c382ebe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ policies:
- "*.zip"
```

- `FilterByRegexpPath` - delete artifacts whose path matches the specified regexp

```yaml
- rule: DeleteByRegexpPath
path: "\d"
```

## Create your own rule

If you want to create your own rule, you can do it!
Expand Down
17 changes: 16 additions & 1 deletion artifactory_cleanup/rules/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from artifactory_cleanup.rules.utils import to_masks
from artifactory_cleanup.rules.base import Rule
from artifactory_cleanup.rules.base import ArtifactsList, Rule


class FilterRule(Rule):
Expand Down Expand Up @@ -68,3 +68,18 @@ class ExcludeFilename(FilterRule):
attribute_name = "name"
operator = "$nmatch"
boolean_operator = "$and"


class FilterByRegexpPath(Rule):
"""
Filter artifacts paths by regex pattern.
"""

def init(self, path):
self.path = rf"{path}"

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

0 comments on commit c382ebe

Please sign in to comment.