diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-29 10:50:08 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-29 10:50:08 +0200 |
commit | 40b9f4d62d5b9853bfd63317d8ad578b4525e665 (patch) | |
tree | 4e9143e7a6b0313ee799295e3b4815f265066bd6 | |
parent | 0cc9828fda25531a57010cb310f23d3c185e63a6 (diff) | |
download | gitlab-40b9f4d62d5b9853bfd63317d8ad578b4525e665.tar.gz |
Add support for the gitlab CI lint API
-rw-r--r-- | gitlab/__init__.py | 23 | ||||
-rw-r--r-- | tools/python_test_v4.py | 4 |
2 files changed, 27 insertions, 0 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py index fd4abcf..8d522b4 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -227,6 +227,29 @@ class Gitlab(object): return self._server_version, self._server_revision + def lint(self, content, **kwargs): + """Validate a gitlab CI configuration. + + Args: + content (txt): The .gitlab-ci.yml content + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabVerifyError: If the validation could not be done + + Returns: + tuple: (True, []) if the file is valid, (False, errors(list)) + otherwise + """ + post_data = {'content': content} + try: + data = self.http_post('/ci/lint', post_data=post_data, **kwargs) + except Exception: + raise GitlabVerifyError + + return (data['status'] == 'valid', data['errors']) + def markdown(self, text, gfm=False, project=None, **kwargs): """Render an arbitrary Markdown document. diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py index 47d9af2..558d7ab 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -64,6 +64,10 @@ assert(isinstance(gl.user, gitlab.v4.objects.CurrentUser)) # html = gl.markdown('foo') # assert('foo' in html) +success, errors = gl.lint('Invalid') +assert(success is False) +assert(errors) + # sidekiq out = gl.sidekiq.queue_metrics() assert(isinstance(out, dict)) |