File: query_contributors.py

package info (click to toggle)
xgboost 3.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,848 kB
  • sloc: cpp: 67,603; python: 35,537; java: 4,676; ansic: 1,426; sh: 1,352; xml: 1,226; makefile: 204; javascript: 19
file content (75 lines) | stat: -rw-r--r-- 2,905 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Query list of all contributors and reviewers in a release"""

import json
import re
import sys

import requests
from sh.contrib import git

if len(sys.argv) != 5:
    print(f'Usage: {sys.argv[0]} [starting commit/tag] [ending commit/tag] [GitHub username] ' +
           '[GitHub password]')
    sys.exit(1)

from_commit = sys.argv[1]
to_commit = sys.argv[2]
username = sys.argv[3]
password = sys.argv[4]

contributors = set()
reviewers = set()

def paginate_request(url, callback):
    r = requests.get(url, auth=(username, password))
    assert r.status_code == requests.codes.ok, f'Code: {r.status_code}, Text: {r.text}'
    callback(json.loads(r.text))
    while 'next' in r.links:
        r = requests.get(r.links['next']['url'], auth=(username, password))
        callback(json.loads(r.text))

for line in git.log(f'{from_commit}..{to_commit}', '--pretty=format:%s', '--reverse', '--first-parent'):
    m = re.search('\(#([0-9]+)\)$', line.rstrip())
    if m:
        pr_id = m.group(1)
        print(f'PR #{pr_id}')

        def process_commit_list(commit_list):
            try:
                contributors.update([commit['author']['login'] for commit in commit_list])
            except TypeError:
                prompt = (f'Error fetching contributors for PR #{pr_id}. Enter it manually, ' +
                          'as a space-separated list: ')
                contributors.update(str(input(prompt)).split(' '))
        def process_review_list(review_list):
            reviewers.update([x['user']['login'] for x in review_list])
        def process_comment_list(comment_list):
            reviewers.update([x['user']['login'] for x in comment_list])

        paginate_request(f'https://api.github.com/repos/dmlc/xgboost/pulls/{pr_id}/commits',
                         process_commit_list)
        paginate_request(f'https://api.github.com/repos/dmlc/xgboost/pulls/{pr_id}/reviews',
                         process_review_list)
        paginate_request(f'https://api.github.com/repos/dmlc/xgboost/issues/{pr_id}/comments',
                         process_comment_list)

print('Contributors: ', end='')
for x in sorted(contributors):
    r = requests.get(f'https://api.github.com/users/{x}', auth=(username, password))
    assert r.status_code == requests.codes.ok, f'Code: {r.status_code}, Text: {r.text}'
    user_info = json.loads(r.text)
    if user_info['name'] is None:
        print(f"@{x}, ", end='')
    else:
        print(f"{user_info['name']} (@{x}), ", end='')

print('\nReviewers: ', end='')
for x in sorted(reviewers):
    r = requests.get(f'https://api.github.com/users/{x}', auth=(username, password))
    assert r.status_code == requests.codes.ok, f'Code: {r.status_code}, Text: {r.text}'
    user_info = json.loads(r.text)
    if user_info['name'] is None:
        print(f"@{x}, ", end='')
    else:
        print(f"{user_info['name']} (@{x}), ", end='')
print('')