forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmilestone.py
More file actions
159 lines (117 loc) · 4.47 KB
/
milestone.py
File metadata and controls
159 lines (117 loc) · 4.47 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from json import dumps
from . import label
from .. import users
from ..decorators import requires_auth
from ..models import GitHubCore
class Milestone(GitHubCore):
"""Representation of milestones on a repository.
See also: http://developer.github.com/v3/issues/milestones/
This object has the following attributes:
.. attribute:: closed_issues_count
The number of closed issues in this milestone.
.. attribute:: created_at
A :class:`~datetime.datetime` object representing the date and time
when this milestone was created.
.. attribute:: creator
If present, a :class:`~github3.users.ShortUser` representing the user
who created this milestone.
.. attribute:: description
The written description of this milestone and its purpose.
.. attribute:: due_on
If set, a :class:`~datetime.datetime` object representing the date and
time when this milestone is due.
.. attribute:: id
The unique identifier of this milestone in GitHub.
.. attribute:: number
The repository-local numeric identifier of this milestone. This starts
at 1 like issues.
.. attribute:: open_issues_count
The number of open issues still in this milestone.
.. attribute:: state
The state of this milestone, e.g., ``'open'`` or ``'closed'``.
.. attribute:: title
The title of this milestone.
.. attribute:: updated_at
A :class:`~datetime.datetime` object representing the date and time
when this milestone was last updated.
"""
def _update_attributes(self, milestone):
self._api = milestone["url"]
self.closed_issues_count = milestone["closed_issues"]
self.closed_issues = self.closed_issues_count
self.created_at = self._strptime(milestone["created_at"])
self.creator = milestone["creator"]
if self.creator:
self.creator = users.ShortUser(self.creator, self)
self.description = milestone["description"]
self.due_on = self._strptime(milestone["due_on"])
self.id = milestone["id"]
self.number = milestone["number"]
self.open_issues_count = milestone["open_issues"]
self.open_issues = self.open_issues_count
self.state = milestone["state"]
self.title = milestone["title"]
self.updated_at = self._strptime(milestone["updated_at"])
def _repr(self):
return "<Milestone [{0}]>".format(self)
def __str__(self):
return self.title
@requires_auth
def delete(self):
"""Delete this milestone.
:returns:
True if successful, False otherwise
:rtype:
bool
"""
return self._boolean(self._delete(self._api), 204, 404)
def labels(self, number=-1, etag=None):
"""Iterate over the labels of every associated issue.
.. versionchanged:: 0.9
Add etag parameter.
:param int number:
(optional), number of labels to return. Default: -1 returns all
available labels.
:param str etag:
(optional), ETag header from a previous response
:returns:
generator of labels
:rtype:
:class:`~github3.issues.label.ShortLabel`
"""
url = self._build_url("labels", base_url=self._api)
return self._iter(int(number), url, label.ShortLabel, etag=etag)
@requires_auth
def update(self, title=None, state=None, description=None, due_on=None):
"""Update this milestone.
All parameters are optional, but it makes no sense to omit all of them
at once.
:param str title:
(optional), new title of the milestone
:param str state:
(optional), ('open', 'closed')
:param str description:
(optional)
:param str due_on:
(optional), ISO 8601 time format: YYYY-MM-DDTHH:MM:SSZ
:returns:
True if successful, False otherwise
:rtype:
bool
"""
data = {
"title": title,
"state": state,
"description": description,
"due_on": due_on,
}
self._remove_none(data)
json = None
if data:
json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_attributes(json)
return True
return False