comparison venv/lib/python2.7/site-packages/github/PullRequest.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 Michael Stead <michael.stead@gmail.com> #
6 # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> #
7 # Copyright 2012 Zearin <zearin@gonk.net> #
8 # Copyright 2013 AKFish <akfish@gmail.com> #
9 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
10 # Copyright 2013 martinqt <m.ki2@laposte.net> #
11 # #
12 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ #
13 # #
14 # PyGithub is free software: you can redistribute it and/or modify it under #
15 # the terms of the GNU Lesser General Public License as published by the Free #
16 # Software Foundation, either version 3 of the License, or (at your option) #
17 # any later version. #
18 # #
19 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
20 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
21 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
22 # details. #
23 # #
24 # You should have received a copy of the GNU Lesser General Public License #
25 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
26 # #
27 # ##############################################################################
28
29 import github.GithubObject
30 import github.PaginatedList
31
32 import github.PullRequestMergeStatus
33 import github.NamedUser
34 import github.PullRequestPart
35 import github.PullRequestComment
36 import github.File
37 import github.IssueComment
38 import github.Commit
39
40
41 class PullRequest(github.GithubObject.CompletableGithubObject):
42 """
43 This class represents PullRequests. The reference can be found here http://developer.github.com/v3/pulls/
44 """
45
46 @property
47 def additions(self):
48 """
49 :type: integer
50 """
51 self._completeIfNotSet(self._additions)
52 return self._additions.value
53
54 @property
55 def assignee(self):
56 """
57 :type: :class:`github.NamedUser.NamedUser`
58 """
59 self._completeIfNotSet(self._assignee)
60 return self._assignee.value
61
62 @property
63 def base(self):
64 """
65 :type: :class:`github.PullRequestPart.PullRequestPart`
66 """
67 self._completeIfNotSet(self._base)
68 return self._base.value
69
70 @property
71 def body(self):
72 """
73 :type: string
74 """
75 self._completeIfNotSet(self._body)
76 return self._body.value
77
78 @property
79 def changed_files(self):
80 """
81 :type: integer
82 """
83 self._completeIfNotSet(self._changed_files)
84 return self._changed_files.value
85
86 @property
87 def closed_at(self):
88 """
89 :type: datetime.datetime
90 """
91 self._completeIfNotSet(self._closed_at)
92 return self._closed_at.value
93
94 @property
95 def comments(self):
96 """
97 :type: integer
98 """
99 self._completeIfNotSet(self._comments)
100 return self._comments.value
101
102 @property
103 def comments_url(self):
104 """
105 :type: string
106 """
107 self._completeIfNotSet(self._comments_url)
108 return self._comments_url.value
109
110 @property
111 def commits(self):
112 """
113 :type: integer
114 """
115 self._completeIfNotSet(self._commits)
116 return self._commits.value
117
118 @property
119 def commits_url(self):
120 """
121 :type: string
122 """
123 self._completeIfNotSet(self._commits_url)
124 return self._commits_url.value
125
126 @property
127 def created_at(self):
128 """
129 :type: datetime.datetime
130 """
131 self._completeIfNotSet(self._created_at)
132 return self._created_at.value
133
134 @property
135 def deletions(self):
136 """
137 :type: integer
138 """
139 self._completeIfNotSet(self._deletions)
140 return self._deletions.value
141
142 @property
143 def diff_url(self):
144 """
145 :type: string
146 """
147 self._completeIfNotSet(self._diff_url)
148 return self._diff_url.value
149
150 @property
151 def head(self):
152 """
153 :type: :class:`github.PullRequestPart.PullRequestPart`
154 """
155 self._completeIfNotSet(self._head)
156 return self._head.value
157
158 @property
159 def html_url(self):
160 """
161 :type: string
162 """
163 self._completeIfNotSet(self._html_url)
164 return self._html_url.value
165
166 @property
167 def id(self):
168 """
169 :type: integer
170 """
171 self._completeIfNotSet(self._id)
172 return self._id.value
173
174 @property
175 def issue_url(self):
176 """
177 :type: string
178 """
179 self._completeIfNotSet(self._issue_url)
180 return self._issue_url.value
181
182 @property
183 def merge_commit_sha(self):
184 """
185 :type: string
186 """
187 self._completeIfNotSet(self._merge_commit_sha)
188 return self._merge_commit_sha.value
189
190 @property
191 def mergeable(self):
192 """
193 :type: bool
194 """
195 self._completeIfNotSet(self._mergeable)
196 return self._mergeable.value
197
198 @property
199 def mergeable_state(self):
200 """
201 :type: string
202 """
203 self._completeIfNotSet(self._mergeable_state)
204 return self._mergeable_state.value
205
206 @property
207 def merged(self):
208 """
209 :type: bool
210 """
211 self._completeIfNotSet(self._merged)
212 return self._merged.value
213
214 @property
215 def merged_at(self):
216 """
217 :type: datetime.datetime
218 """
219 self._completeIfNotSet(self._merged_at)
220 return self._merged_at.value
221
222 @property
223 def merged_by(self):
224 """
225 :type: :class:`github.NamedUser.NamedUser`
226 """
227 self._completeIfNotSet(self._merged_by)
228 return self._merged_by.value
229
230 @property
231 def milestone(self):
232 """
233 :type: :class:`github.Milestone.Milestone`
234 """
235 self._completeIfNotSet(self._milestone)
236 return self._milestone.value
237
238 @property
239 def number(self):
240 """
241 :type: integer
242 """
243 self._completeIfNotSet(self._number)
244 return self._number.value
245
246 @property
247 def patch_url(self):
248 """
249 :type: string
250 """
251 self._completeIfNotSet(self._patch_url)
252 return self._patch_url.value
253
254 @property
255 def review_comment_url(self):
256 """
257 :type: string
258 """
259 self._completeIfNotSet(self._review_comment_url)
260 return self._review_comment_url.value
261
262 @property
263 def review_comments(self):
264 """
265 :type: integer
266 """
267 self._completeIfNotSet(self._review_comments)
268 return self._review_comments.value
269
270 @property
271 def review_comments_url(self):
272 """
273 :type: string
274 """
275 self._completeIfNotSet(self._review_comments_url)
276 return self._review_comments_url.value
277
278 @property
279 def state(self):
280 """
281 :type: string
282 """
283 self._completeIfNotSet(self._state)
284 return self._state.value
285
286 @property
287 def title(self):
288 """
289 :type: string
290 """
291 self._completeIfNotSet(self._title)
292 return self._title.value
293
294 @property
295 def updated_at(self):
296 """
297 :type: datetime.datetime
298 """
299 self._completeIfNotSet(self._updated_at)
300 return self._updated_at.value
301
302 @property
303 def url(self):
304 """
305 :type: string
306 """
307 self._completeIfNotSet(self._url)
308 return self._url.value
309
310 @property
311 def user(self):
312 """
313 :type: :class:`github.NamedUser.NamedUser`
314 """
315 self._completeIfNotSet(self._user)
316 return self._user.value
317
318 def create_comment(self, body, commit_id, path, position):
319 """
320 :calls: `POST /repos/:owner/:repo/pulls/:number/comments <http://developer.github.com/v3/pulls/comments>`_
321 :param body: string
322 :param commit_id: :class:`github.Commit.Commit`
323 :param path: string
324 :param position: integer
325 :rtype: :class:`github.PullRequestComment.PullRequestComment`
326 """
327 return self.create_review_comment(body, commit_id, path, position)
328
329 def create_review_comment(self, body, commit_id, path, position):
330 """
331 :calls: `POST /repos/:owner/:repo/pulls/:number/comments <http://developer.github.com/v3/pulls/comments>`_
332 :param body: string
333 :param commit_id: :class:`github.Commit.Commit`
334 :param path: string
335 :param position: integer
336 :rtype: :class:`github.PullRequestComment.PullRequestComment`
337 """
338 assert isinstance(body, (str, unicode)), body
339 assert isinstance(commit_id, github.Commit.Commit), commit_id
340 assert isinstance(path, (str, unicode)), path
341 assert isinstance(position, (int, long)), position
342 post_parameters = {
343 "body": body,
344 "commit_id": commit_id._identity,
345 "path": path,
346 "position": position,
347 }
348 headers, data = self._requester.requestJsonAndCheck(
349 "POST",
350 self.url + "/comments",
351 input=post_parameters
352 )
353 return github.PullRequestComment.PullRequestComment(self._requester, headers, data, completed=True)
354
355 def create_issue_comment(self, body):
356 """
357 :calls: `POST /repos/:owner/:repo/issues/:number/comments <http://developer.github.com/v3/issues/comments>`_
358 :param body: string
359 :rtype: :class:`github.IssueComment.IssueComment`
360 """
361 assert isinstance(body, (str, unicode)), body
362 post_parameters = {
363 "body": body,
364 }
365 headers, data = self._requester.requestJsonAndCheck(
366 "POST",
367 self._parentUrl(self._parentUrl(self.url)) + "/issues/" + str(self.number) + "/comments",
368 input=post_parameters
369 )
370 return github.IssueComment.IssueComment(self._requester, headers, data, completed=True)
371
372 def edit(self, title=github.GithubObject.NotSet, body=github.GithubObject.NotSet, state=github.GithubObject.NotSet):
373 """
374 :calls: `PATCH /repos/:owner/:repo/pulls/:number <http://developer.github.com/v3/pulls>`_
375 :param title: string
376 :param body: string
377 :param state: string
378 :rtype: None
379 """
380 assert title is github.GithubObject.NotSet or isinstance(title, (str, unicode)), title
381 assert body is github.GithubObject.NotSet or isinstance(body, (str, unicode)), body
382 assert state is github.GithubObject.NotSet or isinstance(state, (str, unicode)), state
383 post_parameters = dict()
384 if title is not github.GithubObject.NotSet:
385 post_parameters["title"] = title
386 if body is not github.GithubObject.NotSet:
387 post_parameters["body"] = body
388 if state is not github.GithubObject.NotSet:
389 post_parameters["state"] = state
390 headers, data = self._requester.requestJsonAndCheck(
391 "PATCH",
392 self.url,
393 input=post_parameters
394 )
395 self._useAttributes(data)
396
397 def get_comment(self, id):
398 """
399 :calls: `GET /repos/:owner/:repo/pulls/comments/:number <http://developer.github.com/v3/pulls/comments>`_
400 :param id: integer
401 :rtype: :class:`github.PullRequestComment.PullRequestComment`
402 """
403 return self.get_review_comment(id)
404
405 def get_review_comment(self, id):
406 """
407 :calls: `GET /repos/:owner/:repo/pulls/comments/:number <http://developer.github.com/v3/pulls/comments>`_
408 :param id: integer
409 :rtype: :class:`github.PullRequestComment.PullRequestComment`
410 """
411 assert isinstance(id, (int, long)), id
412 headers, data = self._requester.requestJsonAndCheck(
413 "GET",
414 self._parentUrl(self.url) + "/comments/" + str(id)
415 )
416 return github.PullRequestComment.PullRequestComment(self._requester, headers, data, completed=True)
417
418 def get_comments(self):
419 """
420 :calls: `GET /repos/:owner/:repo/pulls/:number/comments <http://developer.github.com/v3/pulls/comments>`_
421 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment`
422 """
423 return self.get_review_comments()
424
425 def get_review_comments(self):
426 """
427 :calls: `GET /repos/:owner/:repo/pulls/:number/comments <http://developer.github.com/v3/pulls/comments>`_
428 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment`
429 """
430 return github.PaginatedList.PaginatedList(
431 github.PullRequestComment.PullRequestComment,
432 self._requester,
433 self.url + "/comments",
434 None
435 )
436
437 def get_commits(self):
438 """
439 :calls: `GET /repos/:owner/:repo/pulls/:number/commits <http://developer.github.com/v3/pulls>`_
440 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Commit.Commit`
441 """
442 return github.PaginatedList.PaginatedList(
443 github.Commit.Commit,
444 self._requester,
445 self.url + "/commits",
446 None
447 )
448
449 def get_files(self):
450 """
451 :calls: `GET /repos/:owner/:repo/pulls/:number/files <http://developer.github.com/v3/pulls>`_
452 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.File.File`
453 """
454 return github.PaginatedList.PaginatedList(
455 github.File.File,
456 self._requester,
457 self.url + "/files",
458 None
459 )
460
461 def get_issue_comment(self, id):
462 """
463 :calls: `GET /repos/:owner/:repo/issues/comments/:id <http://developer.github.com/v3/issues/comments>`_
464 :param id: integer
465 :rtype: :class:`github.IssueComment.IssueComment`
466 """
467 assert isinstance(id, (int, long)), id
468 headers, data = self._requester.requestJsonAndCheck(
469 "GET",
470 self._parentUrl(self._parentUrl(self.url)) + "/issues/comments/" + str(id)
471 )
472 return github.IssueComment.IssueComment(self._requester, headers, data, completed=True)
473
474 def get_issue_comments(self):
475 """
476 :calls: `GET /repos/:owner/:repo/issues/:number/comments <http://developer.github.com/v3/issues/comments>`_
477 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueComment.IssueComment`
478 """
479 return github.PaginatedList.PaginatedList(
480 github.IssueComment.IssueComment,
481 self._requester,
482 self._parentUrl(self._parentUrl(self.url)) + "/issues/" + str(self.number) + "/comments",
483 None
484 )
485
486 def is_merged(self):
487 """
488 :calls: `GET /repos/:owner/:repo/pulls/:number/merge <http://developer.github.com/v3/pulls>`_
489 :rtype: bool
490 """
491 status, headers, data = self._requester.requestJson(
492 "GET",
493 self.url + "/merge"
494 )
495 return status == 204
496
497 def merge(self, commit_message=github.GithubObject.NotSet):
498 """
499 :calls: `PUT /repos/:owner/:repo/pulls/:number/merge <http://developer.github.com/v3/pulls>`_
500 :param commit_message: string
501 :rtype: :class:`github.PullRequestMergeStatus.PullRequestMergeStatus`
502 """
503 assert commit_message is github.GithubObject.NotSet or isinstance(commit_message, (str, unicode)), commit_message
504 post_parameters = dict()
505 if commit_message is not github.GithubObject.NotSet:
506 post_parameters["commit_message"] = commit_message
507 headers, data = self._requester.requestJsonAndCheck(
508 "PUT",
509 self.url + "/merge",
510 input=post_parameters
511 )
512 return github.PullRequestMergeStatus.PullRequestMergeStatus(self._requester, headers, data, completed=True)
513
514 def _initAttributes(self):
515 self._additions = github.GithubObject.NotSet
516 self._assignee = github.GithubObject.NotSet
517 self._base = github.GithubObject.NotSet
518 self._body = github.GithubObject.NotSet
519 self._changed_files = github.GithubObject.NotSet
520 self._closed_at = github.GithubObject.NotSet
521 self._comments = github.GithubObject.NotSet
522 self._comments_url = github.GithubObject.NotSet
523 self._commits = github.GithubObject.NotSet
524 self._commits_url = github.GithubObject.NotSet
525 self._created_at = github.GithubObject.NotSet
526 self._deletions = github.GithubObject.NotSet
527 self._diff_url = github.GithubObject.NotSet
528 self._head = github.GithubObject.NotSet
529 self._html_url = github.GithubObject.NotSet
530 self._id = github.GithubObject.NotSet
531 self._issue_url = github.GithubObject.NotSet
532 self._merge_commit_sha = github.GithubObject.NotSet
533 self._mergeable = github.GithubObject.NotSet
534 self._mergeable_state = github.GithubObject.NotSet
535 self._merged = github.GithubObject.NotSet
536 self._merged_at = github.GithubObject.NotSet
537 self._merged_by = github.GithubObject.NotSet
538 self._milestone = github.GithubObject.NotSet
539 self._number = github.GithubObject.NotSet
540 self._patch_url = github.GithubObject.NotSet
541 self._review_comment_url = github.GithubObject.NotSet
542 self._review_comments = github.GithubObject.NotSet
543 self._review_comments_url = github.GithubObject.NotSet
544 self._state = github.GithubObject.NotSet
545 self._title = github.GithubObject.NotSet
546 self._updated_at = github.GithubObject.NotSet
547 self._url = github.GithubObject.NotSet
548 self._user = github.GithubObject.NotSet
549
550 def _useAttributes(self, attributes):
551 if "additions" in attributes: # pragma no branch
552 self._additions = self._makeIntAttribute(attributes["additions"])
553 if "assignee" in attributes: # pragma no branch
554 self._assignee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assignee"])
555 if "base" in attributes: # pragma no branch
556 self._base = self._makeClassAttribute(github.PullRequestPart.PullRequestPart, attributes["base"])
557 if "body" in attributes: # pragma no branch
558 self._body = self._makeStringAttribute(attributes["body"])
559 if "changed_files" in attributes: # pragma no branch
560 self._changed_files = self._makeIntAttribute(attributes["changed_files"])
561 if "closed_at" in attributes: # pragma no branch
562 self._closed_at = self._makeDatetimeAttribute(attributes["closed_at"])
563 if "comments" in attributes: # pragma no branch
564 self._comments = self._makeIntAttribute(attributes["comments"])
565 if "comments_url" in attributes: # pragma no branch
566 self._comments_url = self._makeStringAttribute(attributes["comments_url"])
567 if "commits" in attributes: # pragma no branch
568 self._commits = self._makeIntAttribute(attributes["commits"])
569 if "commits_url" in attributes: # pragma no branch
570 self._commits_url = self._makeStringAttribute(attributes["commits_url"])
571 if "created_at" in attributes: # pragma no branch
572 self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
573 if "deletions" in attributes: # pragma no branch
574 self._deletions = self._makeIntAttribute(attributes["deletions"])
575 if "diff_url" in attributes: # pragma no branch
576 self._diff_url = self._makeStringAttribute(attributes["diff_url"])
577 if "head" in attributes: # pragma no branch
578 self._head = self._makeClassAttribute(github.PullRequestPart.PullRequestPart, attributes["head"])
579 if "html_url" in attributes: # pragma no branch
580 self._html_url = self._makeStringAttribute(attributes["html_url"])
581 if "id" in attributes: # pragma no branch
582 self._id = self._makeIntAttribute(attributes["id"])
583 if "issue_url" in attributes: # pragma no branch
584 self._issue_url = self._makeStringAttribute(attributes["issue_url"])
585 if "merge_commit_sha" in attributes: # pragma no branch
586 self._merge_commit_sha = self._makeStringAttribute(attributes["merge_commit_sha"])
587 if "mergeable" in attributes: # pragma no branch
588 self._mergeable = self._makeBoolAttribute(attributes["mergeable"])
589 if "mergeable_state" in attributes: # pragma no branch
590 self._mergeable_state = self._makeStringAttribute(attributes["mergeable_state"])
591 if "merged" in attributes: # pragma no branch
592 self._merged = self._makeBoolAttribute(attributes["merged"])
593 if "merged_at" in attributes: # pragma no branch
594 self._merged_at = self._makeDatetimeAttribute(attributes["merged_at"])
595 if "merged_by" in attributes: # pragma no branch
596 self._merged_by = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["merged_by"])
597 if "milestone" in attributes: # pragma no branch
598 self._milestone = self._makeClassAttribute(github.Milestone.Milestone, attributes["milestone"])
599 if "number" in attributes: # pragma no branch
600 self._number = self._makeIntAttribute(attributes["number"])
601 if "patch_url" in attributes: # pragma no branch
602 self._patch_url = self._makeStringAttribute(attributes["patch_url"])
603 if "review_comment_url" in attributes: # pragma no branch
604 self._review_comment_url = self._makeStringAttribute(attributes["review_comment_url"])
605 if "review_comments" in attributes: # pragma no branch
606 self._review_comments = self._makeIntAttribute(attributes["review_comments"])
607 if "review_comments_url" in attributes: # pragma no branch
608 self._review_comments_url = self._makeStringAttribute(attributes["review_comments_url"])
609 if "state" in attributes: # pragma no branch
610 self._state = self._makeStringAttribute(attributes["state"])
611 if "title" in attributes: # pragma no branch
612 self._title = self._makeStringAttribute(attributes["title"])
613 if "updated_at" in attributes: # pragma no branch
614 self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
615 if "url" in attributes: # pragma no branch
616 self._url = self._makeStringAttribute(attributes["url"])
617 if "user" in attributes: # pragma no branch
618 self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])