| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b4951cd commit 31c3c5e
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -566,8 +566,10 @@ Get the content of a snippet:: | |||
| 566 | 566 | Create a snippet:: | |
| 567 | 567 | ||
| 568 | 568 | snippet = project.snippets.create({'title': 'sample 1', | |
| 569 | - 'file_name': 'foo.py', | ||
| 570 | - 'code': 'import gitlab', | ||
| 569 | + 'files': [{ | ||
| 570 | + 'file_path': 'foo.py', | ||
| 571 | + 'content': 'import gitlab' | ||
| 572 | + }], | ||
| 571 | 573 | 'visibility_level': | |
| 572 | 574 | gitlab.const.Visibility.PRIVATE}) | |
| 573 | 575 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,8 +39,11 @@ Get a snippet:: | |||
| 39 | 39 | Create a snippet:: | |
| 40 | 40 | ||
| 41 | 41 | snippet = gl.snippets.create({'title': 'snippet1', | |
| 42 | - 'file_name': 'snippet1.py', | ||
| 43 | - 'content': open('snippet1.py').read()}) | ||
| 42 | + 'files': [{ | ||
| 43 | + 'file_path': 'foo.py', | ||
| 44 | + 'content': 'import gitlab' | ||
| 45 | + }], | ||
| 46 | + }) | ||
| 44 | 47 | ||
| 45 | 48 | Update the snippet attributes:: | |
| 46 | 49 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,10 +70,23 @@ class SnippetManager(CRUDMixin, RESTManager): | |||
| 70 | 70 | _path = "/snippets" | |
| 71 | 71 | _obj_cls = Snippet | |
| 72 | 72 | _create_attrs = RequiredOptional( | |
| 73 | - required=("title", "file_name", "content"), optional=("lifetime", "visibility") | ||
| 73 | + required=("title",), | ||
| 74 | + exclusive=("files", "file_name"), | ||
| 75 | + optional=( | ||
| 76 | + "description", | ||
| 77 | + "content", | ||
| 78 | + "visibility", | ||
| 79 | + ), | ||
| 74 | 80 | ) | |
| 75 | 81 | _update_attrs = RequiredOptional( | |
| 76 | - optional=("title", "file_name", "content", "visibility") | ||
| 82 | + optional=( | ||
| 83 | + "title", | ||
| 84 | + "files", | ||
| 85 | + "file_name", | ||
| 86 | + "content", | ||
| 87 | + "visibility", | ||
| 88 | + "description", | ||
| 89 | + ), | ||
| 77 | 90 | ) | |
| 78 | 91 | ||
| 79 | 92 | @cli.register_custom_action("SnippetManager") | |
@@ -151,11 +164,22 @@ class ProjectSnippetManager(CRUDMixin, RESTManager): | |||
| 151 | 164 | _obj_cls = ProjectSnippet | |
| 152 | 165 | _from_parent_attrs = {"project_id": "id"} | |
| 153 | 166 | _create_attrs = RequiredOptional( | |
| 154 | - required=("title", "file_name", "content", "visibility"), | ||
| 155 | - optional=("description",), | ||
| 167 | + required=("title", "visibility"), | ||
| 168 | + exclusive=("files", "file_name"), | ||
| 169 | + optional=( | ||
| 170 | + "description", | ||
| 171 | + "content", | ||
| 172 | + ), | ||
| 156 | 173 | ) | |
| 157 | 174 | _update_attrs = RequiredOptional( | |
| 158 | - optional=("title", "file_name", "content", "visibility", "description"), | ||
| 175 | + optional=( | ||
| 176 | + "title", | ||
| 177 | + "files", | ||
| 178 | + "file_name", | ||
| 179 | + "content", | ||
| 180 | + "visibility", | ||
| 181 | + "description", | ||
| 182 | + ), | ||
| 159 | 183 | ) | |
| 160 | 184 | ||
| 161 | 185 | def get( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,10 @@ def test_snippets(gl): | |||
| 6 | 6 | assert not snippets | |
| 7 | 7 | ||
| 8 | 8 | snippet = gl.snippets.create( | |
| 9 | - {"title": "snippet1", "file_name": "snippet1.py", "content": "import gitlab"} | ||
| 9 | + { | ||
| 10 | + "title": "snippet1", | ||
| 11 | + "files": [{"file_path": "snippet1.py", "content": "import gitlab"}], | ||
| 12 | + } | ||
| 10 | 13 | ) | |
| 11 | 14 | snippet = gl.snippets.get(snippet.id) | |
| 12 | 15 | snippet.title = "updated_title" | |
@@ -30,8 +33,7 @@ def test_project_snippets(project): | |||
| 30 | 33 | snippet = project.snippets.create( | |
| 31 | 34 | { | |
| 32 | 35 | "title": "snip1", | |
| 33 | - "file_name": "foo.py", | ||
| 34 | - "content": "initial content", | ||
| 36 | + "files": [{"file_path": "foo.py", "content": "initial content"}], | ||
| 35 | 37 | "visibility": gitlab.const.VISIBILITY_PRIVATE, | |
| 36 | 38 | } | |
| 37 | 39 | ) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments