-
Notifications
You must be signed in to change notification settings - Fork 7
/
project.py
90 lines (70 loc) · 2.83 KB
/
project.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
import issue
import milestone
import category
import user
class Project(object):
"""Representation of a project in Sifter"""
def __init__(self, project, account):
self._account = account
self.issues_url = project['issues_url']
self.archived = project['archived']
self.url = project['url']
self.api_url = project['api_url']
self.milestones_url = project['milestones_url']
self.api_people_url = project['api_people_url']
self.api_issues_url = project['api_issues_url']
self.api_milestones_url = project['api_milestones_url']
self.api_categories_url = project['api_categories_url']
self.name = project['name']
self.primary_company_name = project['primary_company_name']
def issues(self):
"""Gets all the issues for a given project"""
issues = []
# Set per_page to 25 issues per page
first_page = self.api_issues_url + '?per_page=25&page=1'
# Get page one
json_raw = self._account.request(first_page)
# Set the next page
next_page = json_raw['next_page_url']
# Set the number of pages
number_of_pages = json_raw['total_pages']
for current_page in range(number_of_pages):
# Create a wrapper for each issue, add it to the list
raw_issues = json_raw['issues']
for raw_issue in raw_issues:
i = issue.Issue(raw_issue, self._account)
issues.append(i)
# Make a request for the next page
if current_page < number_of_pages - 1:
# store the results
json_raw = self._account.request(next_page)
# set the next page
next_page = json_raw['next_page_url']
return issues
def milestones(self):
"""Gets all the milestones for a given project"""
milestones = []
json_raw = self._account.request(self.api_milestones_url)
raw_milestones = json_raw['milestones']
for raw_milestone in raw_milestones:
m = milestone.Milestone(raw_milestone)
milestones.append(m)
return milestones
def categories(self):
"""Gets all the categories for a given project"""
categories = []
json_raw = self._account.request(self.api_categories_url)
raw_categories = json_raw['categories']
for raw_category in raw_categories:
c = category.Category(raw_category)
categories.append(c)
return categories
def people(self):
"""Gets all the people for a given project"""
people = []
json_raw = self._account.request(self.api_people_url)
raw_people = json_raw['people']
for raw_user in raw_people:
u = user.User(raw_user)
people.append(u)
return people