Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/github/Issue.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # ########################## Copyrights and license ############################ | |
4 # # | |
5 # Copyright 2012 Andrew Bettison <andrewb@zip.com.au> # | |
6 # Copyright 2012 Philip Kimmey <philip@rover.com> # | |
7 # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # | |
8 # Copyright 2012 Zearin <zearin@gonk.net> # | |
9 # Copyright 2013 AKFish <akfish@gmail.com> # | |
10 # Copyright 2013 Stuart Glaser <stuglaser@gmail.com> # | |
11 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # | |
12 # # | |
13 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ # | |
14 # # | |
15 # PyGithub is free software: you can redistribute it and/or modify it under # | |
16 # the terms of the GNU Lesser General Public License as published by the Free # | |
17 # Software Foundation, either version 3 of the License, or (at your option) # | |
18 # any later version. # | |
19 # # | |
20 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # | |
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # | |
22 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # | |
23 # details. # | |
24 # # | |
25 # You should have received a copy of the GNU Lesser General Public License # | |
26 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # | |
27 # # | |
28 # ############################################################################## | |
29 | |
30 import github.GithubObject | |
31 import github.PaginatedList | |
32 | |
33 import github.Repository | |
34 import github.IssueEvent | |
35 import github.Label | |
36 import github.NamedUser | |
37 import github.Milestone | |
38 import github.IssueComment | |
39 import github.IssuePullRequest | |
40 | |
41 | |
42 class Issue(github.GithubObject.CompletableGithubObject): | |
43 """ | |
44 This class represents Issues as returned for example by http://developer.github.com/v3/todo | |
45 """ | |
46 | |
47 @property | |
48 def assignee(self): | |
49 """ | |
50 :type: :class:`github.NamedUser.NamedUser` | |
51 """ | |
52 self._completeIfNotSet(self._assignee) | |
53 return self._assignee.value | |
54 | |
55 @property | |
56 def body(self): | |
57 """ | |
58 :type: string | |
59 """ | |
60 self._completeIfNotSet(self._body) | |
61 return self._body.value | |
62 | |
63 @property | |
64 def closed_at(self): | |
65 """ | |
66 :type: datetime.datetime | |
67 """ | |
68 self._completeIfNotSet(self._closed_at) | |
69 return self._closed_at.value | |
70 | |
71 @property | |
72 def closed_by(self): | |
73 """ | |
74 :type: :class:`github.NamedUser.NamedUser` | |
75 """ | |
76 self._completeIfNotSet(self._closed_by) | |
77 return self._closed_by.value | |
78 | |
79 @property | |
80 def comments(self): | |
81 """ | |
82 :type: integer | |
83 """ | |
84 self._completeIfNotSet(self._comments) | |
85 return self._comments.value | |
86 | |
87 @property | |
88 def comments_url(self): | |
89 """ | |
90 :type: string | |
91 """ | |
92 self._completeIfNotSet(self._comments_url) | |
93 return self._comments_url.value | |
94 | |
95 @property | |
96 def created_at(self): | |
97 """ | |
98 :type: datetime.datetime | |
99 """ | |
100 self._completeIfNotSet(self._created_at) | |
101 return self._created_at.value | |
102 | |
103 @property | |
104 def events_url(self): | |
105 """ | |
106 :type: string | |
107 """ | |
108 self._completeIfNotSet(self._events_url) | |
109 return self._events_url.value | |
110 | |
111 @property | |
112 def html_url(self): | |
113 """ | |
114 :type: string | |
115 """ | |
116 self._completeIfNotSet(self._html_url) | |
117 return self._html_url.value | |
118 | |
119 @property | |
120 def id(self): | |
121 """ | |
122 :type: integer | |
123 """ | |
124 self._completeIfNotSet(self._id) | |
125 return self._id.value | |
126 | |
127 @property | |
128 def labels(self): | |
129 """ | |
130 :type: list of :class:`github.Label.Label` | |
131 """ | |
132 self._completeIfNotSet(self._labels) | |
133 return self._labels.value | |
134 | |
135 @property | |
136 def labels_url(self): | |
137 """ | |
138 :type: string | |
139 """ | |
140 self._completeIfNotSet(self._labels_url) | |
141 return self._labels_url.value | |
142 | |
143 @property | |
144 def milestone(self): | |
145 """ | |
146 :type: :class:`github.Milestone.Milestone` | |
147 """ | |
148 self._completeIfNotSet(self._milestone) | |
149 return self._milestone.value | |
150 | |
151 @property | |
152 def number(self): | |
153 """ | |
154 :type: integer | |
155 """ | |
156 self._completeIfNotSet(self._number) | |
157 return self._number.value | |
158 | |
159 @property | |
160 def pull_request(self): | |
161 """ | |
162 :type: :class:`github.IssuePullRequest.IssuePullRequest` | |
163 """ | |
164 self._completeIfNotSet(self._pull_request) | |
165 return self._pull_request.value | |
166 | |
167 @property | |
168 def repository(self): | |
169 """ | |
170 :type: :class:`github.Repository.Repository` | |
171 """ | |
172 self._completeIfNotSet(self._repository) | |
173 if self._repository is github.GithubObject.NotSet: | |
174 # The repository was not set automatically, so it must be looked up by url. | |
175 repo_url = "/".join(self.url.split("/")[:-2]) | |
176 self._repository = github.GithubObject._ValuedAttribute(github.Repository.Repository(self._requester, self._headers, {'url': repo_url}, completed=False)) | |
177 return self._repository.value | |
178 | |
179 @property | |
180 def state(self): | |
181 """ | |
182 :type: string | |
183 """ | |
184 self._completeIfNotSet(self._state) | |
185 return self._state.value | |
186 | |
187 @property | |
188 def title(self): | |
189 """ | |
190 :type: string | |
191 """ | |
192 self._completeIfNotSet(self._title) | |
193 return self._title.value | |
194 | |
195 @property | |
196 def updated_at(self): | |
197 """ | |
198 :type: datetime.datetime | |
199 """ | |
200 self._completeIfNotSet(self._updated_at) | |
201 return self._updated_at.value | |
202 | |
203 @property | |
204 def url(self): | |
205 """ | |
206 :type: string | |
207 """ | |
208 self._completeIfNotSet(self._url) | |
209 return self._url.value | |
210 | |
211 @property | |
212 def user(self): | |
213 """ | |
214 :type: :class:`github.NamedUser.NamedUser` | |
215 """ | |
216 self._completeIfNotSet(self._user) | |
217 return self._user.value | |
218 | |
219 def add_to_labels(self, *labels): | |
220 """ | |
221 :calls: `POST /repos/:owner/:repo/issues/:number/labels <http://developer.github.com/v3/issues/labels>`_ | |
222 :param label: :class:`github.Label.Label` or string | |
223 :rtype: None | |
224 """ | |
225 assert all(isinstance(element, (github.Label.Label, str, unicode)) for element in labels), labels | |
226 post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels] | |
227 headers, data = self._requester.requestJsonAndCheck( | |
228 "POST", | |
229 self.url + "/labels", | |
230 input=post_parameters | |
231 ) | |
232 | |
233 def create_comment(self, body): | |
234 """ | |
235 :calls: `POST /repos/:owner/:repo/issues/:number/comments <http://developer.github.com/v3/issues/comments>`_ | |
236 :param body: string | |
237 :rtype: :class:`github.IssueComment.IssueComment` | |
238 """ | |
239 assert isinstance(body, (str, unicode)), body | |
240 post_parameters = { | |
241 "body": body, | |
242 } | |
243 headers, data = self._requester.requestJsonAndCheck( | |
244 "POST", | |
245 self.url + "/comments", | |
246 input=post_parameters | |
247 ) | |
248 return github.IssueComment.IssueComment(self._requester, headers, data, completed=True) | |
249 | |
250 def delete_labels(self): | |
251 """ | |
252 :calls: `DELETE /repos/:owner/:repo/issues/:number/labels <http://developer.github.com/v3/issues/labels>`_ | |
253 :rtype: None | |
254 """ | |
255 headers, data = self._requester.requestJsonAndCheck( | |
256 "DELETE", | |
257 self.url + "/labels" | |
258 ) | |
259 | |
260 def edit(self, title=github.GithubObject.NotSet, body=github.GithubObject.NotSet, assignee=github.GithubObject.NotSet, state=github.GithubObject.NotSet, milestone=github.GithubObject.NotSet, labels=github.GithubObject.NotSet): | |
261 """ | |
262 :calls: `PATCH /repos/:owner/:repo/issues/:number <http://developer.github.com/v3/issues>`_ | |
263 :param title: string | |
264 :param body: string | |
265 :param assignee: string or :class:`github.NamedUser.NamedUser` or None | |
266 :param state: string | |
267 :param milestone: :class:`github.Milestone.Milestone` or None | |
268 :param labels: list of string | |
269 :rtype: None | |
270 """ | |
271 assert title is github.GithubObject.NotSet or isinstance(title, (str, unicode)), title | |
272 assert body is github.GithubObject.NotSet or isinstance(body, (str, unicode)), body | |
273 assert assignee is github.GithubObject.NotSet or assignee is None or isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, (str, unicode)), assignee | |
274 assert state is github.GithubObject.NotSet or isinstance(state, (str, unicode)), state | |
275 assert milestone is github.GithubObject.NotSet or milestone is None or isinstance(milestone, github.Milestone.Milestone), milestone | |
276 assert labels is github.GithubObject.NotSet or all(isinstance(element, (str, unicode)) for element in labels), labels | |
277 post_parameters = dict() | |
278 if title is not github.GithubObject.NotSet: | |
279 post_parameters["title"] = title | |
280 if body is not github.GithubObject.NotSet: | |
281 post_parameters["body"] = body | |
282 if assignee is not github.GithubObject.NotSet: | |
283 if isinstance(assignee, (str, unicode)): | |
284 post_parameters["assignee"] = assignee | |
285 else: | |
286 post_parameters["assignee"] = assignee._identity if assignee else '' | |
287 if state is not github.GithubObject.NotSet: | |
288 post_parameters["state"] = state | |
289 if milestone is not github.GithubObject.NotSet: | |
290 post_parameters["milestone"] = milestone._identity if milestone else '' | |
291 if labels is not github.GithubObject.NotSet: | |
292 post_parameters["labels"] = labels | |
293 headers, data = self._requester.requestJsonAndCheck( | |
294 "PATCH", | |
295 self.url, | |
296 input=post_parameters | |
297 ) | |
298 self._useAttributes(data) | |
299 | |
300 def get_comment(self, id): | |
301 """ | |
302 :calls: `GET /repos/:owner/:repo/issues/comments/:id <http://developer.github.com/v3/issues/comments>`_ | |
303 :param id: integer | |
304 :rtype: :class:`github.IssueComment.IssueComment` | |
305 """ | |
306 assert isinstance(id, (int, long)), id | |
307 headers, data = self._requester.requestJsonAndCheck( | |
308 "GET", | |
309 self._parentUrl(self.url) + "/comments/" + str(id) | |
310 ) | |
311 return github.IssueComment.IssueComment(self._requester, headers, data, completed=True) | |
312 | |
313 def get_comments(self): | |
314 """ | |
315 :calls: `GET /repos/:owner/:repo/issues/:number/comments <http://developer.github.com/v3/issues/comments>`_ | |
316 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueComment.IssueComment` | |
317 """ | |
318 return github.PaginatedList.PaginatedList( | |
319 github.IssueComment.IssueComment, | |
320 self._requester, | |
321 self.url + "/comments", | |
322 None | |
323 ) | |
324 | |
325 def get_events(self): | |
326 """ | |
327 :calls: `GET /repos/:owner/:repo/issues/:issue_number/events <http://developer.github.com/v3/issues/events>`_ | |
328 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueEvent.IssueEvent` | |
329 """ | |
330 return github.PaginatedList.PaginatedList( | |
331 github.IssueEvent.IssueEvent, | |
332 self._requester, | |
333 self.url + "/events", | |
334 None | |
335 ) | |
336 | |
337 def get_labels(self): | |
338 """ | |
339 :calls: `GET /repos/:owner/:repo/issues/:number/labels <http://developer.github.com/v3/issues/labels>`_ | |
340 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` | |
341 """ | |
342 return github.PaginatedList.PaginatedList( | |
343 github.Label.Label, | |
344 self._requester, | |
345 self.url + "/labels", | |
346 None | |
347 ) | |
348 | |
349 def remove_from_labels(self, label): | |
350 """ | |
351 :calls: `DELETE /repos/:owner/:repo/issues/:number/labels/:name <http://developer.github.com/v3/issues/labels>`_ | |
352 :param label: :class:`github.Label.Label` or string | |
353 :rtype: None | |
354 """ | |
355 assert isinstance(label, (github.Label.Label, str, unicode)), label | |
356 if isinstance(label, github.Label.Label): | |
357 label = label._identity | |
358 headers, data = self._requester.requestJsonAndCheck( | |
359 "DELETE", | |
360 self.url + "/labels/" + label | |
361 ) | |
362 | |
363 def set_labels(self, *labels): | |
364 """ | |
365 :calls: `PUT /repos/:owner/:repo/issues/:number/labels <http://developer.github.com/v3/issues/labels>`_ | |
366 :param label: :class:`github.Label.Label` | |
367 :rtype: None | |
368 """ | |
369 assert all(isinstance(element, (github.Label.Label, str, unicode)) for element in labels), labels | |
370 post_parameters = [label.name if isinstance(label, github.Label.Label) else label for label in labels] | |
371 headers, data = self._requester.requestJsonAndCheck( | |
372 "PUT", | |
373 self.url + "/labels", | |
374 input=post_parameters | |
375 ) | |
376 | |
377 @property | |
378 def _identity(self): | |
379 return self.number | |
380 | |
381 def _initAttributes(self): | |
382 self._assignee = github.GithubObject.NotSet | |
383 self._body = github.GithubObject.NotSet | |
384 self._closed_at = github.GithubObject.NotSet | |
385 self._closed_by = github.GithubObject.NotSet | |
386 self._comments = github.GithubObject.NotSet | |
387 self._comments_url = github.GithubObject.NotSet | |
388 self._created_at = github.GithubObject.NotSet | |
389 self._events_url = github.GithubObject.NotSet | |
390 self._html_url = github.GithubObject.NotSet | |
391 self._id = github.GithubObject.NotSet | |
392 self._labels = github.GithubObject.NotSet | |
393 self._labels_url = github.GithubObject.NotSet | |
394 self._milestone = github.GithubObject.NotSet | |
395 self._number = github.GithubObject.NotSet | |
396 self._pull_request = github.GithubObject.NotSet | |
397 self._repository = github.GithubObject.NotSet | |
398 self._state = github.GithubObject.NotSet | |
399 self._title = github.GithubObject.NotSet | |
400 self._updated_at = github.GithubObject.NotSet | |
401 self._url = github.GithubObject.NotSet | |
402 self._user = github.GithubObject.NotSet | |
403 | |
404 def _useAttributes(self, attributes): | |
405 if "assignee" in attributes: # pragma no branch | |
406 self._assignee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assignee"]) | |
407 if "body" in attributes: # pragma no branch | |
408 self._body = self._makeStringAttribute(attributes["body"]) | |
409 if "closed_at" in attributes: # pragma no branch | |
410 self._closed_at = self._makeDatetimeAttribute(attributes["closed_at"]) | |
411 if "closed_by" in attributes: # pragma no branch | |
412 self._closed_by = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["closed_by"]) | |
413 if "comments" in attributes: # pragma no branch | |
414 self._comments = self._makeIntAttribute(attributes["comments"]) | |
415 if "comments_url" in attributes: # pragma no branch | |
416 self._comments_url = self._makeStringAttribute(attributes["comments_url"]) | |
417 if "created_at" in attributes: # pragma no branch | |
418 self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) | |
419 if "events_url" in attributes: # pragma no branch | |
420 self._events_url = self._makeStringAttribute(attributes["events_url"]) | |
421 if "html_url" in attributes: # pragma no branch | |
422 self._html_url = self._makeStringAttribute(attributes["html_url"]) | |
423 if "id" in attributes: # pragma no branch | |
424 self._id = self._makeIntAttribute(attributes["id"]) | |
425 if "labels" in attributes: # pragma no branch | |
426 self._labels = self._makeListOfClassesAttribute(github.Label.Label, attributes["labels"]) | |
427 if "labels_url" in attributes: # pragma no branch | |
428 self._labels_url = self._makeStringAttribute(attributes["labels_url"]) | |
429 if "milestone" in attributes: # pragma no branch | |
430 self._milestone = self._makeClassAttribute(github.Milestone.Milestone, attributes["milestone"]) | |
431 if "number" in attributes: # pragma no branch | |
432 self._number = self._makeIntAttribute(attributes["number"]) | |
433 if "pull_request" in attributes: # pragma no branch | |
434 self._pull_request = self._makeClassAttribute(github.IssuePullRequest.IssuePullRequest, attributes["pull_request"]) | |
435 if "repository" in attributes: # pragma no branch | |
436 self._repository = self._makeClassAttribute(github.Repository.Repository, attributes["repository"]) | |
437 if "state" in attributes: # pragma no branch | |
438 self._state = self._makeStringAttribute(attributes["state"]) | |
439 if "title" in attributes: # pragma no branch | |
440 self._title = self._makeStringAttribute(attributes["title"]) | |
441 if "updated_at" in attributes: # pragma no branch | |
442 self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) | |
443 if "url" in attributes: # pragma no branch | |
444 self._url = self._makeStringAttribute(attributes["url"]) | |
445 if "user" in attributes: # pragma no branch | |
446 self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"]) |