blob: d077deae9b446e0a4d6f936fa15c83aa3bd650c7 (
plain)
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
|
# vim:expandtab ts=4 sw=4 ft=python
import json
import requests
class IssueManager(object):
def __init__(self, username, password, repo_owner, repo):
self._auth_pair = (username, password)
self.issues_url = (
"https://api.github.com/repos/{repo_owner}/{repo}/issues"
.format(**locals())
)
self.milestones_url = (
"https://api.github.com/repos/{repo_owner}/{repo}/milestones"
.format(**locals())
)
def _do_request(self, url):
data = requests.get(url, auth=self._auth_pair)
if data.status_code != 200:
raise Exception(
"Error {data.status_code}: {data.content}".format(data=data))
return json.loads(data.content)
def list_issues(self):
return self._do_request(self.issues_url)
def get_issue(self, issue_id):
url = "{0}/{1}".format(self.issues_url, issue_id)
return self._do_request(url)
def list_milestones(self):
return self._do_request(self.milestones_url)
def list_issues_in_milestone(self, milestone_number):
url = "{0}?milestone={1:d}".format(self.issues_url, milestone_number)
return self._do_request(url)
|