fix accessing product info from configuration

Previously, the `products` dict mapped product names in Fedora to their
Bugzilla counter parts. Now that all information pertaining products is
in this dictionary, the Bugzilla product name (if differing) is in the
bz_product_name sub-key.

Rename some variables to make their purpose a little more obvious, and
not use `product` for two different things (names and the informational
dictionary stored in the product cache).

fixes: #32

Signed-off-by: Nils Philippsen <nils@redhat.com>
This commit is contained in:
Nils Philippsen 2019-11-25 13:49:05 +01:00
parent 9283999992
commit 743b3aaca3

View file

@ -162,26 +162,27 @@ class BugzillaProxy:
# Old API -- in python-bugzilla. But with current server, this
# gives ProxyError
for collection, product in self.config["products"].items():
self.product_cache[collection] = self.server.getcomponentsdetails(product)
bz_product_name = product.get('bz_product_name', collection)
self.product_cache[collection] = self.server.getcomponentsdetails(bz_product_name)
elif self.config['bugzilla']['compat_api'] == 'component.get':
# Way that's undocumented in the partner-bugzilla api but works
# currently
for collection, product in self.config["products"].items():
bz_product_name = product.get('bz_product_name', collection)
# restrict the list of info returned to only the packages of
# interest
pkglist = [
project["name"]
for project in pagure_projects
if product in project["products"]
if bz_product_name in project["products"]
]
products = {}
product_info_by_pkg = {}
for pkg_segment in segment(pkglist, self.config['bugzilla']['req_segment']):
# Format that bugzilla will understand. Strip None's that
# segment() pads out the final data segment() with
query = [
dict(
product=self.config['products'][collection],
product=bz_product_name,
component=p
)
for p in pkg_segment
@ -191,14 +192,14 @@ class BugzillaProxy:
for package in raw_data['components']:
# Reformat data to be the same as what's returned from
# getcomponentsdetails
product = dict(
product_info = dict(
initialowner=package['default_assignee'],
description=package['description'],
initialqacontact=package['default_qa_contact'],
initialcclist=package['default_cc']
)
products[package['name'].lower()] = product
self.product_cache[collection] = products
product_info_by_pkg[package['name'].lower()] = product_info
self.product_cache[collection] = product_info_by_pkg
def invert_user_cache(self):
""" Takes the user_cache built when querying FAS and invert it so
@ -314,6 +315,8 @@ class BugzillaProxy:
e.args = ('ProtocolError', e.errcode, e.errmsg)
raise
bz_product_name = self.config['products'][collection].get('bz_product_name', collection)
# Set the qacontact_email and name
default_qa_contact_email = self.config['default_qa_contact_email']
default_qa_contact = f"<default: {default_qa_contact_email.split('@', 1)[0]}@...>"
@ -350,7 +353,7 @@ class BugzillaProxy:
if data:
# Changes occurred. Submit a request to change via xmlrpc
data['product'] = self.config['products'][collection]
data['product'] = bz_product_name
data['component'] = package
if self.config["verbose"]:
@ -414,16 +417,12 @@ class BugzillaProxy:
new_poc=owner_email,
prev_poc=product[pkg_key]['initialowner'],
name=package,
product=self.config['products'][collection],
product=bz_product_name,
)
else:
if self.config.get("print-no-change"):
bz_product_name = self.config['products'][collection].get(
'bz_product_name', collection
)
print(f"[NOCHANGE] {package}/{bz_product_name}")
else:
bz_product_name = self.config['products'][collection].get('bz_product_name', collection)
if retired:
if self.config['verbose']:
print(f"[NOADD] {bz_product_name}/{package} (is retired)")