| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,11 +112,12 @@ You can use pagination to go throught long lists: | |||
| 112 | 112 | ||
| 113 | 113 | ten_first_groups = gl.groups.list(page=0, per_page=10) | |
| 114 | 114 | ||
| 115 | - Use the ``all`` parameter to get all the items: | ||
| 115 | + Use the ``all`` parameter to get all the items when using listing methods: | ||
| 116 | 116 | ||
| 117 | 117 | .. code-block:: python | |
| 118 | 118 | ||
| 119 | 119 | all_groups = gl.groups.list(all=True) | |
| 120 | + all_owned_projects = gl.projects.owned(all=True) | ||
| 120 | 121 | ||
| 121 | 122 | Sudo | |
| 122 | 123 | ==== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -269,6 +269,31 @@ def _raw_get(self, path, content_type=None, **kwargs): | |||
| 269 | 269 | raise GitlabConnectionError( | |
| 270 | 270 | "Can't connect to GitLab server (%s)" % e) | |
| 271 | 271 | ||
| 272 | + def _raw_list(self, path, cls, **kwargs): | ||
| 273 | + r = self._raw_get(path, **kwargs) | ||
| 274 | + raise_error_from_response(r, GitlabListError) | ||
| 275 | + | ||
| 276 | + cls_kwargs = kwargs.copy() | ||
| 277 | + | ||
| 278 | + # Add _from_api manually, because we are not creating objects | ||
| 279 | + # through normal path | ||
| 280 | + cls_kwargs['_from_api'] = True | ||
| 281 | + get_all_results = kwargs.get('all', False) | ||
| 282 | + | ||
| 283 | + # Remove parameters from kwargs before passing it to constructor | ||
| 284 | + for key in ['all', 'page', 'per_page', 'sudo']: | ||
| 285 | + if key in cls_kwargs: | ||
| 286 | + del cls_kwargs[key] | ||
| 287 | + | ||
| 288 | + results = [cls(self, item, **cls_kwargs) for item in r.json() | ||
| 289 | + if item is not None] | ||
| 290 | + if ('next' in r.links and 'url' in r.links['next'] | ||
| 291 | + and get_all_results is True): | ||
| 292 | + args = kwargs.copy() | ||
| 293 | + args['next_url'] = r.links['next']['url'] | ||
| 294 | + results.extend(self.list(cls, **args)) | ||
| 295 | + return results | ||
| 296 | + | ||
| 272 | 297 | def _raw_post(self, path, data=None, content_type=None, **kwargs): | |
| 273 | 298 | url = '%s%s' % (self._url, path) | |
| 274 | 299 | headers = self._create_headers(content_type) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -155,18 +155,6 @@ def delete(self, id, **kwargs): | |||
| 155 | 155 | raise NotImplementedError | |
| 156 | 156 | self.gitlab.delete(self.obj_cls, id, **args) | |
| 157 | 157 | ||
| 158 | - def _custom_list(self, url, cls, **kwargs): | ||
| 159 | - r = self.gitlab._raw_get(url, **kwargs) | ||
| 160 | - raise_error_from_response(r, GitlabListError) | ||
| 161 | - | ||
| 162 | - l = [] | ||
| 163 | - for j in r.json(): | ||
| 164 | - o = cls(self.gitlab, j) | ||
| 165 | - o._from_api = True | ||
| 166 | - l.append(o) | ||
| 167 | - | ||
| 168 | - return l | ||
| 169 | - | ||
| 170 | 158 | ||
| 171 | 159 | class GitlabObject(object): | |
| 172 | 160 | """Base class for all classes that interface with GitLab.""" | |
@@ -569,6 +557,7 @@ def search(self, query, **kwargs): | |||
| 569 | 557 | ||
| 570 | 558 | Args: | |
| 571 | 559 | query (str): The query string to send to GitLab for the search. | |
| 560 | + all (bool): If True, return all the items, without pagination | ||
| 572 | 561 | **kwargs: Additional arguments to send to GitLab. | |
| 573 | 562 | ||
| 574 | 563 | Returns: | |
@@ -579,7 +568,7 @@ def search(self, query, **kwargs): | |||
| 579 | 568 | GitlabListError: If the server fails to perform the request. | |
| 580 | 569 | """ | |
| 581 | 570 | url = self.obj_cls._url + '?search=' + query | |
| 582 | - return self._custom_list(url, self.obj_cls, **kwargs) | ||
| 571 | + return self.gitlab._raw_list(url, self.obj_cls, **kwargs) | ||
| 583 | 572 | ||
| 584 | 573 | def get_by_username(self, username, **kwargs): | |
| 585 | 574 | """Get a user by its username. | |
@@ -596,7 +585,7 @@ def get_by_username(self, username, **kwargs): | |||
| 596 | 585 | GitlabGetError: If the server fails to perform the request. | |
| 597 | 586 | """ | |
| 598 | 587 | url = self.obj_cls._url + '?username=' + username | |
| 599 | - results = self._custom_list(url, self.obj_cls, **kwargs) | ||
| 588 | + results = self.gitlab._raw_list(url, self.obj_cls, **kwargs) | ||
| 600 | 589 | assert len(results) in (0, 1) | |
| 601 | 590 | try: | |
| 602 | 591 | return results[0] | |
@@ -712,10 +701,15 @@ class GroupManager(BaseManager): | |||
| 712 | 701 | def search(self, query, **kwargs): | |
| 713 | 702 | """Searches groups by name. | |
| 714 | 703 | ||
| 715 | - Returns a list of matching groups. | ||
| 704 | + Args: | ||
| 705 | + query (str): The search string | ||
| 706 | + all (bool): If True, return all the items, without pagination | ||
| 707 | + | ||
| 708 | + Returns: | ||
| 709 | + list(Group): a list of matching groups. | ||
| 716 | 710 | """ | |
| 717 | 711 | url = '/groups?search=' + query | |
| 718 | - return self._custom_list(url, Group, **kwargs) | ||
| 712 | + return self.gitlab._raw_list(url, self.obj_cls, **kwargs) | ||
| 719 | 713 | ||
| 720 | 714 | ||
| 721 | 715 | class Hook(GitlabObject): | |
@@ -1524,35 +1518,38 @@ def search(self, query, **kwargs): | |||
| 1524 | 1518 | ||
| 1525 | 1519 | Args: | |
| 1526 | 1520 | query (str): The query string to send to GitLab for the search. | |
| 1521 | + all (bool): If True, return all the items, without pagination | ||
| 1527 | 1522 | **kwargs: Additional arguments to send to GitLab. | |
| 1528 | 1523 | ||
| 1529 | 1524 | Returns: | |
| 1530 | 1525 | list(Project): A list of matching projects. | |
| 1531 | 1526 | """ | |
| 1532 | - return self._custom_list("/projects/search/" + query, Project, | ||
| 1533 | - **kwargs) | ||
| 1527 | + return self.gitlab._raw_list("/projects/search/" + query, Project, | ||
| 1528 | + **kwargs) | ||
| 1534 | 1529 | ||
| 1535 | 1530 | def all(self, **kwargs): | |
| 1536 | 1531 | """List all the projects (need admin rights). | |
| 1537 | 1532 | ||
| 1538 | 1533 | Args: | |
| 1534 | + all (bool): If True, return all the items, without pagination | ||
| 1539 | 1535 | **kwargs: Additional arguments to send to GitLab. | |
| 1540 | 1536 | ||
| 1541 | 1537 | Returns: | |
| 1542 | 1538 | list(Project): The list of projects. | |
| 1543 | 1539 | """ | |
| 1544 | - return self._custom_list("/projects/all", Project, **kwargs) | ||
| 1540 | + return self.gitlab._raw_list("/projects/all", Project, **kwargs) | ||
| 1545 | 1541 | ||
| 1546 | 1542 | def owned(self, **kwargs): | |
| 1547 | 1543 | """List owned projects. | |
| 1548 | 1544 | ||
| 1549 | 1545 | Args: | |
| 1546 | + all (bool): If True, return all the items, without pagination | ||
| 1550 | 1547 | **kwargs: Additional arguments to send to GitLab. | |
| 1551 | 1548 | ||
| 1552 | 1549 | Returns: | |
| 1553 | 1550 | list(Project): The list of owned projects. | |
| 1554 | 1551 | """ | |
| 1555 | - return self._custom_list("/projects/owned", Project, **kwargs) | ||
| 1552 | + return self.gitlab._raw_list("/projects/owned", Project, **kwargs) | ||
| 1556 | 1553 | ||
| 1557 | 1554 | ||
| 1558 | 1555 | class UserProjectManager(BaseManager): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments