|
18 | 18 |
|
19 | 19 | import os |
20 | 20 | import time |
| 21 | +import warnings |
21 | 22 | from typing import Any, cast, Dict, List, Optional, Tuple, TYPE_CHECKING, Union |
22 | 23 |
|
23 | 24 | import requests |
24 | 25 | import requests.utils |
25 | 26 | from requests_toolbelt.multipart.encoder import MultipartEncoder # type: ignore |
26 | 27 |
|
| 28 | +import gitlab |
27 | 29 | import gitlab.config |
28 | 30 | import gitlab.const |
29 | 31 | import gitlab.exceptions |
|
35 | 37 | "{source!r} to {target!r}" |
36 | 38 | ) |
37 | 39 |
|
| 40 | +# https://docs.gitlab.com/ee/api/#offset-based-pagination |
| 41 | +_PAGINATION_URL = ( |
| 42 | + f"https://python-gitlab.readthedocs.io/en/v{gitlab.__version__}/" |
| 43 | + f"api-usage.html#pagination" |
| 44 | +) |
| 45 | + |
38 | 46 |
|
39 | 47 | class Gitlab: |
40 | 48 | """Represents a GitLab server connection. |
@@ -818,7 +826,26 @@ def http_list( |
818 | 826 |
|
819 | 827 | if page or as_list is True: |
820 | 828 | # pagination requested, we return a list |
821 | | - return list(GitlabList(self, url, query_data, get_next=False, **kwargs)) |
| 829 | + gl_list = GitlabList(self, url, query_data, get_next=False, **kwargs) |
| 830 | + items = list(gl_list) |
| 831 | + if ( |
| 832 | + page is None |
| 833 | + and len(items) >= gl_list.per_page |
| 834 | + and (gl_list.total is None or len(items) < gl_list.total) |
| 835 | + ): |
| 836 | + total_items = "10,000+" if gl_list.total is None else gl_list.total |
| 837 | + # Warn the user that they are only going to retrieve `per_page` maximum |
| 838 | + # items. This is a common cause of issues filed. |
| 839 | + warnings.warn( |
| 840 | + ( |
| 841 | + f"Calling a `list()` method without specifying `all=True` or " |
| 842 | + f"`as_list=False` will return a maximum of {gl_list.per_page} " |
| 843 | + f"items. Your query returned {len(items)} of {total_items} " |
| 844 | + f"items. See {_PAGINATION_URL} for more details" |
| 845 | + ), |
| 846 | + UserWarning, |
| 847 | + ) |
| 848 | + return items |
822 | 849 |
|
823 | 850 | # No pagination, generator requested |
824 | 851 | return GitlabList(self, url, query_data, **kwargs) |
|
0 commit comments