-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_list.py
More file actions
89 lines (74 loc) · 2.78 KB
/
commit_list.py
File metadata and controls
89 lines (74 loc) · 2.78 KB
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
"""
this program takes the apikey and username from the config file
and compiles a list of commits authored by that user.
currently this program is time and api access intensive, and does not store partial nor complete results
but writes directly to stdout
"""
from configparser import ConfigParser
import github
import logging
logging.basicConfig(level=logging.INFO)
APIKEY: str
USERNAME : str
def authenticate():
global APIKEY, USERNAME
config = ConfigParser()
config.read('config.ini')
config['DEFAULT'] = {'apikey':'', 'username':''}
APIKEY = config['commit_list']['apikey']
USERNAME = config['commit_list']['username']
if APIKEY:
# authenticate with api key
g = github.Github(APIKEY)
else:
# authenticate with username and password'
logging.warning('no api key provided, please login with github credentials')
import getpass
USERNAME = input("username > ")
g = github.Github(USERNAME, getpass.getpass())
try:
lim=g.get_rate_limit()
except github.BadCredentialsException:
logging.fatal('invalid credentials')
exit(1)
else:
if lim.core.limit == 60:
logging.fatal('unauthenticated user')
exit(1)
if lim.core.remaining < 2000:
logging.fatal('insufficient api calls remaining')
logging.fatal(f'api calls reset on {lim.core.reset}.')
exit()
return g
g: github.Github = authenticate()
commits = list()
commit_queue = list()
def get_branch_commits():
for repo in g.get_organization("R2D2-2019").get_repos():
for branch in repo.get_branches():
print(branch)
if not branch.commit:
logging.warning(branch.name + ' in ' + repo.name + ' has no commits')
if branch.commit not in commit_queue:
commit_queue.append(branch.commit)
def get_parents():
while commit_queue:
commit = commit_queue.pop()
if commit in commits:
continue
commits.append(commit)
for commit_parent in commit.parents:
if commit_parent not in commits and commit_parent not in commit_queue:
commit_queue.append(commit_parent)
if __name__ == "__main__":
get_branch_commits()
get_parents()
filtered = list(filter((lambda commit: commit.author.name == USERNAME if commit.author else False), commits))
filtered.sort(key=(lambda commit: commit.commit.author.date))
last_weeknum = 0
for commit in filtered:
weeknum = commit.commit.author.date.isocalendar()[1]
if weeknum > last_weeknum:
last_weeknum = weeknum
print('Year-week', weeknum)
print(commit.html_url)