|
47 | 47 | ) |
48 | 48 | from .push_rulesimportProjectPushRulesManager |
49 | 49 | from .releasesimportProjectReleaseManager |
| 50 | +from .repositoriesimportRepositoryMixin |
50 | 51 | from .runnersimportProjectRunnerManager |
51 | 52 | from .servicesimportProjectServiceManager |
52 | 53 | from .snippetsimportProjectSnippetManager |
@@ -100,7 +101,7 @@ class GroupProjectManager(ListMixin, RESTManager): |
100 | 101 | ) |
101 | 102 |
|
102 | 103 |
|
103 | | -classProject(RefreshMixin,SaveMixin,ObjectDeleteMixin,RESTObject): |
| 104 | +classProject(RefreshMixin,SaveMixin,ObjectDeleteMixin,RepositoryMixin,RESTObject): |
104 | 105 | _short_print_attr="path" |
105 | 106 | _managers= ( |
106 | 107 | ("access_tokens","ProjectAccessTokenManager"), |
@@ -154,187 +155,6 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RESTObject): |
154 | 155 | ("deploytokens","ProjectDeployTokenManager"), |
155 | 156 | ) |
156 | 157 |
|
157 | | -@cli.register_custom_action("Project", ("submodule","branch","commit_sha")) |
158 | | -@exc.on_http_error(exc.GitlabUpdateError) |
159 | | -defupdate_submodule(self,submodule,branch,commit_sha,**kwargs): |
160 | | -"""Update a project submodule |
161 | | -
|
162 | | - Args: |
163 | | - submodule (str): Full path to the submodule |
164 | | - branch (str): Name of the branch to commit into |
165 | | - commit_sha (str): Full commit SHA to update the submodule to |
166 | | - commit_message (str): Commit message. If no message is provided, a default one will be set (optional) |
167 | | -
|
168 | | - Raises: |
169 | | - GitlabAuthenticationError: If authentication is not correct |
170 | | - GitlabPutError: If the submodule could not be updated |
171 | | - """ |
172 | | - |
173 | | -submodule=submodule.replace("/","%2F")# .replace('.', '%2E') |
174 | | -path="/projects/%s/repository/submodules/%s"% (self.get_id(),submodule) |
175 | | -data= {"branch":branch,"commit_sha":commit_sha} |
176 | | -if"commit_message"inkwargs: |
177 | | -data["commit_message"]=kwargs["commit_message"] |
178 | | -returnself.manager.gitlab.http_put(path,post_data=data) |
179 | | - |
180 | | -@cli.register_custom_action("Project",tuple(), ("path","ref","recursive")) |
181 | | -@exc.on_http_error(exc.GitlabGetError) |
182 | | -defrepository_tree(self,path="",ref="",recursive=False,**kwargs): |
183 | | -"""Return a list of files in the repository. |
184 | | -
|
185 | | - Args: |
186 | | - path (str): Path of the top folder (/ by default) |
187 | | - ref (str): Reference to a commit or branch |
188 | | - recursive (bool): Whether to get the tree recursively |
189 | | - all (bool): If True, return all the items, without pagination |
190 | | - per_page (int): Number of items to retrieve per request |
191 | | - page (int): ID of the page to return (starts with page 1) |
192 | | - as_list (bool): If set to False and no pagination option is |
193 | | - defined, return a generator instead of a list |
194 | | - **kwargs: Extra options to send to the server (e.g. sudo) |
195 | | -
|
196 | | - Raises: |
197 | | - GitlabAuthenticationError: If authentication is not correct |
198 | | - GitlabGetError: If the server failed to perform the request |
199 | | -
|
200 | | - Returns: |
201 | | - list: The representation of the tree |
202 | | - """ |
203 | | -gl_path="/projects/%s/repository/tree"%self.get_id() |
204 | | -query_data= {"recursive":recursive} |
205 | | -ifpath: |
206 | | -query_data["path"]=path |
207 | | -ifref: |
208 | | -query_data["ref"]=ref |
209 | | -returnself.manager.gitlab.http_list(gl_path,query_data=query_data,**kwargs) |
210 | | - |
211 | | -@cli.register_custom_action("Project", ("sha",)) |
212 | | -@exc.on_http_error(exc.GitlabGetError) |
213 | | -defrepository_blob(self,sha,**kwargs): |
214 | | -"""Return a file by blob SHA. |
215 | | -
|
216 | | - Args: |
217 | | - sha(str): ID of the blob |
218 | | - **kwargs: Extra options to send to the server (e.g. sudo) |
219 | | -
|
220 | | - Raises: |
221 | | - GitlabAuthenticationError: If authentication is not correct |
222 | | - GitlabGetError: If the server failed to perform the request |
223 | | -
|
224 | | - Returns: |
225 | | - dict: The blob content and metadata |
226 | | - """ |
227 | | - |
228 | | -path="/projects/%s/repository/blobs/%s"% (self.get_id(),sha) |
229 | | -returnself.manager.gitlab.http_get(path,**kwargs) |
230 | | - |
231 | | -@cli.register_custom_action("Project", ("sha",)) |
232 | | -@exc.on_http_error(exc.GitlabGetError) |
233 | | -defrepository_raw_blob( |
234 | | -self,sha,streamed=False,action=None,chunk_size=1024,**kwargs |
235 | | - ): |
236 | | -"""Return the raw file contents for a blob. |
237 | | -
|
238 | | - Args: |
239 | | - sha(str): ID of the blob |
240 | | - streamed (bool): If True the data will be processed by chunks of |
241 | | - `chunk_size` and each chunk is passed to `action` for |
242 | | - treatment |
243 | | - action (callable): Callable responsible of dealing with chunk of |
244 | | - data |
245 | | - chunk_size (int): Size of each chunk |
246 | | - **kwargs: Extra options to send to the server (e.g. sudo) |
247 | | -
|
248 | | - Raises: |
249 | | - GitlabAuthenticationError: If authentication is not correct |
250 | | - GitlabGetError: If the server failed to perform the request |
251 | | -
|
252 | | - Returns: |
253 | | - str: The blob content if streamed is False, None otherwise |
254 | | - """ |
255 | | -path="/projects/%s/repository/blobs/%s/raw"% (self.get_id(),sha) |
256 | | -result=self.manager.gitlab.http_get( |
257 | | -path,streamed=streamed,raw=True,**kwargs |
258 | | - ) |
259 | | -returnutils.response_content(result,streamed,action,chunk_size) |
260 | | - |
261 | | -@cli.register_custom_action("Project", ("from_","to")) |
262 | | -@exc.on_http_error(exc.GitlabGetError) |
263 | | -defrepository_compare(self,from_,to,**kwargs): |
264 | | -"""Return a diff between two branches/commits. |
265 | | -
|
266 | | - Args: |
267 | | - from_(str): Source branch/SHA |
268 | | - to(str): Destination branch/SHA |
269 | | - **kwargs: Extra options to send to the server (e.g. sudo) |
270 | | -
|
271 | | - Raises: |
272 | | - GitlabAuthenticationError: If authentication is not correct |
273 | | - GitlabGetError: If the server failed to perform the request |
274 | | -
|
275 | | - Returns: |
276 | | - str: The diff |
277 | | - """ |
278 | | -path="/projects/%s/repository/compare"%self.get_id() |
279 | | -query_data= {"from":from_,"to":to} |
280 | | -returnself.manager.gitlab.http_get(path,query_data=query_data,**kwargs) |
281 | | - |
282 | | -@cli.register_custom_action("Project") |
283 | | -@exc.on_http_error(exc.GitlabGetError) |
284 | | -defrepository_contributors(self,**kwargs): |
285 | | -"""Return a list of contributors for the project. |
286 | | -
|
287 | | - Args: |
288 | | - all (bool): If True, return all the items, without pagination |
289 | | - per_page (int): Number of items to retrieve per request |
290 | | - page (int): ID of the page to return (starts with page 1) |
291 | | - as_list (bool): If set to False and no pagination option is |
292 | | - defined, return a generator instead of a list |
293 | | - **kwargs: Extra options to send to the server (e.g. sudo) |
294 | | -
|
295 | | - Raises: |
296 | | - GitlabAuthenticationError: If authentication is not correct |
297 | | - GitlabGetError: If the server failed to perform the request |
298 | | -
|
299 | | - Returns: |
300 | | - list: The contributors |
301 | | - """ |
302 | | -path="/projects/%s/repository/contributors"%self.get_id() |
303 | | -returnself.manager.gitlab.http_list(path,**kwargs) |
304 | | - |
305 | | -@cli.register_custom_action("Project",tuple(), ("sha",)) |
306 | | -@exc.on_http_error(exc.GitlabListError) |
307 | | -defrepository_archive( |
308 | | -self,sha=None,streamed=False,action=None,chunk_size=1024,**kwargs |
309 | | - ): |
310 | | -"""Return a tarball of the repository. |
311 | | -
|
312 | | - Args: |
313 | | - sha (str): ID of the commit (default branch by default) |
314 | | - streamed (bool): If True the data will be processed by chunks of |
315 | | - `chunk_size` and each chunk is passed to `action` for |
316 | | - treatment |
317 | | - action (callable): Callable responsible of dealing with chunk of |
318 | | - data |
319 | | - chunk_size (int): Size of each chunk |
320 | | - **kwargs: Extra options to send to the server (e.g. sudo) |
321 | | -
|
322 | | - Raises: |
323 | | - GitlabAuthenticationError: If authentication is not correct |
324 | | - GitlabListError: If the server failed to perform the request |
325 | | -
|
326 | | - Returns: |
327 | | - str: The binary data of the archive |
328 | | - """ |
329 | | -path="/projects/%s/repository/archive"%self.get_id() |
330 | | -query_data= {} |
331 | | -ifsha: |
332 | | -query_data["sha"]=sha |
333 | | -result=self.manager.gitlab.http_get( |
334 | | -path,query_data=query_data,raw=True,streamed=streamed,**kwargs |
335 | | - ) |
336 | | -returnutils.response_content(result,streamed,action,chunk_size) |
337 | | - |
338 | 158 | @cli.register_custom_action("Project", ("forked_from_id",)) |
339 | 159 | @exc.on_http_error(exc.GitlabCreateError) |
340 | 160 | defcreate_fork_relation(self,forked_from_id,**kwargs): |
@@ -366,21 +186,6 @@ def delete_fork_relation(self, **kwargs): |
366 | 186 | path="/projects/%s/fork"%self.get_id() |
367 | 187 | self.manager.gitlab.http_delete(path,**kwargs) |
368 | 188 |
|
369 | | -@cli.register_custom_action("Project") |
370 | | -@exc.on_http_error(exc.GitlabDeleteError) |
371 | | -defdelete_merged_branches(self,**kwargs): |
372 | | -"""Delete merged branches. |
373 | | -
|
374 | | - Args: |
375 | | - **kwargs: Extra options to send to the server (e.g. sudo) |
376 | | -
|
377 | | - Raises: |
378 | | - GitlabAuthenticationError: If authentication is not correct |
379 | | - GitlabDeleteError: If the server failed to perform the request |
380 | | - """ |
381 | | -path="/projects/%s/repository/merged_branches"%self.get_id() |
382 | | -self.manager.gitlab.http_delete(path,**kwargs) |
383 | | - |
384 | 189 | @cli.register_custom_action("Project") |
385 | 190 | @exc.on_http_error(exc.GitlabGetError) |
386 | 191 | deflanguages(self,**kwargs): |
|