Skip to content

Commit 9ede652

Browse files
author
Gauvain Pocentek
committed
Add support for project housekeeping
Closes #368
1 parent 4ee139a commit 9ede652

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

docs/gl_objects/projects.py

+4
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@
180180
contributors = project.repository_contributors()
181181
# end repository contributors
182182

183+
# housekeeping
184+
project.housekeeping()
185+
# end housekeeping
186+
183187
# files get
184188
f = project.files.get(file_path='README.rst', ref='master')
185189

docs/gl_objects/projects.rst

+6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ Archive/unarchive a project:
114114
Previous versions used ``archive_`` and ``unarchive_`` due to a naming issue,
115115
they have been deprecated but not yet removed.
116116

117+
Start the housekeeping job:
118+
119+
.. literalinclude:: projects.py
120+
:start-after: # housekeeping
121+
:end-before: # end housekeeping
122+
117123
List the repository tree:
118124

119125
.. literalinclude:: projects.py

gitlab/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ class GitlabCherryPickError(GitlabOperationError):
189189
pass
190190

191191

192+
class GitlabHousekeepingError(GitlabOperationError):
193+
pass
194+
195+
192196
def raise_error_from_response(response, error, expected_code=200):
193197
"""Tries to parse gitlab error message from response and raises error.
194198

gitlab/v4/objects.py

+16
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,22 @@ def trigger_pipeline(self, ref, token, variables={}, **kwargs):
23282328
post_data = {'ref': ref, 'token': token, 'variables': variables}
23292329
self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
23302330

2331+
@cli.register_custom_action('Project')
2332+
@exc.on_http_error(exc.GitlabHousekeepingError)
2333+
def housekeeping(self, **kwargs):
2334+
"""Start the housekeeping task.
2335+
2336+
Args:
2337+
**kwargs: Extra options to send to the server (e.g. sudo)
2338+
2339+
Raises:
2340+
GitlabAuthenticationError: If authentication is not correct
2341+
GitlabHousekeepingError: If the server failed to perform the
2342+
request
2343+
"""
2344+
path = '/projects/%s/housekeeping' % self.get_id()
2345+
self.manager.gitlab.http_post(path, **kwargs)
2346+
23312347
# see #56 - add file attachment features
23322348
@cli.register_custom_action('Project', ('filename', 'filepath'))
23332349
@exc.on_http_error(exc.GitlabUploadError)

tools/python_test_v4.py

+3
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@
331331
commit.comments.create({'note': 'This is a commit comment'})
332332
assert(len(commit.comments.list()) == 1)
333333

334+
# housekeeping
335+
admin_project.housekeeping()
336+
334337
# repository
335338
tree = admin_project.repository_tree()
336339
assert(len(tree) != 0)

0 commit comments

Comments
 (0)