From f2bea59f37b192e5bda345eed562b083aede1574 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Nov 25 2019 09:42:04 +0000 Subject: allow configuring products for branches by regex This is in order not to have to hard code EPEL. In the course, reorganize how products and their correspondent versions and component namespaces are configured. Signed-off-by: Nils Philippsen --- diff --git a/distgit_bugzilla_sync/default-config-files/configuration.toml b/distgit_bugzilla_sync/default-config-files/configuration.toml index 8ce9d16..4c3fb12 100644 --- a/distgit_bugzilla_sync/default-config-files/configuration.toml +++ b/distgit_bugzilla_sync/default-config-files/configuration.toml @@ -7,21 +7,19 @@ Reassigning to the new maintainer of this component. """ [products] - "Fedora" = "Fedora" - "Fedora Container" = "Fedora Container Images" - "Fedora Modules" = "Fedora Modules" - "Fedora EPEL" = "Fedora EPEL" - -[products_versions] - "Fedora" = ["rawhide", "31", "30", "29"] - "Fedora Container" = ["rawhide", "29"] - "Fedora Modules" = [] - "Fedora EPEL" = ["epel8", "epel7", "el6"] - -[namespace_to_product] - "rpms" = "Fedora" # except EPEL... - "container" = "Fedora Container" - "modules" = "Fedora Modules" + [products.Fedora] + namespace = "rpms" + versions = ["rawhide", "31", "30", "29"] + [products."Fedora Container"] + namespace = "container" + versions = ["rawhide", "29"] + bz_product_name = "Fedora Container Images" + [products."Fedora Modules"] + namespace = "modules" + versions = [] + [products."Fedora EPEL"] + branch_regex = '^epel\d+$' + versions = ["epel8", "epel7", "el6"] [pdc_types] "rpms" = "rpm" diff --git a/distgit_bugzilla_sync/script.py b/distgit_bugzilla_sync/script.py index 2f0d154..d78bce6 100644 --- a/distgit_bugzilla_sync/script.py +++ b/distgit_bugzilla_sync/script.py @@ -248,7 +248,7 @@ class BugzillaProxy: 'NEW', 'ASSIGNED', 'ON_DEV', 'ON_QA', 'MODIFIED', 'POST', 'FAILS_QA', 'PASSES_QA', 'RELEASE_PENDING'] # Update only maintained releases - bz_query['version'] = self.config["products_versions"][product] + bz_query['version'] = self.config["products"][product]["versions"] query_results = self.server.query(bz_query) @@ -409,11 +409,14 @@ class BugzillaProxy: ) else: if self.config.get("print-no-change"): - print(f"[NOCHANGE] {package}/{self.config['products'][collection]}") + bz_product_name = self.config['products'][collection].get( + 'bz_product_name', collection + ) + print(f"[NOCHANGE] {package}/{bz_product_name}") else: # Add component data = { - 'product': self.config['products'][collection], + 'product': self.config['products'][collection].get('bz_product_name', collection), 'component': package, 'description': description or 'NA', 'initialowner': owner_email, @@ -473,22 +476,6 @@ def _get_pdc_branches(session, repo): return [branch['name'] for branch in data['results']] -def _is_retired(product, project): - branches = project['branches'] - if product == 'Fedora EPEL': - for branch, active in branches: - if re.match(r'^epel\d+$', branch): - if active: - return False - # No active branches means it is retired. - return True - else: - for branch, active in branches: - if active: - return False - return True - - class ScriptExecError(RuntimeError): def __init__(self, *args, **kwargs): @@ -498,6 +485,11 @@ class ScriptExecError(RuntimeError): class DistgitBugzillaSync: + # cache placeholders for properties which are computed once + _namespace_to_product = None + _product_to_branch_regex = None + _branch_regex_to_product = None + def send_email(self, from_address, to_address, subject, message, cc_address=None): '''Send an email if there's an error. @@ -652,6 +644,45 @@ class DistgitBugzillaSync: watchers=pagure_namespace_to_cc[namespace][name], )) + @property + def namespace_to_product(self): + if self._namespace_to_product is None: + self._namespace_to_product = { + p['namespace']: n + for n, p in self.env['products'].items() if 'namespace' in p + } + return self._namespace_to_product + + @property + def product_to_branch_regex(self): + if self._product_to_branch_regex is None: + self._product_to_branch_regex = { + n: re.compile(p['branch_regex']) + for n, p in self.env['products'].items() if 'branch_regex' in p + } + return self._product_to_branch_regex + + @property + def branch_regex_to_product(self): + if self._branch_regex_to_product is None: + self._branch_regex_to_product = {n: r for r, n in self.product_to_branch_regex.items()} + return self._branch_regex_to_product + + def _is_retired(self, product, project): + branches = project['branches'] + branch_regex = self.product_to_branch_regex.get(product) + if branch_regex: + for branch, active in branches: + if branch_regex.match(branch) and active: + return False + # No active branches means it is retired. + return True + else: + for branch, active in branches: + if active: + return False + return True + def add_branches_products_and_summaries(self): """ For each project retrieved, this method adds branches, products and summary information. @@ -699,17 +730,19 @@ class DistgitBugzillaSync: # Products products = set() for branch, active in project.get('branches'): - if re.match(r'^epel\d+$', branch): - products.add('Fedora EPEL') + for regex, product in self.branch_regex_to_product.items(): + if regex.match(branch): + products.add(product) + break else: - products.add(self.env['namespace_to_product'][project['namespace']]) + products.add(self.namespace_to_product[project['namespace']]) project['products'] = list(products) products_poc = {} for product in products: owner = project["poc"] # Check if the project is retired in PDC, and if so set assignee to orphan. - if _is_retired(product, project): + if self._is_retired(product, project): owner = 'orphan' # Check if the Bugzilla ticket assignee has been manually overridden