| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4f30ec5 commit 9c02633
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,7 +66,8 @@ class Gitlab: | |||
| 66 | 66 | user_agent: A custom user agent to use for making HTTP requests. | |
| 67 | 67 | retry_transient_errors: Whether to retry after 500, 502, 503, 504 | |
| 68 | 68 | or 52x responses. Defaults to False. | |
| 69 | - persist_base_url: reconstruct next url if found not same as user provided url | ||
| 69 | + keep_base_url: keep user-provided base URL for pagination if it | ||
| 70 | + differs from response headers | ||
| 70 | 71 | """ | |
| 71 | 72 | ||
| 72 | 73 | def __init__( | |
@@ -86,7 +87,7 @@ def __init__( | |||
| 86 | 87 | order_by: Optional[str] = None, | |
| 87 | 88 | user_agent: str = gitlab.const.USER_AGENT, | |
| 88 | 89 | retry_transient_errors: bool = False, | |
| 89 | - persist_base_url: bool = False, | ||
| 90 | + keep_base_url: bool = False, | ||
| 90 | 91 | ) -> None: | |
| 91 | 92 | ||
| 92 | 93 | self._api_version = str(api_version) | |
@@ -97,7 +98,7 @@ def __init__( | |||
| 97 | 98 | #: Timeout to use for requests to gitlab server | |
| 98 | 99 | self.timeout = timeout | |
| 99 | 100 | self.retry_transient_errors = retry_transient_errors | |
| 100 | - self.persist_base_url = persist_base_url | ||
| 101 | + self.keep_base_url = keep_base_url | ||
| 101 | 102 | #: Headers that will be used in request to GitLab | |
| 102 | 103 | self.headers = {"User-Agent": user_agent} | |
| 103 | 104 | ||
@@ -1143,19 +1144,20 @@ def _query( | |||
| 1143 | 1144 | search_api_url = re.search(r"(^.*?/api)", next_url) | |
| 1144 | 1145 | if search_api_url: | |
| 1145 | 1146 | next_api_url = search_api_url.group(1) | |
| 1146 | - if self._gl.persist_base_url: | ||
| 1147 | + if self._gl.keep_base_url: | ||
| 1147 | 1148 | next_url = next_url.replace( | |
| 1148 | 1149 | next_api_url, f"{self._gl._base_url}/api" | |
| 1149 | 1150 | ) | |
| 1150 | 1151 | else: | |
| 1151 | 1152 | utils.warn( | |
| 1152 | 1153 | message=( | |
| 1153 | - f"The base url of the returned next page got " | ||
| 1154 | - f"different with the user provided " | ||
| 1155 | - f"{self._gl.url}/api* ~> {next_api_url}*, " | ||
| 1156 | - f"since this may can lead to unexpected behaviour. " | ||
| 1157 | - f"set argument persist_base_url to True for " | ||
| 1158 | - f"resonctruct it with the origin one." | ||
| 1154 | + f"The base URL in the server response" | ||
| 1155 | + f"differs from the user-provided base URL " | ||
| 1156 | + f"({self._gl.url}/api/ -> {next_api_url}/). " | ||
| 1157 | + f"This may lead to unexpected behavior and " | ||
| 1158 | + f"broken pagination. Use `keep_base_url=True` " | ||
| 1159 | + f"when initializing the Gitlab instance " | ||
| 1160 | + f"to follow the user-provided base URL." | ||
| 1159 | 1161 | ), | |
| 1160 | 1162 | category=UserWarning, | |
| 1161 | 1163 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -359,30 +359,28 @@ def test_gitlab_plain_const_does_not_warn(recwarn): | |||
| 359 | 359 | @pytest.mark.parametrize( | |
| 360 | 360 | "kwargs,link_header,expected_next_url,show_warning", | |
| 361 | 361 | [ | |
| 362 | - # normal execution | ||
| 363 | 362 | ( | |
| 364 | 363 | {}, | |
| 365 | 364 | "<http://localhost/api/v4/tests?per_page=1&page=2>;" ' rel="next"', | |
| 366 | 365 | "http://localhost/api/v4/tests?per_page=1&page=2", | |
| 367 | 366 | False, | |
| 368 | 367 | ), | |
| 369 | - # got different url and will show the warning | ||
| 370 | 368 | ( | |
| 371 | 369 | {}, | |
| 372 | 370 | "<http://orig_host/api/v4/tests?per_page=1&page=2>;" ' rel="next"', | |
| 373 | 371 | "http://orig_host/api/v4/tests?per_page=1&page=2", | |
| 374 | 372 | True, | |
| 375 | 373 | ), | |
| 376 | - # persist the base url | ||
| 377 | 374 | ( | |
| 378 | - {"persist_base_url": True}, | ||
| 375 | + {"keep_base_url": True}, | ||
| 379 | 376 | "<http://orig_host/api/v4/tests?per_page=1&page=2>;" ' rel="next"', | |
| 380 | 377 | "http://localhost/api/v4/tests?per_page=1&page=2", | |
| 381 | 378 | False, | |
| 382 | 379 | ), | |
| 383 | 380 | ], | |
| 381 | + ids=["url-match-does-not-warn", "url-mismatch-warns", "url-mismatch-keeps-url"], | ||
| 384 | 382 | ) | |
| 385 | - def test_gitlab_persist_base_url(kwargs, link_header, expected_next_url, show_warning): | ||
| 383 | + def test_gitlab_keep_base_url(kwargs, link_header, expected_next_url, show_warning): | ||
| 386 | 384 | responses.add( | |
| 387 | 385 | **{ | |
| 388 | 386 | "method": responses.GET, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments