-
Notifications
You must be signed in to change notification settings - Fork 407
/
Copy pathpulls.py
1214 lines (901 loc) · 37.3 KB
/
pulls.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""This module contains all the classes relating to pull requests."""
from json import dumps
from uritemplate import URITemplate # type: ignore
from . import models
from . import users
from .decorators import requires_auth
from .issues import Issue
from .issues.comment import IssueComment
from .repos import commit as rcommit
from .repos import contents
class PullDestination(models.GitHubCore):
"""The object that represents a pull request destination.
This is the base class for the :class:`~github3.pulls.Head` and
:class:`~github3.pulls.Base` objects. Each has identical attributes to
this object.
Please see GitHub's `Pull Request Documentation`_ for more information.
.. _Pull Request Documentation:
http://developer.github.com/v3/pulls/#get-a-single-pull-request
.. attribute:: ref
The full reference string for the git object
.. attribute:: label
The label for the destination (e.g., 'master', 'mybranch')
.. attribute:: user
If provided, a :class:`~github3.users.ShortUser` instance representing
the owner of the destination
.. attribute:: sha
The SHA of the commit at the head of the destination
.. attribute:: repository
A :class:`~github3.repos.repo.ShortRepository` representing the
repository containing this destination
.. attribute:: repo
A tuple containing the login and repository name, e.g.,
('sigmavirus24', 'github3.py')
This attribute is generated by github3.py and may be deprecated in the
future.
"""
direction = None
def _update_attributes(self, dest):
from .repos.repo import ShortRepository
self.ref = dest["ref"]
self.label = dest["label"]
self.user = dest.get("user")
if self.user:
self.user = users.ShortUser(self.user, self)
self.sha = dest["sha"]
self._repo_name = ""
self._repo_owner = ""
repo = dest.get("repo")
if repo:
self._repo_name = repo.get("name")
self._repo_owner = repo.get("owner")
if self._repo_owner:
self._repo_owner = self._repo_owner["login"]
self.repository = ShortRepository(repo, self)
self.repo = (self._repo_owner, self._repo_name)
def _repr(self):
return f"<{self.direction} [{self.label}]>"
class Head(PullDestination):
"""An object representing the Head destination of a pull request.
See :class:`~github3.pulls.PullDestination` for more details.
"""
destination = "Head"
class Base(PullDestination):
"""An object representing the Base destination of a pull request.
See :class:`~github3.pulls.PullDestination` for more details.
"""
destination = "Base"
class PullFile(models.GitHubCore):
"""The object that represents a file in a pull request.
Please see GitHub's `Pull Request Files Documentation`_ for more
information.
.. _Pull Request Files Documentation:
http://developer.github.com/v3/pulls/#list-pull-requests-files
.. attribute:: additions_count
The number of additions made to this file
.. attribute:: blob_url
The API resource used to retrieve the blob for this file
.. attribute:: changes_count
The number of changes made to this file
.. attribute:: contents_url
The API resource to view the raw contents of this file
.. attribute:: deletions_count
The number of deletions made to this file
.. attribute:: filename
The name of this file
.. attribute:: patch
The patch generated by this
.. note::
If the patch is larger than a specific size it may be missing
from GitHub's response. The attribute will be set to ``None``
in this case.
.. attribute:: raw_url
The API resource to view the raw diff of this file
.. attribute:: sha
The SHA of the commit that this file belongs to
.. attribute:: status
The string with the status of the file, e.g., 'added'
"""
def _update_attributes(self, pfile):
self.sha = pfile["sha"]
self.filename = pfile["filename"]
self.status = pfile["status"]
self.additions_count = pfile["additions"]
self.deletions_count = pfile["deletions"]
self.changes_count = pfile["changes"]
self.blob_url = pfile["blob_url"]
self.raw_url = pfile["raw_url"]
self.patch = pfile.get("patch")
self.contents_url = pfile["contents_url"]
def _repr(self):
return f"<Pull Request File [{self.filename}]>"
def contents(self):
"""Return the contents of the file.
:returns:
An object representing the contents of this file
:rtype:
:class:`~github3.repos.contents.Contents`
"""
json = self._json(self._get(self.contents_url), 200)
return self._instance_or_null(contents.Contents, json)
class _PullRequest(models.GitHubCore):
"""The :class:`PullRequest <PullRequest>` object.
Please see GitHub's `PullRequests Documentation`_ for more information.
.. _PullRequests Documentation:
http://developer.github.com/v3/pulls/
"""
class_name = "_PullRequest"
def _update_attributes(self, pull):
from . import orgs
self._api = pull["url"]
self.active_lock_reason = pull["active_lock_reason"]
self.assignee = pull["assignee"]
if self.assignee is not None:
self.assignee = users.ShortUser(self.assignee, self)
self.assignees = [users.ShortUser(a, self) for a in pull["assignees"]]
self.base = Base(pull["base"], self)
self.body = pull["body"]
self.body_html = pull["body_html"]
self.body_text = pull["body_text"]
self.closed_at = self._strptime(pull["closed_at"])
self.comments_url = pull["comments_url"]
self.commits_url = pull["commits_url"]
self.created_at = self._strptime(pull["created_at"])
self.diff_url = pull["diff_url"]
self.head = Head(pull["head"], self)
self.html_url = pull["html_url"]
self.id = pull["id"]
self.issue_url = pull["issue_url"]
self.links = pull["_links"]
self.locked = pull["locked"]
self.merge_commit_sha = pull["merge_commit_sha"]
self.merged_at = self._strptime(pull["merged_at"])
self.number = pull["number"]
self.patch_url = pull["patch_url"]
self.rebaseable = pull.get("rebaseable")
requested_reviewers = pull.get("requested_reviewers", [])
self.requested_reviewers = [
users.ShortUser(r, self) for r in requested_reviewers
]
requested_teams = pull.get("requested_teams", [])
self.requested_teams = [
orgs.ShortTeam(t, self) for t in requested_teams
]
self.review_comment_urlt = URITemplate(pull["review_comment_url"])
self.review_comments_url = pull["review_comments_url"]
self.repository = None
if self.base:
self.repository = self.base.repository
self.state = pull["state"]
self.statuses_url = pull["statuses_url"]
self.title = pull["title"]
self.updated_at = self._strptime(pull["updated_at"])
self.user = users.ShortUser(pull["user"], self)
def _repr(self):
return f"<{self.class_name} [#{self.number}]>"
@requires_auth
def close(self):
"""Close this Pull Request without merging.
:returns:
True if successful, False otherwise
:rtype:
bool
"""
return self.update(self.title, self.body, "closed")
@requires_auth
def create_comment(self, body):
"""Create a comment on this pull request's issue.
:param str body:
(required), comment body
:returns:
the comment that was created on the pull request
:rtype:
:class:`~github3.issues.comment.IssueComment`
"""
url = self.comments_url
json = None
if body:
json = self._json(self._post(url, data={"body": body}), 201)
return self._instance_or_null(IssueComment, json)
@requires_auth
def create_review_comment(self, body, commit_id, path, position):
"""Create a review comment on this pull request.
.. note::
All parameters are required by the GitHub API.
:param str body:
The comment text itself
:param str commit_id:
The SHA of the commit to comment on
:param str path:
The relative path of the file to comment on
:param int position:
The line index in the diff to comment on.
:returns:
The created review comment.
:rtype:
:class:`~github3.pulls.ReviewComment`
"""
url = self._build_url("comments", base_url=self._api)
data = {
"body": body,
"commit_id": commit_id,
"path": path,
"position": int(position),
}
json = self._json(self._post(url, data=data), 201)
return self._instance_or_null(ReviewComment, json)
@requires_auth
def create_review_requests(self, reviewers=None, team_reviewers=None):
"""Ask for reviews on this pull request.
:param list reviewers:
The users to which request a review
:param list team_reviewers:
The teams to which request a review
:returns:
The pull request on which the reviews were requested
:rtype:
:class:`~github3.pulls.ShortPullRequest`
"""
url = self._build_url("requested_reviewers", base_url=self._api)
data = {}
if reviewers is not None:
data["reviewers"] = [getattr(r, "login", r) for r in reviewers]
if team_reviewers is not None:
data["team_reviewers"] = [
getattr(t, "slug", t) for t in team_reviewers
]
json = self._json(self._post(url, data=data), 201)
return self._instance_or_null(ShortPullRequest, json)
@requires_auth
def create_review(self, body, commit_id=None, event=None, comments=None):
"""Create a review comment on this pull request.
.. warning::
If you do not specify ``event``, GitHub will default it
to ``PENDING`` which means that your review will need to
be submitted after creation. (See also
:meth:`~github3.pulls.PullReview.submit`.)
:param str body:
The comment text itself, required when using COMMENT or
REQUEST_CHANGES.
:param str commit_id:
The SHA of the commit to comment on
:param str event:
The review action you want to perform. Actions include
APPROVE, REQUEST_CHANGES or COMMENT. By leaving this blank
you set the action to PENDING and will need to submit the
review. Leaving blank may result in a 422 error response
which will need to be handled.
:param list comments:
Array of draft review comment objects. Please see Github's
`Create a pull request review documentation`_ for details
on review comment objects. At the time of writing these
were a dictionary with 3 keys: `path`, `position` and
`body`.
.. _Create a pull request review documentation:
https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
:returns:
The created review.
:rtype:
:class:`~github3.pulls.PullReview`
"""
if comments is None:
comments = []
url = self._build_url("reviews", base_url=self._api)
data = {"body": body, "comments": comments}
if commit_id is not None:
data["commit_id"] = commit_id
if event is not None:
data["event"] = event
json = self._json(self._post(url, data=data), 200)
return self._instance_or_null(PullReview, json)
@requires_auth
def delete_review_requests(self, reviewers=None, team_reviewers=None):
"""Cancel review requests on this pull request.
:param list reviewers:
The users whose review is no longer requested
:param list team_reviewers:
The teams whose review is no longer requested
:returns:
True if successful, False otherwise
:rtype:
bool
"""
url = self._build_url("requested_reviewers", base_url=self._api)
data = {}
if reviewers is not None:
data["reviewers"] = [getattr(r, "login", r) for r in reviewers]
if team_reviewers is not None:
data["team_reviewers"] = [
getattr(t, "slug", t) for t in team_reviewers
]
return self._boolean(self._delete(url, data=dumps(data)), 200, 404)
def diff(self):
"""Return the diff.
:returns:
representation of the diff
:rtype:
bytes
"""
resp = self._get(
self._api, headers={"Accept": "application/vnd.github.diff"}
)
return resp.content if self._boolean(resp, 200, 404) else b""
def is_merged(self):
"""Check to see if the pull request was merged.
.. versionchanged:: 1.0.0
This now always makes a call to the GitHub API. To avoid that,
check :attr:`merged` before making this call.
:returns:
True if merged, False otherwise
:rtype:
bool
"""
url = self._build_url("merge", base_url=self._api)
return self._boolean(self._get(url), 204, 404)
def issue(self):
"""Retrieve the issue associated with this pull request.
:returns:
the issue object that this pull request builds upon
:rtype:
:class:`~github3.issues.Issue`
"""
json = self._json(self._get(self.issue_url), 200)
return self._instance_or_null(Issue, json)
def commits(self, number=-1, etag=None):
"""Iterate over the commits on this pull request.
:param int number:
(optional), number of commits to return. Default: -1 returns all
available commits.
:param str etag:
(optional), ETag from a previous request to the same endpoint
:returns:
generator of repository commit objects
:rtype:
:class:`~github3.repos.commit.ShortCommit`
"""
url = self._build_url("commits", base_url=self._api)
return self._iter(int(number), url, rcommit.ShortCommit, etag=etag)
def files(self, number=-1, etag=None):
"""Iterate over the files associated with this pull request.
:param int number:
(optional), number of files to return. Default: -1 returns all
available files.
:param str etag:
(optional), ETag from a previous request to the same endpoint
:returns: generator of pull request files
:rtype: :class:`~PullFile`
"""
url = self._build_url("files", base_url=self._api)
return self._iter(int(number), url, PullFile, etag=etag)
def issue_comments(self, number=-1, etag=None):
"""Iterate over the issue comments on this pull request.
In this case, GitHub leaks implementation details. Pull Requests are
really just Issues with a diff. As such, comments on a pull request
that are not in-line with code, are technically issue comments.
:param int number:
(optional), number of comments to return. Default: -1 returns all
available comments.
:param str etag:
(optional), ETag from a previous request to the same endpoint
:returns:
generator of non-review comments on this pull request
:rtype:
:class:`~github3.issues.comment.IssueComment`
"""
comments = self.links.get("comments", {})
url = comments.get("href")
return self._iter(int(number), url, IssueComment, etag=etag)
@requires_auth
def merge(
self,
commit_message=None,
sha=None,
merge_method="merge",
commit_title=None,
):
"""Merge this pull request.
.. versionchanged:: 1.3.0
The ``commit_title`` parameter has been added to allow users to
set the merge commit title.
.. versionchanged:: 1.0.0
The boolean ``squash`` parameter has been replaced with
``merge_method`` which requires a string.
:param str commit_message:
(optional), message to be used for the merge commit
:param str commit_title:
(optional), message to be used for the merge commit title
:param str sha:
(optional), SHA that pull request head must match to merge.
:param str merge_method: (optional), Change the merge method.
Either 'merge', 'squash' or 'rebase'. Default is 'merge'.
:returns:
True if successful, False otherwise
:rtype:
bool
:returns: bool
"""
parameters = {"merge_method": merge_method}
if sha:
parameters["sha"] = sha
if commit_message is not None:
parameters["commit_message"] = commit_message
if commit_title is not None:
parameters["commit_title"] = commit_title
url = self._build_url("merge", base_url=self._api)
json = self._json(self._put(url, data=dumps(parameters)), 200)
if not json:
return False
return json["merged"]
def patch(self):
"""Return the patch.
:returns:
bytestring representation of the patch
:rtype:
bytes
"""
resp = self._get(
self._api, headers={"Accept": "application/vnd.github.patch"}
)
return resp.content if self._boolean(resp, 200, 404) else b""
@requires_auth
def reopen(self):
"""Re-open a closed Pull Request.
:returns:
True if successful, False otherwise
:rtype:
bool
"""
return self.update(self.title, self.body, state="open")
def review_comments(self, number=-1, etag=None):
"""Iterate over the review comments on this pull request.
:param int number:
(optional), number of comments to return. Default: -1 returns all
available comments.
:param str etag:
(optional), ETag from a previous request to the same endpoint
:returns:
generator of review comments
:rtype:
:class:`~github3.pulls.ReviewComment`
"""
url = self._build_url("comments", base_url=self._api)
return self._iter(int(number), url, ReviewComment, etag=etag)
def review_requests(self):
"""Retrieve the review requests associated with this pull request.
:returns:
review requests associated with this pull request
:rtype:
:class:`~github3.pulls.ReviewRequests`
"""
url = self._build_url("requested_reviewers", base_url=self._api)
json = self._json(self._get(url), 200)
return self._instance_or_null(ReviewRequests, json)
def reviews(self, number=-1, etag=None):
"""Iterate over the reviews associated with this pull request.
:param int number:
(optional), number of reviews to return. Default: -1 returns all
available files.
:param str etag:
(optional), ETag from a previous request to the same endpoint
:returns:
generator of reviews for this pull request
:rtype:
:class:`~github3.pulls.PullReview`
"""
url = self._build_url("reviews", base_url=self._api)
return self._iter(int(number), url, PullReview, etag=etag)
@requires_auth
def update(
self,
title=None,
body=None,
state=None,
base=None,
maintainer_can_modify=None,
):
"""Update this pull request.
:param str title:
(optional), title of the pull
:param str body:
(optional), body of the pull request
:param str state:
(optional), one of ('open', 'closed')
:param str base:
(optional), Name of the branch on the current repository that the
changes should be pulled into.
:param bool maintainer_can_modify:
(optional), Indicates whether a maintainer is allowed to modify the
pull request or not.
:returns:
True if successful, False otherwise
:rtype:
bool
"""
data = {
"title": title,
"body": body,
"state": state,
"base": base,
"maintainer_can_modify": maintainer_can_modify,
}
json = None
self._remove_none(data)
if data:
json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_attributes(json)
return True
return False
class PullRequest(_PullRequest):
"""Object for the full representation of a PullRequest.
GitHub's API returns different amounts of information about prs based
upon how that information is retrieved. This object exists to represent
the full amount of information returned for a specific pr. For example,
you would receive this class when calling
:meth:`~github3.github.GitHub.pull_request`. To provide a clear
distinction between the types of prs, github3.py uses different classes
with different sets of attributes.
.. versionchanged:: 1.0.0
This object has all of the same attributes as
:class:`~github3.pulls.ShortPullRequest` as well as the following:
.. attribute:: additions_count
The number of lines of code added in this pull request.
.. attribute:: deletions_count
The number of lines of code deleted in this pull request.
.. attribute:: comments_count
The number of comments left on this pull request.
.. attribute:: commits_count
The number of commits included in this pull request.
.. attribute:: mergeable
A boolean attribute indicating whether GitHub deems this pull request
is mergeable.
.. attribute:: mergeable_state
A string indicating whether this would be a 'clean' or 'dirty' merge.
.. attribute:: merged
A boolean attribute indicating whether the pull request has been merged
or not.
.. attribute:: merged_by
An instance of :class:`~github3.users.ShortUser` to indicate the user
who merged this pull request. If this hasn't been merged or if
:attr:`mergeable` is still being decided by GitHub this will be
``None``.
.. attribute:: review_comments_count
The number of review comments on this pull request.
"""
class_name = "Pull Request"
def _update_attributes(self, pull):
super()._update_attributes(pull)
self.additions_count = pull["additions"]
self.auto_merge = pull.get("auto_merge", None)
self.author_association = pull["author_association"]
self.comments_count = pull["comments"]
self.commits_count = pull["commits"]
self.deletions_count = pull["deletions"]
self.draft = pull["draft"]
self.mergeable = pull["mergeable"]
self.mergeable_state = pull["mergeable_state"]
self.merged = pull["merged"]
self.merged_by = pull["merged_by"]
if self.merged_by is not None:
self.merged_by = users.ShortUser(self.merged_by, self)
self.review_comments_count = pull["review_comments"]
requested_teams = pull["requested_teams"]
self.requested_teams = []
if requested_teams:
from . import orgs
self.requested_teams = [
orgs.ShortTeam(team, self) for team in requested_teams
]
requested_reviewers = pull["requested_reviewers"]
self.requested_reviewers = []
if requested_reviewers:
self.requested_reviewers = [
users.ShortUser(user, self) for user in requested_reviewers
]
class ShortPullRequest(_PullRequest):
"""Object for the shortened representation of a PullRequest.
GitHub's API returns different amounts of information about prs based
upon how that information is retrieved. Often times, when iterating over
several prs, GitHub will return less information. To provide a clear
distinction between the types of Pull Requests, github3.py uses different
classes with different sets of attributes.
.. versionadded:: 1.0.0
The attributes available on this object are:
.. attribute:: url
The URL that describes this exact pull request.
.. attribute:: assignee
.. deprecated:: 1.0.0
Use :attr:`assignees` instead.
The assignee of the pull request, if present, represented as an
instance of :class:`~github3.users.ShortUser`
.. attribute:: assignees
.. versionadded:: 1.0.0
A list of the assignees of the pull request. If not empty, a list
of instances of :class:`~github3.users.ShortUser`.
.. attribute:: base
A :class:`~github3.pulls.Base` object representing the base pull
request destination.
.. attribute:: body
The Markdown formatted body of the pull request message.
.. attribute:: body_html
The HTML formatted body of the pull request mesage.
.. attribute:: body_text
The plain-text formatted body of the pull request message.
.. attribute:: closed_at
A :class:`~datetime.datetime` object representing the date and time
when this pull request was closed.
.. attribute:: comments_url
The URL to retrieve the comments on this pull request from the API.
.. attribute:: commits_url
The URL to retrieve the commits in this pull request from the API.
.. attribute:: created_at
A :class:`~datetime.datetime` object representing the date and time
when this pull request was created.
.. attribute:: diff_url
The URL to retrieve the diff for this pull request via the API.
.. attribute:: head
A :class:`~github3.pulls.Head` object representing the head pull
request destination.
.. attribute:: html_url
The URL one would use to view this pull request in the browser.
.. attribute:: id
The unique ID of this pull request across all of GitHub.
.. attribute:: issue_url
The URL of the resource that represents this pull request as an issue.
.. attribute:: links
A dictionary provided by ``_links`` in the API response.
.. versionadded:: 1.0.0
.. attribute:: merge_commit_sha
If unmerged, holds the sha of the commit to test mergability.
If merged, holds commit sha of the merge commit, squashed commit on
the base branch or the commit that the base branch was updated to
after rebasing the PR.
.. attribute:: merged_at
A :class:`~datetime.datetime` object representing the date and time
this pull request was merged. If this pull request has not been merged
then this attribute will be ``None``.
.. attribute:: number
The number of the pull request on the repository.
.. attribute:: patch_url
The URL to retrieve the patch for this pull request via the API.
.. attribute:: rebaseable
A boolean attribute indicating whether GitHub deems this pull request
is rebaseable. None if not set.
.. attribute:: repository
A :class:`~github3.repos.repo.ShortRepository` from the :attr:`base`
instance.
.. attribute:: requested_reviewers
A list of :class:`~github3.users.ShortUser` from which a review was
requested.
.. attribute:: requested_teams
A list of :class:`~github3.orgs.ShortTeam` from which a review was
requested.
.. attribute:: review_comment_urlt
A URITemplate instance that expands to provide the review comment URL
provided a number.
.. attribute:: review_comments_url
The URl to retrieve all review comments on this pull request from the
API.
.. attribute:: state
The current state of this pull request.
.. attribute:: title
The title of this pull request.
.. attribute:: updated_at
A :class:`~datetime.datetime` instance representing the date and time
when this pull request was last updated.
.. attribute:: user
A :class:`~github3.users.ShortUser` instance representing who opened
this pull request.
"""
class_name = "Short Pull Request"
_refresh_to = PullRequest
class PullReview(models.GitHubCore):
"""Object representing a Pull Request Review returned by the API.
Please see GitHub's `Pull Review Documentation`_ for more information.
.. _PullReview Documentation:
https://developer.github.com/v3/pulls/reviews/
.. attribute:: id
The unique ID of this pull request review.
.. attribute:: author_association
.. versionadded:: 1.0.0
The relationship of this review's author to the project.
.. attribute:: body
The Markdown formatted body of this review.
.. attribute:: body_html
.. versionadded:: 1.0.0
The HTML formatted body of this review.
.. attribute:: body_text
.. versionadded:: 1.0.0
The plain-text formatted body of this review.
.. attribute:: commit_id
The SHA of the commit that the review was left on.
.. note::
It is possible for the attribute to be set to ``None``, if the
review references a commit that is no longer available in the pull
request branch, such as after a force push.
.. attribute:: html_url
.. versionadded:: 1.0.0
The URL to view this pull request in a browser.
.. attribute:: pull_request_url
The URL to retrieve the pull request via the API.
.. attribute:: state
The state of this review, e.g., the option specified in the review
dialog by the author.
.. attribute:: submitted_at
A :class:`~datetime.datetime` object representing the date and time
this review was submitted.
.. attribute:: user
A :class:`~github3.users.ShortUser` instance representing the author
of this review.
"""
def _update_attributes(self, review):
self.id = review["id"]
self.author_association = review["author_association"]
self.body = review["body"]
self.body_html = review["body_html"]
self.body_text = review["body_text"]
# NOTE(pabelanger): In some cases, commit_id could be missing on a
# PullReview.
self.commit_id = review.get("commit_id", None)
self.html_url = review["html_url"]
self.user = review["user"]
if self.user:
self.user = users.ShortUser(self.user, self)
self.state = review["state"]