From 28eb8a81e10577dcddf3a779c17ba17c4a7345c9 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Apr 28 2021 10:41:27 +0000 Subject: PR#2817: koji-gc: Implement hastag policy for koji-gc Merges #2817 https://pagure.io/koji/pull-request/2817 Fixes: #2813 https://pagure.io/koji/issue/2813 RFE: koji-gc: hastag policy --- diff --git a/docs/source/utils.rst b/docs/source/utils.rst index c10c38d..ea07967 100644 --- a/docs/source/utils.rst +++ b/docs/source/utils.rst @@ -168,6 +168,7 @@ comments. # stuff to protect # note that tags with master lock engaged are already protected tag *-updates :: keep + hastag no-gc :: skip age < 1 day :: skip sig fedora-gold :: skip sig fedora-test && age < 12 weeks :: keep diff --git a/util/koji-gc b/util/koji-gc index fe9be82..01260f4 100755 --- a/util/koji-gc +++ b/util/koji-gc @@ -776,6 +776,18 @@ class AgePruneTest(koji.policy.BaseSimpleTest): return self.func(time.time() - data['ts'], self.span) +class HasTagPruneTest(koji.policy.BaseSimpleTest): + name = 'hastag' + + def run(self, data): + patterns = self.str.split()[1:] + for tag in data['tags']: + for pattern in patterns: + if fnmatch.fnmatch(tag['name'], pattern): + return True + return False + + def read_policies(fn=None): """Read tag gc policies from file @@ -907,6 +919,7 @@ def handle_prune(): data['keys'] = LazyValue(get_build_sigs, (entry['build_id'],), {'cache': True}) data['volname'] = LazyValue(lambda x: session.getBuild(x).get('volume_name'), (entry['build_id'],), cache=True) + data['tags'] = LazyValue(session.listTags, (entry['build_id'],), cache=True) build_ids[nvr] = entry['build_id'] action = policies.apply(data) if action is None: