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 <nils@redhat.com>
This commit is contained in:
parent
12b90b22dd
commit
f2bea59f37
2 changed files with 69 additions and 38 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue