Skip to content

Commit bdbec67

Browse files
author
Gauvain Pocentek
committed
Improve the snippets examples
closes python-gitlab#543
1 parent 9751ab6 commit bdbec67

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

docs/gl_objects/snippets.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Reference
99

1010
+ :class:`gitlab.v4.objects.Snippet`
1111
+ :class:`gitlab.v4.objects.SnipptManager`
12-
+ :attr:`gilab.Gitlab.snippets`
12+
+ :attr:`gitlab.Gitlab.snippets`
1313

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

@@ -42,11 +42,19 @@ Create a snippet::
4242
'file_name': 'snippet1.py',
4343
'content': open('snippet1.py').read()})
4444

45-
Update a snippet::
45+
Update the snippet attributes::
4646

4747
snippet.visibility_level = gitlab.Project.VISIBILITY_PUBLIC
4848
snippet.save()
4949

50+
To update a snippet code you need to create a ``ProjectSnippet`` object:
51+
52+
snippet = gl.snippets.get(snippet_id)
53+
project = gl.projects.get(snippet.projec_id, lazy=True)
54+
editable_snippet = project.snippets.get(snippet.id)
55+
editable_snippet.code = new_snippet_content
56+
editable_snippet.save()
57+
5058
Delete a snippet::
5159

5260
gl.snippets.delete(snippet_id)

0 commit comments

Comments
 (0)