From 8f820ec654ed02d2f970c037444f71f9e8db0218 Mon Sep 17 00:00:00 2001 From: Mattia Verga Date: Mar 07 2025 17:03:46 +0000 Subject: Add Koji builds check Signed-off-by: Mattia Verga --- diff --git a/Pipfile b/Pipfile index d81a5bb..3282f7e 100644 --- a/Pipfile +++ b/Pipfile @@ -6,5 +6,6 @@ name = "pypi" [packages] click = "*" fasjson-client = "*" +koji = "*" python-bugzilla = "*" diff --git a/README.md b/README.md index 2fa7af8..10f8448 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ The script will search for any activity in the last year in: +- koji builds - src.fedoraproject.org - pagure.io - bodhi (through datagrepper) @@ -26,7 +27,7 @@ Use the '--privacy' flag to not print emails in the log. To run the script you'll need: -- click, fasjson_client, and python-bugzilla to be installed +- click, fasjson_client, koji, and python-bugzilla to be installed - an active kerberos ticket to login to fasjson.fedoraproject.org - a bugzilla API key for bugzilla.redhat.com in your ~/.bugzillarc config file diff --git a/find_inactive_packagers.py b/find_inactive_packagers.py index 39a70a2..929e12b 100644 --- a/find_inactive_packagers.py +++ b/find_inactive_packagers.py @@ -27,6 +27,7 @@ The script will search for any activity in the last year in: +- koji builds - src.fedoraproject.org - pagure.io - bodhi (through datagrepper) @@ -53,7 +54,7 @@ Use the '--privacy' flag to not print emails in the log. To run the script you'll need: -- fasjson_client to be installed +- click, fasjson_client, koji, and python-bugzilla to be installed - an active kerberos ticket to login to fasjson.fedoraproject.org - a bugzilla API key for bugzilla.redhat.com in your ~/.bugzillarc config file @@ -67,7 +68,7 @@ import logging import requests import sys from copy import copy -from datetime import datetime, timezone +from datetime import datetime, timedelta, timezone from dateutil import parser as dateparser from os import getenv from requests.adapters import HTTPAdapter @@ -75,6 +76,7 @@ from urllib3.util.retry import Retry from bugzilla import Bugzilla from fasjson_client import Client +from koji import ClientSession PAGURE_API_KEY = getenv('PAGURE_API_KEY', None) PAGURE_API_BASE_URL = getenv('PAGURE_API_BASE_URL', 'https://pagure.io/api/0/find-inactive-packagers') @@ -91,6 +93,9 @@ PAGURE_NEW_TICKET_ASSIGNEE = getenv('PAGURE_NEW_TICKET_ASSIGNEE', None) FASCLIENT_URL = 'https://fasjson.fedoraproject.org/' +KOJI_HUB = 'https://koji.fedoraproject.org/kojihub' +KOJI_BUILD_CUTOFF = (datetime.now(timezone.utc) - timedelta(weeks=52)).strftime("%Y-%m-%d 00:00:00") + # A list of system users that should never be removed from the packager group EXCLUDE_USERS = ['orphan', 'packagerbot', 'releng', 'rhcontainerbot'] @@ -243,6 +248,21 @@ def _close_pagure_ticket(ticket_id, close_status, comment=''): log.error(f'ERROR: Error on changing status of ticket {ticket_id}') +def _check_koji_activity(kojisession, username): + """Look for user latest builds in a Koji.""" + if not username: + log.error('ERROR: Cannot check an empty username!') + return False + packagerUser = kojisession.getUser(username) + if not packagerUser: + raise AttributeError(f'User {username} not found in koji') + packagerUid = packagerUser['id'] + if kojisession.listBuilds(userID=packagerUid, createdAfter=KOJI_BUILD_CUTOFF): + log.info(f'Found recent builds in Koji for user {username}') + return True + return False + + def _check_pagure_activity(user, base_url='https://src.fedoraproject.org'): """Look for user activity in a Pagure deployment.""" if not user: @@ -414,6 +434,12 @@ def _check_user_activity(user, privacy=False, fasclient=None, bzclient=None): 'a Kerberos ticket.') raise SystemExit('Unable to connect to fasclient, you probably forgot to obtain ' 'a Kerberos ticket.') + + kojiSession = ClientSession(KOJI_HUB) + + log.info(f'Checking {user} activity in Koji...') + if _check_koji_activity(kojiSession, user): + return True log.info(f'Checking {user} activity in Pagure...') try: src_fpo = _check_pagure_activity(user) @@ -583,6 +609,8 @@ def step_one(ctx, with_bz_check, open_tickets): 'Queue processing will stop immediately.') raise SystemExit() + kojiSession = ClientSession(KOJI_HUB) + try: fasclient = Client(FASCLIENT_URL) except Exception: @@ -592,11 +620,9 @@ def step_one(ctx, with_bz_check, open_tickets): packagers = fasclient.list_group_members(groupname='packager').result 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...') + # Check for activity in Koji + log.info('Checking users activity in Koji...') for i, p in enumerate(packagers): if i > 0 and i % 100 == 0: log.info(f'Done {i}.') @@ -604,6 +630,23 @@ def step_one(ctx, with_bz_check, open_tickets): if user in EXCLUDE_USERS: continue try: + koji_active = _check_koji_activity(kojiSession, user) + except AttributeError as ex: + log.info(f'{ex}') + koji_active = False + if not koji_active: + inactive_packagers.append(user) + + log.info(f'### Found {len(inactive_packagers)} users with no builds in Koji over the last year. ###') + + # Check for activity in Pagure + log.info('Checking users activity in Pagure...') + nouser_in_pagureio = [] + nouser_in_bugzilla = [] + for i, user in enumerate(copy(inactive_packagers)): + if i > 0 and i % 100 == 0: + log.info(f'Done {i}.') + try: src_fpo = _check_pagure_activity(user) except AttributeError as ex: log.info(f'{ex}') @@ -611,6 +654,7 @@ def step_one(ctx, with_bz_check, open_tickets): except ValueError as ex: log.info(f'{ex}') src_fpo = False + pagure = False if not src_fpo: try: pagure = _check_pagure_activity(user, base_url='https://pagure.io') @@ -622,8 +666,8 @@ def step_one(ctx, with_bz_check, open_tickets): log.info(f'{ex}') pagure = False nouser_in_pagureio.append(user) - if not src_fpo and not pagure: - inactive_packagers.append(user) + if src_fpo or pagure: + inactive_packagers.remove(user) log.info(f'### Found {len(inactive_packagers)} users with no activity in pagure/src.fp.org over the last year. ###')