Convert bugzilla email back into username when possible
Basically we have a mapping username -> email, so we can build the opposite one email -> username which we can then use to try to translate bugzilla email back into FAS accounts. This assumes bugzilla_email is unique (which it should). Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
This commit is contained in:
parent
0e74c819ef
commit
cd9696f0cb
1 changed files with 45 additions and 9 deletions
|
@ -121,7 +121,9 @@ class BugzillaProxy:
|
||||||
url=self.bz_xmlrpc_server,
|
url=self.bz_xmlrpc_server,
|
||||||
user=self.username,
|
user=self.username,
|
||||||
password=self.password)
|
password=self.password)
|
||||||
|
|
||||||
self.product_cache = {}
|
self.product_cache = {}
|
||||||
|
self.inverted_user_cache = {}
|
||||||
|
|
||||||
# Connect to the fedora account system
|
# Connect to the fedora account system
|
||||||
self.fas = AccountSystem(
|
self.fas = AccountSystem(
|
||||||
|
@ -187,6 +189,14 @@ class BugzillaProxy:
|
||||||
products[package['name'].lower()] = product
|
products[package['name'].lower()] = product
|
||||||
self.product_cache[collection] = products
|
self.product_cache[collection] = products
|
||||||
|
|
||||||
|
def invert_user_cache(self):
|
||||||
|
""" Takes the user_cache built when querying FAS and invert it so
|
||||||
|
that the bugzilla_email is the key and the username the value.
|
||||||
|
"""
|
||||||
|
for username in self.user_cache:
|
||||||
|
bz_email = self.user_cache[username]['bugzilla_email'].lower()
|
||||||
|
self.inverted_user_cache[bz_email] = username
|
||||||
|
|
||||||
def _get_bugzilla_email(self, username):
|
def _get_bugzilla_email(self, username):
|
||||||
'''Return the bugzilla email address for a user.
|
'''Return the bugzilla email address for a user.
|
||||||
|
|
||||||
|
@ -194,7 +204,7 @@ class BugzillaProxy:
|
||||||
reloads the cache from fas and tries again.
|
reloads the cache from fas and tries again.
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
return self.user_cache[username]['bugzilla_email'].lower()
|
bz_email = self.user_cache[username]['bugzilla_email'].lower()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if username.startswith('@'):
|
if username.startswith('@'):
|
||||||
group = self.fas.group_by_name(username[1:])
|
group = self.fas.group_by_name(username[1:])
|
||||||
|
@ -203,14 +213,15 @@ class BugzillaProxy:
|
||||||
return
|
return
|
||||||
self.user_cache[username] = {
|
self.user_cache[username] = {
|
||||||
'bugzilla_email': bz_email}
|
'bugzilla_email': bz_email}
|
||||||
|
self.inverted_user_cache[bz_email] = username
|
||||||
else:
|
else:
|
||||||
person = self.fas.person_by_username(username)
|
person = self.fas.person_by_username(username)
|
||||||
bz_email = person.get('bugzilla_email', None)
|
bz_email = person.get('bugzilla_email', None)
|
||||||
if bz_email is None:
|
if bz_email is None:
|
||||||
|
|
||||||
return
|
return
|
||||||
self.user_cache[username] = {'bugzilla_email': bz_email}
|
self.user_cache[username] = {'bugzilla_email': bz_email}
|
||||||
return self.user_cache[username]['bugzilla_email'].lower()
|
self.inverted_user_cache[bz_email] = username
|
||||||
|
return bz_email
|
||||||
|
|
||||||
def add_edit_component(self, package, collection, owner, description=None,
|
def add_edit_component(self, package, collection, owner, description=None,
|
||||||
qacontact=None, cclist=None, print_fas_names=False):
|
qacontact=None, cclist=None, print_fas_names=False):
|
||||||
|
@ -285,19 +296,42 @@ class BugzillaProxy:
|
||||||
print(f'[EDITCOMP] {data["product"]}/{data["component"]}')
|
print(f'[EDITCOMP] {data["product"]}/{data["component"]}')
|
||||||
for key in ["initialowner", "description", "initialqacontact", "initialcclist"]:
|
for key in ["initialowner", "description", "initialqacontact", "initialcclist"]:
|
||||||
if data.get(key):
|
if data.get(key):
|
||||||
|
|
||||||
|
old_value = product[pkg_key][key]
|
||||||
|
if not isinstance(old_value, str):
|
||||||
|
old_value = sorted(old_value)
|
||||||
|
new_value = data.get(key)
|
||||||
|
if not isinstance(new_value, str):
|
||||||
|
new_value = sorted(new_value)
|
||||||
|
|
||||||
if print_fas_names and key in ('initialowner',
|
if print_fas_names and key in ('initialowner',
|
||||||
'initialqacontact',
|
'initialqacontact',
|
||||||
'initialcclist'):
|
'initialcclist'):
|
||||||
if key == 'initialowner':
|
if key == 'initialowner':
|
||||||
value = owner
|
new_value = owner
|
||||||
elif key == 'initialqacontact':
|
elif key == 'initialqacontact':
|
||||||
value = qacontact
|
new_value = qacontact
|
||||||
else:
|
else:
|
||||||
value = initial_cc_fasnames
|
new_value = sorted(initial_cc_fasnames)
|
||||||
print(f" {key} changed to FAS name(s) `{value}`")
|
|
||||||
|
from_fas_names = []
|
||||||
|
for email in product[pkg_key][key]:
|
||||||
|
if email in self.inverted_user_cache:
|
||||||
|
from_fas_names.append(self.inverted_user_cache[email])
|
||||||
|
elif email == 'extras-qa@fedoraproject.org':
|
||||||
|
from_fas_names.append("<default: extras-qa@...>")
|
||||||
|
if from_fas_names:
|
||||||
|
if len(from_fas_names) < len(product[pkg_key][key]):
|
||||||
|
x = len(product[pkg_key][key]) - len(from_fas_names)
|
||||||
|
from_fas_names.append(f"And {x} more")
|
||||||
|
old_value = f"from `{from_fas_names}`"
|
||||||
|
else:
|
||||||
|
old_value = ""
|
||||||
|
print(
|
||||||
|
f" {key} changed {old_value}"
|
||||||
|
f" to FAS name(s) `{new_value}`")
|
||||||
else:
|
else:
|
||||||
print(f" {key} changed from `{product[pkg_key][key]} "
|
print(f" {key} changed from `{old_value}` to `{new_value}`")
|
||||||
f"to `{data.get(key)}`")
|
|
||||||
|
|
||||||
# FIXME: initialowner has been made mandatory for some
|
# FIXME: initialowner has been made mandatory for some
|
||||||
# reason. Asking dkl why.
|
# reason. Asking dkl why.
|
||||||
|
@ -719,6 +753,8 @@ class DistgitBugzillaSync:
|
||||||
self.env['bugzilla']['user'],
|
self.env['bugzilla']['user'],
|
||||||
self.env['bugzilla']['password'],
|
self.env['bugzilla']['password'],
|
||||||
self.env)
|
self.env)
|
||||||
|
if self.args.print_fas_names:
|
||||||
|
bugzilla.invert_user_cache()
|
||||||
|
|
||||||
if self.env["verbose"]:
|
if self.env["verbose"]:
|
||||||
times["FAS cache building end"] = time.time()
|
times["FAS cache building end"] = time.time()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue