Skip to content

Commit e7c7b2e

Browse files
committed
Add more functions to get commits per repo
1 parent 9cde776 commit e7c7b2e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

datauploader/api/rest.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
# https://developer.github.com/v3/#pagination
77

88

9+
GITHUB_USER_INFO_ENDPOINT = "https://api.github.com/user"
910
GITHUB_RATE_LIMIT_ENDPOINT = "https://api.github.com/rate_limit"
1011
GITHUB_REPOS_ENDPOINT = "https://api.github.com/user/repos?sort=created&per_page=100"
11-
GITHUB_EVENTS_ENDPOINT = "https://api.github.com/users/carolinux/events?sort=created&per_page=100" #FIXME, get username
12-
13-
GITHUB_EVENTS_ENDPOINT="https://api.github.com/repos/anitagraser/TimeManager/commits?author=carolinux&per_page=100"
12+
GITHUB_REPO_COMMITS_ENDPOINT = "https://api.github.com/repos/{}/commits?author={}&per_page=100"
1413

1514
#https://api.github.com/repos/carolinux/Subs.py/commits?author=carolinux&per_page=100
1615
# also allows for a since param in the url
@@ -21,6 +20,10 @@ def get_auth_header(github_access_token):
2120
return auth_header
2221

2322

23+
def get_full_names_from_repos(repos):
24+
return [repo['full_name'] for repo in repos]
25+
26+
2427
def get_rate_limit_remaining(github_access_token, type="core"):
2528
""" Get the rate limit remaining and the reset time (in seconds from epoch format) as a tuple.
2629
The query itself does not decrement the available
@@ -36,6 +39,12 @@ def get_rate_limit_remaining(github_access_token, type="core"):
3639
return rate_limit_info['remaining'], rate_limit_info['reset']
3740

3841

42+
def get_user_info(github_access_token):
43+
auth_header = get_auth_header(github_access_token)
44+
response = requests.get(GITHUB_USER_INFO_ENDPOINT, headers=auth_header)
45+
return json.loads(response.content)
46+
47+
3948
def get_user_repos(github_access_token):
4049
results = []
4150
cnt = 0
@@ -53,10 +62,10 @@ def get_user_repos(github_access_token):
5362
return results
5463

5564

56-
def get_user_events(github_access_token):
65+
def get_repo_commits_for_user(github_access_token, repo, username):
5766
results = []
5867
cnt = 0
59-
url = GITHUB_EVENTS_ENDPOINT
68+
url = GITHUB_REPO_COMMITS_ENDPOINT.format(repo, username)
6069
while(True):
6170
cnt+=1
6271
response = requests.get(url, headers=get_auth_header(github_access_token))

0 commit comments

Comments
 (0)