rriverak / vscode-gitlab-explorer

VSCode extension for working with GitLab Project Items, supporting both GitLab.com and custom GitLab Servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gitlab-explorer won't find some groups if you have a large number of groups that you have access to

tneksenoj opened this issue · comments

Describe the bug
We have a gitlab repository with hundreds of groups. Because the gitlab API paginates response the current function "async GetGroupsAsync():Promise<Array>{" won't find some of the groups because it only searches the first few groups returned by the API

To Reproduce
Steps to reproduce the behavior:

  1. Setup your own gilab server.
  2. Create 200+ groups but only give yourself two or 3 parentless groups. The other groups should be subgroups.
  3. Give yourself access two or three of the groups one at the beginning and one at the end.

Expected behavior
Try use git-lab explorer in vscode to find your groups. You will only find the first group.

Desktop (please complete the following information):

  • OS: [e.g.Win
  • VSCode Version [e.g. 1.37.1]
  • GitLab-ce

Additional context
Here is the code that I used to fix this problem.

async GetGroupsAsync():Promise<Array<Group>>{
    let groups:Array<Group> = [];
    let next_groups:Array<Group> = [];
    let p = 1;
    
    try {
        // Need to allow for a large number of groups on the gitlab server. 
        // this searches through the groups page by page and finds those without parents
        let response = await this.httpClient.get('/groups?per_page=20&page='+ p.toString() ); 
        while ( response.data && response.data.length > 0  ) {
                            
            next_groups = response.data.map((group:any)=>{
                return new Group(group);
            }) as Array<Group>;
            next_groups = next_groups.filter((g)=>{return g.GetParentID() === null;}); //Only Root Groups
            groups = groups.concat(next_groups);

            p = p + 1;
            response = await this.httpClient.get('/groups?per_page=20&page='+ p.toString() );
        }   
    } catch (error) {
        this.HandleError(error);
    }
    return groups;            
}