Add dry run support for tags after a terrible fatal accident

This commit is contained in:
Salt 2025-01-24 17:04:32 -06:00
parent 055011441a
commit 57e7f84c64

View File

@ -7,8 +7,14 @@ from django.db import models
class Command(BaseCommand):
help = "Runs tagging rules against every release in the database"
def add_arguments(self, parser):
parser.add_argument("--dry-run", action="store_true", help="Preview changes instead of actually committing them")
def handle(self, *args, **options):
self.stdout.write('Tagging releases...')
if options['dry_run']:
self.stdout.write('Dry-running tagging rules...')
else:
self.stdout.write('Tagging releases...')
updates = 0
ignores = 0
failures = []
@ -25,11 +31,14 @@ class Command(BaseCommand):
continue
if taggingrule.required_tag and not taggingrule.required_tag in release.tags.all():
continue
if taggingrule.channel_regex and not re.match(taggingrule.channel_regex, release.channel.handle):
continue
if taggingrule.tag in release.tags.all():
ignores += 1
continue
self.stdout.write(f'Release "{str(release)}" matched rule "{str(taggingrule)}" for tag "{str(taggingrule.tag)}"')
release.tags.add(taggingrule.tag)
if not options['dry_run']:
release.tags.add(taggingrule.tag)
updates += 1
except Exception as e:
self.stdout.write(self.style.WARNING(f'Failed to apply rule {str(taggingrule.name)}: {e}'))