Skip to content

Commit 40b9f4d

Browse files
author
Gauvain Pocentek
committed
Add support for the gitlab CI lint API
1 parent 0cc9828 commit 40b9f4d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

gitlab/__init__.py

+23
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,29 @@ def version(self):
227227

228228
return self._server_version, self._server_revision
229229

230+
def lint(self, content, **kwargs):
231+
"""Validate a gitlab CI configuration.
232+
233+
Args:
234+
content (txt): The .gitlab-ci.yml content
235+
**kwargs: Extra options to send to the server (e.g. sudo)
236+
237+
Raises:
238+
GitlabAuthenticationError: If authentication is not correct
239+
GitlabVerifyError: If the validation could not be done
240+
241+
Returns:
242+
tuple: (True, []) if the file is valid, (False, errors(list))
243+
otherwise
244+
"""
245+
post_data = {'content': content}
246+
try:
247+
data = self.http_post('/ci/lint', post_data=post_data, **kwargs)
248+
except Exception:
249+
raise GitlabVerifyError
250+
251+
return (data['status'] == 'valid', data['errors'])
252+
230253
def markdown(self, text, gfm=False, project=None, **kwargs):
231254
"""Render an arbitrary Markdown document.
232255

tools/python_test_v4.py

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
# html = gl.markdown('foo')
6565
# assert('foo' in html)
6666

67+
success, errors = gl.lint('Invalid')
68+
assert(success is False)
69+
assert(errors)
70+
6771
# sidekiq
6872
out = gl.sidekiq.queue_metrics()
6973
assert(isinstance(out, dict))

0 commit comments

Comments
 (0)