| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -219,6 +219,18 @@ You can define the ``per_page`` value globally to avoid passing it to every | |||
| 219 | 219 | ||
| 220 | 220 | gl = gitlab.Gitlab(url, token, per_page=50) | |
| 221 | 221 | ||
| 222 | + Gitlab allows to also use keyset pagination. You can supply it to your project listing, | ||
| 223 | + but you can also do so globally. Be aware that GitLab then also requires you to only use supported | ||
| 224 | + order options. At the time of writing, only ``order_by="id"`` works. | ||
| 225 | + | ||
| 226 | + .. code-block:: python | ||
| 227 | + | ||
| 228 | + gl = gitlab.Gitlab(url, token, pagination="keyset", order_by="id", per_page=100) | ||
| 229 | + gl.projects.list() | ||
| 230 | + | ||
| 231 | + Reference: | ||
| 232 | + https://docs.gitlab.com/ce/api/README.html#keyset-based-pagination | ||
| 233 | + | ||
| 222 | 234 | ``list()`` methods can also return a generator object which will handle the | |
| 223 | 235 | next calls to the API when required. This is the recommended way to iterate | |
| 224 | 236 | through a large number of items: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,8 @@ class Gitlab(object): | |||
| 69 | 69 | http_username (str): Username for HTTP authentication | |
| 70 | 70 | http_password (str): Password for HTTP authentication | |
| 71 | 71 | api_version (str): Gitlab API version to use (support for 4 only) | |
| 72 | + pagination (str): Can be set to 'keyset' to use keyset pagination | ||
| 73 | + order_by (str): Set order_by globally | ||
| 72 | 74 | """ | |
| 73 | 75 | ||
| 74 | 76 | def __init__( | |
@@ -84,6 +86,8 @@ def __init__( | |||
| 84 | 86 | api_version="4", | |
| 85 | 87 | session=None, | |
| 86 | 88 | per_page=None, | |
| 89 | + pagination=None, | ||
| 90 | + order_by=None, | ||
| 87 | 91 | ): | |
| 88 | 92 | ||
| 89 | 93 | self._api_version = str(api_version) | |
@@ -109,6 +113,8 @@ def __init__( | |||
| 109 | 113 | self.session = session or requests.Session() | |
| 110 | 114 | ||
| 111 | 115 | self.per_page = per_page | |
| 116 | + self.pagination = pagination | ||
| 117 | + self.order_by = order_by | ||
| 112 | 118 | ||
| 113 | 119 | objects = importlib.import_module("gitlab.v%s.objects" % self._api_version) | |
| 114 | 120 | self._objects = objects | |
@@ -200,6 +206,8 @@ def from_config(cls, gitlab_id=None, config_files=None): | |||
| 200 | 206 | http_password=config.http_password, | |
| 201 | 207 | api_version=config.api_version, | |
| 202 | 208 | per_page=config.per_page, | |
| 209 | + pagination=config.pagination, | ||
| 210 | + order_by=config.order_by, | ||
| 203 | 211 | ) | |
| 204 | 212 | ||
| 205 | 213 | def auth(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,3 +163,15 @@ def __init__(self, gitlab_id=None, config_files=None): | |||
| 163 | 163 | pass | |
| 164 | 164 | if self.per_page is not None and not 0 <= self.per_page <= 100: | |
| 165 | 165 | raise GitlabDataError("Unsupported per_page number: %s" % self.per_page) | |
| 166 | + | ||
| 167 | + self.pagination = None | ||
| 168 | + try: | ||
| 169 | + self.pagination = self._config.get(self.gitlab_id, "pagination") | ||
| 170 | + except Exception: | ||
| 171 | + pass | ||
| 172 | + | ||
| 173 | + self.order_by = None | ||
| 174 | + try: | ||
| 175 | + self.order_by = self._config.get(self.gitlab_id, "order_by") | ||
| 176 | + except Exception: | ||
| 177 | + pass | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,6 +120,13 @@ def list(self, **kwargs): | |||
| 120 | 120 | if self.gitlab.per_page: | |
| 121 | 121 | data.setdefault("per_page", self.gitlab.per_page) | |
| 122 | 122 | ||
| 123 | + # global keyset pagination | ||
| 124 | + if self.gitlab.pagination: | ||
| 125 | + data.setdefault("pagination", self.gitlab.pagination) | ||
| 126 | + | ||
| 127 | + if self.gitlab.order_by: | ||
| 128 | + data.setdefault("order_by", self.gitlab.order_by) | ||
| 129 | + | ||
| 123 | 130 | # We get the attributes that need some special transformation | |
| 124 | 131 | types = getattr(self, "_types", {}) | |
| 125 | 132 | if types: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -268,6 +268,13 @@ class UserProjectManager(ListMixin, CreateMixin, RESTManager): | |||
| 268 | 268 | "statistics", | |
| 269 | 269 | "with_issues_enabled", | |
| 270 | 270 | "with_merge_requests_enabled", | |
| 271 | + "with_custom_attributes", | ||
| 272 | + "with_programming_language", | ||
| 273 | + "wiki_checksum_failed", | ||
| 274 | + "repository_checksum_failed", | ||
| 275 | + "min_access_level", | ||
| 276 | + "id_after", | ||
| 277 | + "id_before", | ||
| 271 | 278 | ) | |
| 272 | 279 | ||
| 273 | 280 | def list(self, **kwargs): | |
@@ -1192,12 +1199,16 @@ class GroupProjectManager(ListMixin, RESTManager): | |||
| 1192 | 1199 | "order_by", | |
| 1193 | 1200 | "sort", | |
| 1194 | 1201 | "search", | |
| 1195 | - "ci_enabled_first", | ||
| 1196 | 1202 | "simple", | |
| 1197 | 1203 | "owned", | |
| 1198 | 1204 | "starred", | |
| 1199 | 1205 | "with_custom_attributes", | |
| 1200 | 1206 | "include_subgroups", | |
| 1207 | + "with_issues_enabled", | ||
| 1208 | + "with_merge_requests_enabled", | ||
| 1209 | + "with_shared", | ||
| 1210 | + "min_access_level", | ||
| 1211 | + "with_security_reports", | ||
| 1201 | 1212 | ) | |
| 1202 | 1213 | ||
| 1203 | 1214 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments