Skip to content
Open
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
8 changes: 5 additions & 3 deletions dockerhub_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def process_tags(tags, retention_days, global_preserve_last, preserve_rules):
If preserve_rules is empty, the global_preserve_last value is used.
Returns a list of tag dictionaries with additional computed fields.
"""
pull_cutoff = datetime.utcnow() - timedelta(days=retention_days)
retention_cutoff = datetime.utcnow() - timedelta(days=retention_days)
processed = []

# Parse dates once and build a new collection with computed fields.
Expand Down Expand Up @@ -100,8 +100,10 @@ def process_tags(tags, retention_days, global_preserve_last, preserve_rules):
reasons = []
if tag["name"] in preserved_reasons:
reasons.append(preserved_reasons[tag["name"]])
if tag["last_pulled_dt"] and tag["last_pulled_dt"] >= pull_cutoff:
if tag["last_pulled_dt"] and tag["last_pulled_dt"] >= retention_cutoff:
reasons.append(f"pulled within retention ({retention_days} days)")
if tag["last_updated_dt"] and tag["last_updated_dt"] >= retention_cutoff:
reasons.append(f"pushed within retention ({retention_days} days)")

if reasons:
tag["status"] = "PRESERVED"
Expand All @@ -111,7 +113,7 @@ def process_tags(tags, retention_days, global_preserve_last, preserve_rules):
if not tag["last_pulled_dt"]:
deletion_reasons.append("never pulled")
else:
deletion_reasons.append(f"not pulled since {pull_cutoff.isoformat()}")
deletion_reasons.append(f"not pulled since {retention_cutoff.isoformat()}")
tag["status"] = "TO DELETE"
tag["reason"] = ", ".join(deletion_reasons)

Expand Down