1
1
# -*- coding: utf-8 -*-
2
- """
3
- github3.repos.comparison
4
- ========================
5
-
6
- This module contains the Comparison object for comparing two commits via the
7
- GitHub API.
8
-
9
- """
2
+ """This module contains the Comparison object."""
10
3
from __future__ import unicode_literals
11
4
12
5
from . import commit
6
+ from .. import models
13
7
14
- from ..models import GitHubCore
15
8
9
+ class Comparison (models .GitHubCore ):
10
+ """A representation of a comparison between two or more commit objects.
16
11
17
- class Comparison (GitHubCore ):
18
- """The :class:`Comparison <Comparison>` object. This encapsulates the
19
- information returned by GitHub comparing two commit objects in a
20
- repository.
12
+ See also:
13
+ http://developer.github.com/v3/repos/commits/#compare-two-commits
21
14
22
- Two comparison instances can be checked like so ::
15
+ This object has the following attributes ::
23
16
24
- c1 == c2
25
- c1 != c2
17
+ .. attribute:: ahead_by
26
18
27
- And is equivalent to::
19
+ The number of commits between the head and base commit.
28
20
29
- c1.commits == c2.commits
30
- c1.commits != c2.commits
21
+ .. attribute:: base_commit
31
22
32
- See also:
33
- http://developer.github.com/v3/repos/commits/#compare-two-commits
34
- """
23
+ A :class:`~github3.repos.commit.ShortCommit` representing the base
24
+ commit in this comparison.
35
25
36
- def _update_attributes (self , compare ):
37
- self ._api = self ._get_attribute (compare , 'url' )
26
+ .. attribute:: behind_by
27
+
28
+ The number of commits the head commit is behind the base.
29
+
30
+ .. attribute:: commits
38
31
39
- #: URL to view the comparison at GitHub
40
- self . html_url = self . _get_attribute ( compare , 'html_url' )
32
+ A list of :class:`~github3.repos.commit.ShortCommit` objects
33
+ representing the commits in the comparison.
41
34
42
- #: Permanent link to this comparison.
43
- self .permalink_url = self ._get_attribute (compare , 'permalink_url' )
35
+ .. attribute:: diff_url
44
36
45
- #: URL to see the diff between the two commits.
46
- self .diff_url = self ._get_attribute (compare , 'diff_url' )
37
+ The URL to retrieve the diff between the head and base commits.
47
38
48
- #: Patch URL at GitHub for the comparison.
49
- self .patch_url = self ._get_attribute (compare , 'patch_url' )
39
+ .. attribute:: files
50
40
51
- #: :class:`RepoCommit <github3.repos.commit.RepoCommit>` object
52
- #: representing the base of comparison.
53
- self .base_commit = self ._class_attribute (
54
- compare , 'base_commit' , commit .ShortCommit , None
55
- )
41
+ A list of dictionaries describing each of the modified files in the
42
+ comparison.
56
43
57
- #: Behind or ahead.
58
- self .status = self ._get_attribute (compare , 'status' )
44
+ .. attribute:: html_url
59
45
60
- #: Number of commits ahead by.
61
- self .ahead_by = self ._get_attribute (compare , 'ahead_by' )
46
+ The URL to view the comparison in a browser.
62
47
63
- #: Number of commits behind by.
64
- self .behind_by = self ._get_attribute (compare , 'behind_by' )
48
+ .. attribute:: patch_url
65
49
66
- #: Number of commits difference in the comparison.
67
- self .total_commits = self ._get_attribute (compare , 'total_commits' )
50
+ The URL to retrieve the patch-formatted diff of this comparison.
68
51
69
- #: List of :class:`RepoCommit <github3.repos.commit.RepoCommit>`
70
- #: objects.
71
- self .commits = self ._get_attribute (compare , 'commits' , [])
52
+ .. attribute:: permalink_url
53
+
54
+ The permanent URL to retrieve this comparison.
55
+
56
+ .. attribute:: status
57
+
58
+ Whether the head commit is ahead or behind of base.
59
+
60
+ .. attribute:: total_commits
61
+
62
+ The total number of commits difference.
63
+ """
64
+
65
+ def _update_attributes (self , compare ):
66
+ self ._api = compare ['url' ]
67
+ self .ahead_by = compare ['ahead_by' ]
68
+ self .base_commit = commit .ShortCommit (compare ['base_commit' ], self )
69
+ self .behind_by = compare ['behind_by' ]
70
+ self .commits = compare ['commits' ]
72
71
if self .commits :
73
72
self .commits = [
74
73
commit .ShortCommit (com , self ) for com in self .commits
75
74
]
76
-
77
- #: List of dicts describing the files modified.
78
- self .files = self ._get_attribute (compare , 'files' , [])
79
-
75
+ self .diff_url = compare ['diff_url' ]
76
+ self .files = compare ['files' ]
77
+ self .html_url = compare ['html_url' ]
78
+ self .patch_url = compare ['patch_url' ]
79
+ self .permalink_url = compare ['permalink_url' ]
80
+ self .status = compare ['status' ]
81
+ self .total_commits = compare ['total_commits' ]
80
82
self ._uniq = self .commits
81
83
82
84
def _repr (self ):
@@ -85,8 +87,10 @@ def _repr(self):
85
87
def diff (self ):
86
88
"""Retrieve the diff for this comparison.
87
89
88
- :returns: the diff as a bytes object
89
- :rtype: bytes
90
+ :returns:
91
+ the diff as a bytes object
92
+ :rtype:
93
+ bytes
90
94
"""
91
95
resp = self ._get (self ._api ,
92
96
headers = {'Accept' : 'application/vnd.github.diff' })
@@ -95,8 +99,10 @@ def diff(self):
95
99
def patch (self ):
96
100
"""Retrieve the patch formatted diff for this commit.
97
101
98
- :returns: the patch as a bytes object
99
- :rtype: bytes
102
+ :returns:
103
+ the patch as a bytes object
104
+ :rtype:
105
+ bytes
100
106
"""
101
107
resp = self ._get (self ._api ,
102
108
headers = {'Accept' : 'application/vnd.github.patch' })
0 commit comments