-
Notifications
You must be signed in to change notification settings - Fork 5
/
repo_active_users.py
executable file
·92 lines (82 loc) · 2.75 KB
/
repo_active_users.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
"""
Script to determine the activity of users in a repo
Given a list of repos, and a timefame, check out the repo
and return the list of unique users in that repo
"""
import sys
import tempfile
import alive_progress
import github3
from git import Repo
from github_scripts import utils
def parse_args():
"""
Parse the command line.
Need either repo and org - or if no repo supplied, org.
Timeframe to look over. Default to 30 days.
"""
parser = utils.GH_ArgParser(
description="Gets a list of active users for a list of repos"
"Also checks wiki for activity, and can be told to check for issues activity."
)
parser.add_argument(
"org",
help="The organization that the repos belong to",
)
parser.add_argument(
"--days", help="How many days back to look, default, 30", type=int, default=30
)
parser.add_argument(
"repos",
help="list of repos to examine - or use --file for file base input",
action="store",
nargs="+",
)
parser.add_argument(
"--author",
help="Use the author rather than committer email, if you're concerned about people with permissions, committer is what you want",
action="store_true",
)
parser.add_argument("--debug", action="store_true")
args = parser.parse_args()
return args
def main():
args = parse_args()
userset = set()
# Are we looking at author emails, or committer?
if args.author:
format = "%ae"
else:
format = "%ce"
gh_sess = github3.login(token=args.token)
with alive_progress.alive_bar(
dual_line=True,
title="Getting Perms",
file=sys.stderr,
length=20,
force_tty=True,
disable=False,
) as bar:
for repo in args.repos:
bar.text(f"working on repo: {repo}")
url = f"https://{args.token}:[email protected]/{args.org}/{repo}.git"
localpath = tempfile.TemporaryDirectory()
workingset = set()
try:
clone = Repo.clone_from(url, localpath)
emailstr = clone.git.log(since=f"{args.days} days ago", pretty=f"tformat:{format}")
if emailstr != "":
emaillist = emailstr.split("\n")
workingset = set(emaillist)
if args.debug:
print(f"\t\tEmailSTR: {emailstr}", file=sys.stderr)
finally:
localpath.cleanup()
utils.check_rate_remain(gh_sess, bar=bar)
userset |= workingset
print(f"Unique author emails found in the org {args.org} org and the repos you asked about:")
for item in userset:
print(item)
if __name__ == "__main__":
main()