| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bded2de commit 0b71ba4
4 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", per_page=100) | ||
| 229 | + gl.projects.list(order_by="id") | ||
| 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,7 @@ 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 | ||
| 72 | 73 | """ | |
| 73 | 74 | ||
| 74 | 75 | def __init__( | |
@@ -84,6 +85,7 @@ def __init__( | |||
| 84 | 85 | api_version="4", | |
| 85 | 86 | session=None, | |
| 86 | 87 | per_page=None, | |
| 88 | + pagination=None, | ||
| 87 | 89 | ): | |
| 88 | 90 | ||
| 89 | 91 | self._api_version = str(api_version) | |
@@ -109,6 +111,7 @@ def __init__( | |||
| 109 | 111 | self.session = session or requests.Session() | |
| 110 | 112 | ||
| 111 | 113 | self.per_page = per_page | |
| 114 | + self.pagination = pagination | ||
| 112 | 115 | ||
| 113 | 116 | objects = importlib.import_module("gitlab.v%s.objects" % self._api_version) | |
| 114 | 117 | self._objects = objects | |
@@ -200,6 +203,7 @@ def from_config(cls, gitlab_id=None, config_files=None): | |||
| 200 | 203 | http_password=config.http_password, | |
| 201 | 204 | api_version=config.api_version, | |
| 202 | 205 | per_page=config.per_page, | |
| 206 | + pagination=config.pagination, | ||
| 203 | 207 | ) | |
| 204 | 208 | ||
| 205 | 209 | def auth(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,3 +163,9 @@ 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,6 +120,10 @@ 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 | + | ||
| 123 | 127 | # We get the attributes that need some special transformation | |
| 124 | 128 | types = getattr(self, "_types", {}) | |
| 125 | 129 | if types: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments