Skip to content

Commit

Permalink
gitlab: Use all=True in most list() calls (#4491)
Browse files Browse the repository at this point in the history
If `all=True` is not set then by default only 20 records will be
returned when calling `list()`. Use `all=True` so that all records
will be returned.

For the `list()` use where do not desire to retrieve all entries then
use`all=False` to show explicityly that we don't want to get all of
the entries.

Fixes: #3729
Fixes: #4460
  • Loading branch information
JohnVillalovos committed Apr 13, 2022
1 parent e4a25be commit fe4bbc5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
23 changes: 23 additions & 0 deletions changelogs/fragments/4491-specify_all_in_list_calls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
bugfixes:
- >
gitlab_group_members - handle more than 20 groups when finding a group
(https://github.com/ansible-collections/community.general/pull/4491,
https://github.com/ansible-collections/community.general/issues/4460,
https://github.com/ansible-collections/community.general/issues/3729).
- >
gitlab_group - improve searching for projects inside group on deletion
(https://github.com/ansible-collections/community.general/pull/4491).
- >
gitlab_hook - handle more than 20 hooks when finding a hook
(https://github.com/ansible-collections/community.general/pull/4491).
- >
gitlab_project - handle more than 20 namespaces when finding a namespace
(https://github.com/ansible-collections/community.general/pull/4491).
- >
gitlab_project_members - handle more than 20 projects and users when
finding a project resp. user
(https://github.com/ansible-collections/community.general/pull/4491).
- >
gitlab_user - handle more than 20 users and SSH keys when finding a user
resp. SSH key
(https://github.com/ansible-collections/community.general/pull/4491).
2 changes: 1 addition & 1 deletion plugins/modules/source_control/gitlab/gitlab_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def update_group(self, group, arguments):
def delete_group(self):
group = self.group_object

if len(group.projects.list()) >= 1:
if len(group.projects.list(all=False)) >= 1:
self._module.fail_json(
msg="There are still projects in this group. These needs to be moved or deleted before this group can be removed.")
else:
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/source_control/gitlab/gitlab_group_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ def __init__(self, module, gl):

# get user id if the user exists
def get_user_id(self, gitlab_user):
user_exists = self._gitlab.users.list(username=gitlab_user)
user_exists = self._gitlab.users.list(username=gitlab_user, all=True)
if user_exists:
return user_exists[0].id

# get group id if group exists
def get_group_id(self, gitlab_group):
groups = self._gitlab.groups.list(search=gitlab_group)
groups = self._gitlab.groups.list(search=gitlab_group, all=True)
for group in groups:
if group.full_path == gitlab_group:
return group.id
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/source_control/gitlab/gitlab_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def update_hook(self, hook, arguments):
@param hook_url Url to call on event
'''
def find_hook(self, project, hook_url):
hooks = project.hooks.list()
hooks = project.hooks.list(all=True)
for hook in hooks:
if (hook.url == hook_url):
return hook
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/source_control/gitlab/gitlab_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ def main():
namespace_id = group.id
else:
if username:
namespace = gitlab_instance.namespaces.list(search=username)[0]
namespace = gitlab_instance.namespaces.list(search=username, all=False)[0]
else:
namespace = gitlab_instance.namespaces.list(search=gitlab_instance.user.username)[0]
namespace = gitlab_instance.namespaces.list(search=gitlab_instance.user.username, all=False)[0]
namespace_id = namespace.id

if not namespace_id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def get_project(self, project_name):
project_exists = self._gitlab.projects.get(project_name)
return project_exists.id
except gitlab.exceptions.GitlabGetError as e:
project_exists = self._gitlab.projects.list(search=project_name)
project_exists = self._gitlab.projects.list(search=project_name, all=False)
if project_exists:
return project_exists[0].id

def get_user_id(self, gitlab_user):
user_exists = self._gitlab.users.list(username=gitlab_user)
user_exists = self._gitlab.users.list(username=gitlab_user, all=False)
if user_exists:
return user_exists[0].id

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/source_control/gitlab/gitlab_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def get_user_id(self, user):
@param sshkey_name Name of the ssh key
'''
def ssh_key_exists(self, user, sshkey_name):
keyList = map(lambda k: k.title, user.keys.list())
keyList = map(lambda k: k.title, user.keys.list(all=True))

return sshkey_name in keyList

Expand Down Expand Up @@ -519,7 +519,7 @@ def delete_identities(self, user, identities):
@param username Username of the user
'''
def find_user(self, username):
users = self._gitlab.users.list(search=username)
users = self._gitlab.users.list(search=username, all=True)
for user in users:
if (user.username == username):
return user
Expand Down

0 comments on commit fe4bbc5

Please sign in to comment.