-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubAPI.py
More file actions
63 lines (45 loc) · 1.75 KB
/
githubAPI.py
File metadata and controls
63 lines (45 loc) · 1.75 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
import requests,json,pprint
import configuration
v = configuration.verbose
pp = pprint.PrettyPrinter(indent=4)
#get the first 100 of the open pull requests for a repo, and return the issue urls
def get_pulls(owner,repo):
#/repos/:owner/:repo/pulls
count = 0
pulls = []
request = requests.get('https://api.github.com/repos/%s/%s/pulls?per_page=100' % owner, repo)
content = json.loads(request.content)
for pull in content:
pulls.append(pull)
count+=1
if v: print ('\n%s open pull requests.' % str(count))
return pulls
def get_pull_comments(owner,repo,pull):
count = 0
request = requests.get('https://api.github.com/repos/%s/%s/issues/%s/comments' % owner, repo, pull)
comments = json.loads(request.content)
for comment in comments: count+=1
if v: print ('\n%s comments in pull number %s.' % str(count),pull)
return comments
#get the first 100 of the open pull requests for a repo, and return the issue urls
def get_pull_nums(owner,repo):
#/repos/:owner/:repo/pulls
pulls = get_pulls(owner,repo)
pull_nums = []
count = 0
for pull in pulls:
pull_nums.append(pull['issue_url'].split('/')[-1])
count+=1
if v: print ('\n%s pull numbers extracted.' % str(count))
return pull_nums
def get_user_comments(owner,repo,pull,user):
pull_comments = get_pull_comments(owner,repo,pull)
user_comments = []
count = 0
for comment in pull_comments:
login = comment['user']['login']
if login is user:
user_comments.append(comment['body'])
count +=1
if v: print ('\n%s comments by %s in pull number %s' % str(count),user,pull)
return user_comments