Skip to content

Commit

Permalink
Improve the snippets examples
Browse files Browse the repository at this point in the history
closes #543
  • Loading branch information
Gauvain Pocentek committed Jul 3, 2018
1 parent 9751ab6 commit bdbec67
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/gl_objects/snippets.rst
Expand Up @@ -9,7 +9,7 @@ Reference

+ :class:`gitlab.v4.objects.Snippet`
+ :class:`gitlab.v4.objects.SnipptManager`
+ :attr:`gilab.Gitlab.snippets`
+ :attr:`gitlab.Gitlab.snippets`

* GitLab API: https://docs.gitlab.com/ce/api/snippets.html

Expand Down Expand Up @@ -42,11 +42,19 @@ Create a snippet::
'file_name': 'snippet1.py',
'content': open('snippet1.py').read()})

Update a snippet::
Update the snippet attributes::

snippet.visibility_level = gitlab.Project.VISIBILITY_PUBLIC
snippet.save()

To update a snippet code you need to create a ``ProjectSnippet`` object:

snippet = gl.snippets.get(snippet_id)
project = gl.projects.get(snippet.projec_id, lazy=True)
editable_snippet = project.snippets.get(snippet.id)
editable_snippet.code = new_snippet_content
editable_snippet.save()

Delete a snippet::

gl.snippets.delete(snippet_id)
Expand Down

0 comments on commit bdbec67

Please sign in to comment.