summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/api-usage.rst4
-rw-r--r--gitlab/__init__.py4
-rw-r--r--gitlab/config.py6
-rw-r--r--gitlab/mixins.py3
4 files changed, 15 insertions, 2 deletions
diff --git a/docs/api-usage.rst b/docs/api-usage.rst
index 5b1bd93..19fdea0 100644
--- a/docs/api-usage.rst
+++ b/docs/api-usage.rst
@@ -225,8 +225,8 @@ order options. At the time of writing, only ``order_by="id"`` works.
.. code-block:: python
- gl = gitlab.Gitlab(url, token, pagination="keyset", per_page=100)
- gl.projects.list(order_by="id")
+ gl = gitlab.Gitlab(url, token, pagination="keyset", order_by="id", per_page=100)
+ gl.projects.list()
Reference:
https://docs.gitlab.com/ce/api/README.html#keyset-based-pagination
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 166e00f..85fc5e0 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -70,6 +70,7 @@ class Gitlab(object):
http_password (str): Password for HTTP authentication
api_version (str): Gitlab API version to use (support for 4 only)
pagination (str): Can be set to 'keyset' to use keyset pagination
+ order_by (str): Set order_by globally
"""
def __init__(
@@ -86,6 +87,7 @@ class Gitlab(object):
session=None,
per_page=None,
pagination=None,
+ order_by=None,
):
self._api_version = str(api_version)
@@ -112,6 +114,7 @@ class Gitlab(object):
self.per_page = per_page
self.pagination = pagination
+ self.order_by = order_by
objects = importlib.import_module("gitlab.v%s.objects" % self._api_version)
self._objects = objects
@@ -204,6 +207,7 @@ class Gitlab(object):
api_version=config.api_version,
per_page=config.per_page,
pagination=config.pagination,
+ order_by=config.order_by,
)
def auth(self):
diff --git a/gitlab/config.py b/gitlab/config.py
index 95a1245..2272dd3 100644
--- a/gitlab/config.py
+++ b/gitlab/config.py
@@ -169,3 +169,9 @@ class GitlabConfigParser(object):
self.pagination = self._config.get(self.gitlab_id, "pagination")
except Exception:
pass
+
+ self.order_by = None
+ try:
+ self.order_by = self._config.get(self.gitlab_id, "order_by")
+ except Exception:
+ pass
diff --git a/gitlab/mixins.py b/gitlab/mixins.py
index 2437a6f..8544499 100644
--- a/gitlab/mixins.py
+++ b/gitlab/mixins.py
@@ -124,6 +124,9 @@ class ListMixin(object):
if self.gitlab.pagination:
data.setdefault("pagination", self.gitlab.pagination)
+ if self.gitlab.order_by:
+ data.setdefault("order_by", self.gitlab.order_by)
+
# We get the attributes that need some special transformation
types = getattr(self, "_types", {})
if types: