-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub.py
41 lines (31 loc) · 1.23 KB
/
github.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
import json
import urllib.request
class GitHubApi:
UNVERIFY_SSL = True
BASE_URL = 'https://api.github.com'
def __init__(self, option={}):
self.option = option
if self.UNVERIFY_SSL:
self.__unverify_ssl()
def __unverify_ssl(self):
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
def __get_json(self, url, token):
req = self.__create_request(url, token)
with urllib.request.urlopen(req) as res:
json_text = res.read().decode('utf-8')
json_obj = json.loads(json_text)
return json_obj
def __create_request(self, url, token):
req = urllib.request.Request(url)
req.add_header('Authorization', 'token ' + token)
return req
def get_commits(self, path, token):
url = self.BASE_URL + '/repos' + path
return self.__get_json(url, token)
def get_release(self, repo, release_id, token):
url = self.BASE_URL + '/repos/' + repo + '/releases/' + release_id
return self.__get_json(url, token)
def get_releases(self, repo, token):
url = self.BASE_URL + '/repos/' + repo + '/releases' + '?per_page=100'
return self.__get_json(url, token)