| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f13968b commit 64ae61e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,16 @@ List snippets owned by the current user:: | |||
| 22 | 22 | ||
| 23 | 23 | List the public snippets:: | |
| 24 | 24 | ||
| 25 | - public_snippets = gl.snippets.public() | ||
| 25 | + public_snippets = gl.snippets.list_public() | ||
| 26 | + | ||
| 27 | + List all snippets:: | ||
| 28 | + | ||
| 29 | + all_snippets = gl.snippets.list_all() | ||
| 30 | + | ||
| 31 | + .. warning:: | ||
| 32 | + | ||
| 33 | + Only users with the Administrator or Auditor access levels can see all snippets | ||
| 34 | + (both personal and project). See the upstream API documentation for more details. | ||
| 26 | 35 | ||
| 27 | 36 | Get a snippet:: | |
| 28 | 37 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,11 +90,35 @@ class SnippetManager(CRUDMixin, RESTManager): | |||
| 90 | 90 | ) | |
| 91 | 91 | ||
| 92 | 92 | @cli.register_custom_action(cls_names="SnippetManager") | |
| 93 | - def public(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]: | ||
| 94 | - """List all the public snippets. | ||
| 93 | + def list_public(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]: | ||
| 94 | + """List all public snippets. | ||
| 95 | + | ||
| 96 | + Args: | ||
| 97 | + get_all: If True, return all the items, without pagination | ||
| 98 | + per_page: Number of items to retrieve per request | ||
| 99 | + page: ID of the page to return (starts with page 1) | ||
| 100 | + iterator: If set to True and no pagination option is | ||
| 101 | + defined, return a generator instead of a list | ||
| 102 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 103 | + | ||
| 104 | + Raises: | ||
| 105 | + GitlabListError: If the list could not be retrieved | ||
| 106 | + | ||
| 107 | + Returns: | ||
| 108 | + The list of snippets, or a generator if `iterator` is True | ||
| 109 | + """ | ||
| 110 | + return self.list(path="/snippets/public", **kwargs) | ||
| 111 | + | ||
| 112 | + @cli.register_custom_action(cls_names="SnippetManager") | ||
| 113 | + def list_all(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]: | ||
| 114 | + """List all snippets. | ||
| 95 | 115 | ||
| 96 | 116 | Args: | |
| 97 | - all: If True the returned object will be a list | ||
| 117 | + get_all: If True, return all the items, without pagination | ||
| 118 | + per_page: Number of items to retrieve per request | ||
| 119 | + page: ID of the page to return (starts with page 1) | ||
| 120 | + iterator: If set to True and no pagination option is | ||
| 121 | + defined, return a generator instead of a list | ||
| 98 | 122 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 99 | 123 | ||
| 100 | 124 | Raises: | |
@@ -103,6 +127,32 @@ def public(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]: | |||
| 103 | 127 | Returns: | |
| 104 | 128 | A generator for the snippets list | |
| 105 | 129 | """ | |
| 130 | + return self.list(path="/snippets/all", **kwargs) | ||
| 131 | + | ||
| 132 | + def public(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]: | ||
| 133 | + """List all public snippets. | ||
| 134 | + | ||
| 135 | + Args: | ||
| 136 | + get_all: If True, return all the items, without pagination | ||
| 137 | + per_page: Number of items to retrieve per request | ||
| 138 | + page: ID of the page to return (starts with page 1) | ||
| 139 | + iterator: If set to True and no pagination option is | ||
| 140 | + defined, return a generator instead of a list | ||
| 141 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 142 | + | ||
| 143 | + Raises: | ||
| 144 | + GitlabListError: If the list could not be retrieved | ||
| 145 | + | ||
| 146 | + Returns: | ||
| 147 | + The list of snippets, or a generator if `iterator` is True | ||
| 148 | + """ | ||
| 149 | + utils.warn( | ||
| 150 | + message=( | ||
| 151 | + "Gitlab.snippets.public() is deprecated and will be removed in a" | ||
| 152 | + "future major version. Use Gitlab.snippets.list_public() instead." | ||
| 153 | + ), | ||
| 154 | + category=DeprecationWarning, | ||
| 155 | + ) | ||
| 106 | 156 | return self.list(path="/snippets/public", **kwargs) | |
| 107 | 157 | ||
| 108 | 158 | def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Snippet: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,13 @@ def test_snippets(gl): | |||
| 23 | 23 | content = snippet.content() | |
| 24 | 24 | assert content.decode() == "import gitlab" | |
| 25 | 25 | ||
| 26 | + all_snippets = gl.snippets.list_all(get_all=True) | ||
| 27 | + public_snippets = gl.snippets.public(get_all=True) | ||
| 28 | + list_public_snippets = gl.snippets.list_public(get_all=True) | ||
| 29 | + assert isinstance(all_snippets, list) | ||
| 30 | + assert isinstance(list_public_snippets, list) | ||
| 31 | + assert public_snippets == list_public_snippets | ||
| 32 | + | ||
| 26 | 33 | snippet.delete() | |
| 27 | 34 | ||
| 28 | 35 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments