/inactive_members.py Secret
Created
November 19, 2024 00:26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from github import Github | |
from github import Auth | |
from datetime import date, datetime | |
from dateutil.relativedelta import relativedelta | |
import yaml | |
import argparse | |
parser = argparse.ArgumentParser(description=''' | |
List inactive users in repo''') | |
parser.add_argument('--repo',metavar='REPO', dest='github_repo', action='store', required=True, | |
help='GitHub repo to list.') | |
parser.add_argument('--auth_token',metavar='AUTH_TOKEN', dest='auth_token', action='store', required=True, | |
help='Personal user token') | |
parser.add_argument('--owners_file',metavar='OWNERS', dest='owners_file', action='store', required=False, | |
help='Personal user token', | |
default='OWNERS') | |
args = parser.parse_args() | |
s = date.today() - relativedelta(months=+6) | |
past_half_year = datetime.fromordinal(s.toordinal()) | |
with open(args.owners_file) as stream: | |
try: | |
owners = yaml.safe_load(stream) | |
except yaml.YAMLError as exc: | |
print(exc) | |
if owners: | |
reviewers = owners.get('reviewers') | |
approvers = owners.get('approvers') | |
# using an access token | |
auth = Auth.Token(args.auth_token) | |
# Public Web Github | |
g = Github(auth=auth) | |
repo = g.get_repo(args.github_repo) | |
members = [x.login for x in repo.get_contributors()] | |
# get all active users from pull request comments | |
active_users = {x.user.login: True for x in repo.get_pulls_comments(since=past_half_year)} | |
# not sure if this is really needed | |
for x in repo.get_pulls_review_comments(since=past_half_year): | |
active_users[x.user.login] = True | |
# get all active users from issue comments | |
for x in repo.get_issues_comments(since=past_half_year): | |
active_users[x.user.login] = True | |
# get all active users from commits | |
for x in repo.get_commits(since=datetime(s.year, s.month, s.day)): | |
active_users[x.author.login] = True | |
registry = {'members': members, 'reviewers': reviewers, 'approvers': approvers} | |
for name, lst in registry.items(): | |
for idx in reversed(range(len(lst))): | |
if active_users.get(lst[idx]): | |
del lst[idx] | |
print('All inactive {0}: {1}'.format(name, lst)) | |
g.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment