~nova/gh-pr-filter

f3bda4326195253fac6c3dea2082f5693d9f7443 — Nova DasSarma 1 year, 6 months ago
Initial commit
1 files changed, 39 insertions(+), 0 deletions(-)

A main.py
A  => main.py +39 -0
@@ 1,39 @@
from github import Github
from os import environ as env
import sys

if len(sys.argv) != 4 or 'GH_TOKEN' not in env:
    print(f'Syntax: {sys.argv[0]} organization/repo_name user_name minimum_length')
    print()
    print(f'Environment variable GH_TOKEN must be set (https://github.com/settings/tokens to generate one)')
    sys.exit(1)

repo_path = sys.argv[1]
comment_user_name = sys.argv[2].lower()
minimum_length = int(sys.argv[3])

g = Github(login_or_token=env['GH_TOKEN'], per_page=100)
print(f'PR review and issue comments for {repo_path}')
r = g.get_repo(repo_path)

print(f'user_name: {comment_user_name}')
print(f'minimum_length: {minimum_length}')

has_printed_header = False
for pull in r.get_pulls('all'):
    print(f'PR#{pull.number} - {pull.title}')
    has_printed_header = False
    for review_comment in pull.get_comments():
        if (comment_user_name != '' and (review_comment.user.login.lower() == comment_user_name)) and len(review_comment.body) > minimum_length:
            if not has_printed_header:
                has_printed_header = True
                print(f'Matching review comments:')
            print(f'{review_comment.user.name} at {review_comment.updated_at} <{review_comment.url}>\n{review_comment.body}')
    has_printed_header = False
    for issue_comment in pull.get_issue_comments():
        if (comment_user_name != '' and (issue_comment.user.login.lower() == comment_user_name)) and len(issue_comment.body) > minimum_length:
            if not has_printed_header:
                has_printed_header = True
                print(f'Matching issue comments:')
            print(f'{issue_comment.user.name} at {issue_comment.updated_at} <{issue_comment.url}>\n{issue_comment.body}')