From 0b0f4b392467284fb5e297f840921a0bbed18396 Mon Sep 17 00:00:00 2001 From: Mattia Verga Date: Feb 18 2023 14:07:28 +0000 Subject: Tag tickets where user is not identified in bugzilla Signed-off-by: Mattia Verga --- diff --git a/find_inactive_packagers.py b/find_inactive_packagers.py index 27bfaba..59eeab8 100644 --- a/find_inactive_packagers.py +++ b/find_inactive_packagers.py @@ -79,6 +79,8 @@ PAGURE_API_BASE_URL = getenv('PAGURE_API_BASE_URL', 'https://pagure.io/api/0/fin PAGURE_NEW_TICKET_TAG = getenv('PAGURE_NEW_TICKET_TAG', 'inactive_packager') # A tag for marking tickets where user cannot be tagged because is not registered in pagure.io PAGURE_NOUSER_TAG = getenv('PAGURE_NOUSER_TAG', 'user_not_taggable') +# A tag for marking tickets where user cannot be identified in bugzilla +PAGURE_NOBUGZILLAUSER_TAG = getenv('PAGURE_NOBUGZILLAUSER_TAG', 'bugzilla_user_not_found') # The tag used when a user reply to a ticket asking to be removed from packager PAGURE_ASK_REMOVAL_TAG = getenv('PAGURE_ASK_REMOVAL_TAG', 'asked_removal') # A username to whom assign the ticket by default or None @@ -216,7 +218,7 @@ def _check_pagure_activity(user, base_url='https://src.fedoraproject.org'): resp_src = session.get(f'{base_url}/api/0/user/{user}/activity/stats').json() if resp_src.get('error', None) is not None: if resp_src.get('error_code', None) == 'ENOUSER': - raise AttributeError(f'User not found in {base_url}') + raise AttributeError(f'User {user} not found in {base_url}') log.info(f'Error checking user {user} in {base_url}: {error}') return False if not bool(resp_src): @@ -266,6 +268,9 @@ def _check_maillists_activity(fasclient, user, delta=365): emails = packager['emails'] if packager['rhbzemail']: emails.append(packager['rhbzemail']) + if not emails: + log.error(f'ERROR: User {user} has no emails in FAS') + return (False, []) for email in emails: r = session.get(f'https://lists.fedoraproject.org/archives/api/sender/{email}/emails/?ordering=-date').json() if r.get('count', 0) != 0: @@ -302,8 +307,7 @@ def _check_bugzilla_activity(bzclient, packager, check_fedora_alias=True, privac except Exception: log.warning(f'Unable to find user {username} by email {mask_email(bzemail, privacy=privacy)} in Bugzilla.') if not bzuser: - log.error(f'ERROR: Unable to check user {username} activity in Bugzilla because I cannot find them.') - return False + raise AttributeError(f'ERROR: Unable to check user {username} activity in Bugzilla because I cannot find them.') try: bugs = bzclient.query({ "email1" : bzuser.email, @@ -374,7 +378,12 @@ def _check_user_activity(user, privacy=False, fasclient=None, bzclient=None): if bzclient: log.info(f'Checking {user} activity in bugzilla...') packager = (user, maillist_result[1]) - if _check_bugzilla_activity(bzclient, packager, privacy=privacy): + try: + bugzilla = _check_bugzilla_activity(bzclient, packager, privacy=privacy) + except AttributeError as ex: + log.error(f'{ex}') + bugzilla = False + if bugzilla: return True return False @@ -462,6 +471,7 @@ def step_one(ctx, with_bz_check, open_tickets): log.info(f'### Found {len(packagers)} users in the packager group. ###') inactive_packagers = [] nouser_in_pagureio = [] + nouser_in_bugzilla = [] # Check for activity in Pagure log.info('Checking users activity in Pagure...') @@ -516,7 +526,13 @@ def step_one(ctx, with_bz_check, open_tickets): for i, p in enumerate(copy(packager_email_map).items()): if i > 0 and i % 100 == 0: log.info(f'Done {i}.') - if _check_bugzilla_activity(bzclient, p, privacy=privacy): + try: + bugzilla = _check_bugzilla_activity(bzclient, p, privacy=privacy) + except AttributeError as ex: + log.error(f'{ex}') + bugzilla = False + nouser_in_bugzilla.append(p[0]) + if bugzilla: packager_email_map.pop(p[0]) log.info(f'### Found {len(packager_email_map)} users which also show no activity in Bugzilla over the last year. ###') @@ -525,19 +541,24 @@ def step_one(ctx, with_bz_check, open_tickets): for user, emails in packager_email_map.items(): # Open Pagure tickets ticket_id = 'NONE' + tktags = [PAGURE_NEW_TICKET_TAG] if user in nouser_in_pagureio: nosuchuser = 'not registered in pagure.io' - tktags = f'{PAGURE_NEW_TICKET_TAG},{PAGURE_NOUSER_TAG}' + tktags.append(PAGURE_NOUSER_TAG) else: nosuchuser = '' - tktags = PAGURE_NEW_TICKET_TAG + if user in nouser_in_bugzilla: + nobugzilla = 'not found in bugzilla' + tktags.append(PAGURE_NOBUGZILLAUSER_TAG) + else: + nobugzilla = '' if open_tickets: log.debug(f'Opening ticket for user {user}') headers = {'Authorization': f'token {PAGURE_API_KEY}'} ping_email = mask_email(emails[0]) if len(emails) > 0 else '**ENOEMAIL**' data = {'title': f'Inactive packager detected for user {user}', 'issue_content': PING_INACTIVE_TEXT.format(username = user, email = ping_email), - 'tag': tktags, + 'tag': ','.join(tktags), 'assignee': PAGURE_NEW_TICKET_ASSIGNEE} try: resp = session.post(f'{PAGURE_API_BASE_URL}/new_issue', data=data, headers=headers) @@ -554,8 +575,8 @@ def step_one(ctx, with_bz_check, open_tickets): ticket_id = 'ERROR' # Write results to file emailstring = '|'.join([mask_email(em, privacy=privacy) for em in emails]) - log.info(f'{user} - {ticket_id} - {emailstring} - {nosuchuser}') - fout.write(f'{user},{ticket_id},{emailstring},{nosuchuser}\n') + log.info(f'{user} - {ticket_id} - {emailstring} - {nosuchuser} - {nobugzilla}') + fout.write(f'{user},{ticket_id},{emailstring},{nosuchuser},{nobugzilla}\n') else: log.info('### No inactive packagers detected, YHAY! Nothing to do. ###')