-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.py
114 lines (85 loc) · 4.2 KB
/
functions.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import requests, time
# Get all repos for a given user/org
def get_all_repo(user,token):
all_repo = []
pageno=1
while True:
response = requests.get("https://api.github.com/users/"+user+"/repos?page="+str(pageno)+'&access_token='+token+"&per_page=100")
for r in response.json():
all_repo.append(r['name'])
if 'next' in response.links:
pageno = pageno + 1
else:
break
return all_repo
# Get list of repos and usernames
# Get all contributors for a given repo
def get_all_contributors(user,repo,token):
all_contri = []
pageno=1
while True:
response = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/contributors?page="+str(pageno)+'&access_token='+token+"&per_page=100")
for r in response.json():
all_contri.append(r['login'])
if 'next' in response.links:
pageno = pageno + 1
else:
break
return all_contri
# Get all commits for a given repo
def get_commits_repo(user,repo,token):
pageno = 0
commits = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/commits?page="+str(pageno)+'&access_token='+token+"&per_page=100")
# Iterate through all pages to get rest of commits
all_commits = commits.json()
while 'next' in commits.links.keys():
pageno += 1
commits = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/commits?page="+str(pageno)+'&access_token='+token+"&per_page=100")
all_commits.extend(commits.json())
return all_commits
# Get all PRs for a given repo
def get_pull_requests_repo(user,repo,state,token):
pageno = 0
pull_requests = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/pulls?state="+state+"&page="+str(pageno)+'&access_token='+token+"&per_page=100")
all_pull_requests = pull_requests.json()
while 'next' in pull_requests.links.keys():
pageno += 1
pull_requests = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/pulls?state="+state+"&page="+str(pageno)+'&access_token='+token+"&per_page=100")
all_pull_requests.extend(pull_requests.json())
return all_pull_requests
# Get all PRs for a particular repo
def get_issues_repo(user,repo,state,token):
pageno = 0
issues = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/issues?state="+state+"&page="+str(pageno)+'&access_token='+token+"&per_page=100")
all_issues = issues.json()
while 'next' in issues.links.keys():
pageno += 1
issues = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/issues?state="+state+"&page="+str(pageno)+'&access_token='+token+"&per_page=100")
all_issues.extend(issues.json())
return all_issues
# Get all comments on issues
def get_comments_repo(user,repo,token):
pageno = 0
comments = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/issues/comments?page="+str(pageno)+'&access_token='+token+"&per_page=100")
all_comments = comments.json()
while 'next' in comments.links.keys():
pageno += 1
comments = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/issues/comments?page="+str(pageno)+'&access_token='+token+"&per_page=100")
all_comments.extend(comments.json())
return all_comments
# Get all comments on PRs (reviews)
def get_comments_prs_repo(user,repo,token):
pageno = 0
comments = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/pulls/comments?page="+str(pageno)+'&access_token='+token+"&per_page=100")
all_comments = comments.json()
while 'next' in comments.links.keys():
pageno += 1
comments = requests.get("https://api.github.com/repos/"+user+"/"+repo+"/pulls/comments?page="+str(pageno)+'&access_token='+token+"&per_page=100")
all_comments.extend(comments.json())
return all_comments
# Checks remaining requests if given a github token if lower than x then will wait for one hour.
def check_limit_wait(token):
remaining_requests = requests.get("https://api.github.com/rate_limit?access_token="+token)
if remaining_requests.json()['rate']['remaining'] < 100:
print("We seem to be nearing rate limit stopping for an hour")
time.sleep(3600)