~nova/gh-pr-filter

ref: f3bda4326195253fac6c3dea2082f5693d9f7443 gh-pr-filter/main.py -rw-r--r-- 1.7 KiB
f3bda432 — Nova DasSarma Initial commit 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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}')