comparison venv/lib/python2.7/site-packages/github/Commit.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 Vincent Jacques <vincent@vincent-jacques.net> #
6 # Copyright 2012 Zearin <zearin@gonk.net> #
7 # Copyright 2013 AKFish <akfish@gmail.com> #
8 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
9 # Copyright 2013 martinqt <m.ki2@laposte.net> #
10 # #
11 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ #
12 # #
13 # PyGithub is free software: you can redistribute it and/or modify it under #
14 # the terms of the GNU Lesser General Public License as published by the Free #
15 # Software Foundation, either version 3 of the License, or (at your option) #
16 # any later version. #
17 # #
18 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
21 # details. #
22 # #
23 # You should have received a copy of the GNU Lesser General Public License #
24 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
25 # #
26 # ##############################################################################
27
28 import github.GithubObject
29 import github.PaginatedList
30
31 import github.GitCommit
32 import github.NamedUser
33 import github.CommitStatus
34 import github.File
35 import github.CommitStats
36 import github.CommitComment
37
38
39 class Commit(github.GithubObject.CompletableGithubObject):
40 """
41 This class represents Commits. The reference can be found here http://developer.github.com/v3/git/commits/
42 """
43
44 @property
45 def author(self):
46 """
47 :type: :class:`github.NamedUser.NamedUser`
48 """
49 self._completeIfNotSet(self._author)
50 return self._author.value
51
52 @property
53 def comments_url(self):
54 """
55 :type: string
56 """
57 self._completeIfNotSet(self._comments_url)
58 return self._comments_url.value
59
60 @property
61 def commit(self):
62 """
63 :type: :class:`github.GitCommit.GitCommit`
64 """
65 self._completeIfNotSet(self._commit)
66 return self._commit.value
67
68 @property
69 def committer(self):
70 """
71 :type: :class:`github.NamedUser.NamedUser`
72 """
73 self._completeIfNotSet(self._committer)
74 return self._committer.value
75
76 @property
77 def files(self):
78 """
79 :type: list of :class:`github.File.File`
80 """
81 self._completeIfNotSet(self._files)
82 return self._files.value
83
84 @property
85 def html_url(self):
86 """
87 :type: string
88 """
89 self._completeIfNotSet(self._html_url)
90 return self._html_url.value
91
92 @property
93 def parents(self):
94 """
95 :type: list of :class:`github.Commit.Commit`
96 """
97 self._completeIfNotSet(self._parents)
98 return self._parents.value
99
100 @property
101 def sha(self):
102 """
103 :type: string
104 """
105 self._completeIfNotSet(self._sha)
106 return self._sha.value
107
108 @property
109 def stats(self):
110 """
111 :type: :class:`github.CommitStats.CommitStats`
112 """
113 self._completeIfNotSet(self._stats)
114 return self._stats.value
115
116 @property
117 def url(self):
118 """
119 :type: string
120 """
121 self._completeIfNotSet(self._url)
122 return self._url.value
123
124 def create_comment(self, body, line=github.GithubObject.NotSet, path=github.GithubObject.NotSet, position=github.GithubObject.NotSet):
125 """
126 :calls: `POST /repos/:owner/:repo/commits/:sha/comments <http://developer.github.com/v3/repos/comments>`_
127 :param body: string
128 :param line: integer
129 :param path: string
130 :param position: integer
131 :rtype: :class:`github.CommitComment.CommitComment`
132 """
133 assert isinstance(body, (str, unicode)), body
134 assert line is github.GithubObject.NotSet or isinstance(line, (int, long)), line
135 assert path is github.GithubObject.NotSet or isinstance(path, (str, unicode)), path
136 assert position is github.GithubObject.NotSet or isinstance(position, (int, long)), position
137 post_parameters = {
138 "body": body,
139 }
140 if line is not github.GithubObject.NotSet:
141 post_parameters["line"] = line
142 if path is not github.GithubObject.NotSet:
143 post_parameters["path"] = path
144 if position is not github.GithubObject.NotSet:
145 post_parameters["position"] = position
146 headers, data = self._requester.requestJsonAndCheck(
147 "POST",
148 self.url + "/comments",
149 input=post_parameters
150 )
151 return github.CommitComment.CommitComment(self._requester, headers, data, completed=True)
152
153 def create_status(self, state, target_url=github.GithubObject.NotSet, description=github.GithubObject.NotSet):
154 """
155 :calls: `POST /repos/:owner/:repo/statuses/:sha <http://developer.github.com/v3/repos/statuses>`_
156 :param state: string
157 :param target_url: string
158 :param description: string
159 :rtype: :class:`github.CommitStatus.CommitStatus`
160 """
161 assert isinstance(state, (str, unicode)), state
162 assert target_url is github.GithubObject.NotSet or isinstance(target_url, (str, unicode)), target_url
163 assert description is github.GithubObject.NotSet or isinstance(description, (str, unicode)), description
164 post_parameters = {
165 "state": state,
166 }
167 if target_url is not github.GithubObject.NotSet:
168 post_parameters["target_url"] = target_url
169 if description is not github.GithubObject.NotSet:
170 post_parameters["description"] = description
171 headers, data = self._requester.requestJsonAndCheck(
172 "POST",
173 self._parentUrl(self._parentUrl(self.url)) + "/statuses/" + self.sha,
174 input=post_parameters
175 )
176 return github.CommitStatus.CommitStatus(self._requester, headers, data, completed=True)
177
178 def get_comments(self):
179 """
180 :calls: `GET /repos/:owner/:repo/commits/:sha/comments <http://developer.github.com/v3/repos/comments>`_
181 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CommitComment.CommitComment`
182 """
183 return github.PaginatedList.PaginatedList(
184 github.CommitComment.CommitComment,
185 self._requester,
186 self.url + "/comments",
187 None
188 )
189
190 def get_statuses(self):
191 """
192 :calls: `GET /repos/:owner/:repo/statuses/:ref <http://developer.github.com/v3/repos/statuses>`_
193 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CommitStatus.CommitStatus`
194 """
195 return github.PaginatedList.PaginatedList(
196 github.CommitStatus.CommitStatus,
197 self._requester,
198 self._parentUrl(self._parentUrl(self.url)) + "/statuses/" + self.sha,
199 None
200 )
201
202 @property
203 def _identity(self):
204 return self.sha
205
206 def _initAttributes(self):
207 self._author = github.GithubObject.NotSet
208 self._comments_url = github.GithubObject.NotSet
209 self._commit = github.GithubObject.NotSet
210 self._committer = github.GithubObject.NotSet
211 self._files = github.GithubObject.NotSet
212 self._html_url = github.GithubObject.NotSet
213 self._parents = github.GithubObject.NotSet
214 self._sha = github.GithubObject.NotSet
215 self._stats = github.GithubObject.NotSet
216 self._url = github.GithubObject.NotSet
217
218 def _useAttributes(self, attributes):
219 if "author" in attributes: # pragma no branch
220 self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"])
221 if "comments_url" in attributes: # pragma no branch
222 self._comments_url = self._makeStringAttribute(attributes["comments_url"])
223 if "commit" in attributes: # pragma no branch
224 self._commit = self._makeClassAttribute(github.GitCommit.GitCommit, attributes["commit"])
225 if "committer" in attributes: # pragma no branch
226 self._committer = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["committer"])
227 if "files" in attributes: # pragma no branch
228 self._files = self._makeListOfClassesAttribute(github.File.File, attributes["files"])
229 if "html_url" in attributes: # pragma no branch
230 self._html_url = self._makeStringAttribute(attributes["html_url"])
231 if "parents" in attributes: # pragma no branch
232 self._parents = self._makeListOfClassesAttribute(Commit, attributes["parents"])
233 if "sha" in attributes: # pragma no branch
234 self._sha = self._makeStringAttribute(attributes["sha"])
235 if "stats" in attributes: # pragma no branch
236 self._stats = self._makeClassAttribute(github.CommitStats.CommitStats, attributes["stats"])
237 if "url" in attributes: # pragma no branch
238 self._url = self._makeStringAttribute(attributes["url"])