| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dd79eda commit 35b7f75
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -273,3 +273,47 @@ | |||
| 273 | 273 | # tags release | |
| 274 | 274 | tag.set_release_description('awesome v1.0 release') | |
| 275 | 275 | # end tags release | |
| 276 | + | ||
| 277 | + # snippets list | ||
| 278 | + snippets = gl.project_snippets.list(project_id=1) | ||
| 279 | + # or | ||
| 280 | + snippets = project.snippets.list() | ||
| 281 | + # end snippets list | ||
| 282 | + | ||
| 283 | + # snippets get | ||
| 284 | + snippet = gl.project_snippets.list(snippet_id, project_id=1) | ||
| 285 | + # or | ||
| 286 | + snippets = project.snippets.list(snippet_id) | ||
| 287 | + # end snippets get | ||
| 288 | + | ||
| 289 | + # snippets create | ||
| 290 | + snippet = gl.project_snippets.create({'title': 'sample 1', | ||
| 291 | + 'file_name': 'foo.py', | ||
| 292 | + 'code': 'import gitlab', | ||
| 293 | + 'visibility_level': | ||
| 294 | + Project.VISIBILITY_PRIVATE}, | ||
| 295 | + project_id=1) | ||
| 296 | + # or | ||
| 297 | + snippet = project.snippets.create({'title': 'sample 1', | ||
| 298 | + 'file_name': 'foo.py', | ||
| 299 | + 'code': 'import gitlab', | ||
| 300 | + 'visibility_level': | ||
| 301 | + Project.VISIBILITY_PRIVATE}) | ||
| 302 | + # end snippets create | ||
| 303 | + | ||
| 304 | + # snippets content | ||
| 305 | + print(snippet.content()) | ||
| 306 | + # end snippets content | ||
| 307 | + | ||
| 308 | + # snippets update | ||
| 309 | + snippet.code = 'import gitlab\nimport whatever' | ||
| 310 | + snippet.save | ||
| 311 | + # end snippets update | ||
| 312 | + | ||
| 313 | + # snippets delete | ||
| 314 | + gl.project_snippets.delete(snippet_id, project_id=1) | ||
| 315 | + # or | ||
| 316 | + project.snippets.delete(snippet_id) | ||
| 317 | + # or | ||
| 318 | + snippet.delete() | ||
| 319 | + # end snippets delete | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -206,6 +206,54 @@ Delete a tag: | |||
| 206 | 206 | :start-after: # tags delete | |
| 207 | 207 | :end-before: # end tags delete | |
| 208 | 208 | ||
| 209 | + Snippets | ||
| 210 | + -------- | ||
| 211 | + | ||
| 212 | + Use :class:`~gitlab.objects.ProjectSnippet` objects to manipulate snippets. The | ||
| 213 | + :attr:`gitlab.Gitlab.project_snippets` and :attr:`Project.snippets | ||
| 214 | + <gitlab.objects.Project.snippets>` manager objects provide helper functions. | ||
| 215 | + | ||
| 216 | + List the project snippets: | ||
| 217 | + | ||
| 218 | + .. literalinclude:: projects.py | ||
| 219 | + :start-after: # snippets list | ||
| 220 | + :end-before: # end snippets list | ||
| 221 | + | ||
| 222 | + Get a snippet: | ||
| 223 | + | ||
| 224 | + .. literalinclude:: projects.py | ||
| 225 | + :start-after: # snippets get | ||
| 226 | + :end-before: # end snippets get | ||
| 227 | + | ||
| 228 | + Get the content of a snippet: | ||
| 229 | + | ||
| 230 | + .. literalinclude:: projects.py | ||
| 231 | + :start-after: # snippets content | ||
| 232 | + :end-before: # end snippets content | ||
| 233 | + | ||
| 234 | + .. warning:: | ||
| 235 | + | ||
| 236 | + The snippet content is entirely stored in memory unless you use the | ||
| 237 | + streaming feature. See :ref:`the artifacts example <streaming_example>`. | ||
| 238 | + | ||
| 239 | + Create a snippet: | ||
| 240 | + | ||
| 241 | + .. literalinclude:: projects.py | ||
| 242 | + :start-after: # snippets create | ||
| 243 | + :end-before: # end snippets create | ||
| 244 | + | ||
| 245 | + Update a snippet: | ||
| 246 | + | ||
| 247 | + .. literalinclude:: projects.py | ||
| 248 | + :start-after: # snippets update | ||
| 249 | + :end-before: # end snippets update | ||
| 250 | + | ||
| 251 | + Delete a snippet: | ||
| 252 | + | ||
| 253 | + .. literalinclude:: projects.py | ||
| 254 | + :start-after: # snippets delete | ||
| 255 | + :end-before: # end snippets delete | ||
| 256 | + | ||
| 209 | 257 | Events | |
| 210 | 258 | ------ | |
| 211 | 259 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments