aboutsummaryrefslogtreecommitdiff
path: root/scripts/github-get-top-orga-contributors.py
blob: e571157941acd9508654f0b849905b7965d49713 (plain) (blame)
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
#!/usr/bin/env python3
# Dependencies: PyGithub (https://github.com/PyGithub/PyGithub)

from github import Github

print("""To avoid hitting API rate limits this script requires a GitHub token.
You can generate a personal token here: https://github.com/settings/tokens/new
No additional rights/scopes are required but "read:org" is useful to get the
private members (if you're a member of fsi-tue).
""")

token = input("Enter your token: ")
if token == "":
    token = None
    print("Attempting to run without a token (expect hitting the rate limits).")
g = Github(token)
print()

orga = g.get_organization("fsi-tue")
repos = orga.get_repos()
users = {}

for repo in repos:
    print(repo.name)
    contributors = repo.get_contributors()
    for contributor in contributors:
        name = contributor.login
        if contributor.name:
            name = name + " (" + contributor.name + ")"
        print("- " + name + ": " + str(contributor.contributions))
        if contributor in users:
            users[contributor] += contributor.contributions
        else:
            users[contributor] = contributor.contributions

print()
print("Total:")
for user, contributions in sorted(users.items(), key=lambda kv: kv[1], reverse=True):
    name = user.login
    if user.name:
        name = name + " (" + user.name + ")"
    print("- " + name + ": " + str(contributions))

fsi_tue = g.get_organization("fsi-tue")
org_members = fsi_tue.get_members()

print()
print("Total (fsi-tue only):")
fsi_users = {}
for user in org_members:
    if user in users:
        fsi_users[user] = users[user]
    else:
        fsi_users[user] = 0
for user, contributions in sorted(fsi_users.items(), key=lambda kv: kv[1], reverse=True):
    name = user.login
    if user.name:
        name = name + " (" + user.name + ")"
    print("- " + name + ": " + str(contributions))