diff options
-rw-r--r-- | gitlab/__init__.py | 27 | ||||
-rw-r--r-- | gitlab/exceptions.py | 4 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 4 | ||||
-rw-r--r-- | tools/python_test_v4.py | 4 |
4 files changed, 37 insertions, 2 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 134cada..fd4abcf 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -227,6 +227,33 @@ class Gitlab(object): return self._server_version, self._server_revision + def markdown(self, text, gfm=False, project=None, **kwargs): + """Render an arbitrary Markdown document. + + Args: + text (str): The markdown text to render + gfm (bool): Render text using GitLab Flavored Markdown. Default is + False + project (str): Full path of a project used a context when `gfm` is + True + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabMarkdownError: If the server cannot perform the request + + Returns: + str: The HTML rendering of the markdown text. + """ + post_data = {'text': text, 'gfm': gfm} + if project is not None: + post_data['project'] = project + try: + data = self.http_post('/markdown', post_data=post_data, **kwargs) + except Exception: + raise GitlabMarkdownError + return data['html'] + def _construct_url(self, id_, obj, parameters, action=None): if 'next_url' in parameters: return parameters['next_url'] diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 9e3fa4a..64f3243 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -205,6 +205,10 @@ class GitlabStopError(GitlabOperationError): pass +class GitlabMarkdownError(GitlabOperationError): + pass + + def on_http_error(error): """Manage GitlabHttpError exceptions. diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 65134db..2def952 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -1981,8 +1981,8 @@ class ProjectLabelManager(ListMixin, CreateMixin, UpdateMixin, DeleteMixin, **kwargs: Extra options to send to the Gitlab server (e.g. sudo) Raises: - GitlabAuthenticationError: If authentication is not correct. - GitlabDeleteError: If the server cannot perform the request. + GitlabAuthenticationError: If authentication is not correct + GitlabDeleteError: If the server cannot perform the request """ self.gitlab.http_delete(self.path, query_data={'name': name}, **kwargs) diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py index 24b729d..b9c4e63 100644 --- a/tools/python_test_v4.py +++ b/tools/python_test_v4.py @@ -60,6 +60,10 @@ gl = gitlab.Gitlab.from_config(config_files=['/tmp/python-gitlab.cfg']) gl.auth() assert(isinstance(gl.user, gitlab.v4.objects.CurrentUser)) +# markdown (need to wait for gitlab 11 to enable the test) +# html = gl.markdown('foo') +# assert('foo' in html) + # sidekiq out = gl.sidekiq.queue_metrics() assert(isinstance(out, dict)) |