aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weiss2020-08-08 17:37:37 +0200
committerMichael Weiss2020-08-08 17:39:10 +0200
commit4e80e63d1954dbd4962b4f651bff4a7c8fce2a25 (patch)
treedecd591fc8f994408650914e35a0a4603feac039
parent1069398444a90a6ceef76f9b2b6ad98f0e4e1786 (diff)
scripts: Add github-get-top-orga-contributors.py
I wrote this a while ago out of curiosity.
-rwxr-xr-xscripts/github-get-top-orga-contributors.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/scripts/github-get-top-orga-contributors.py b/scripts/github-get-top-orga-contributors.py
new file mode 100755
index 0000000..e571157
--- /dev/null
+++ b/scripts/github-get-top-orga-contributors.py
@@ -0,0 +1,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))