Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Query for all/owned projects/groups results in 404 #206

Open
rmoreas opened this issue Feb 20, 2019 · 0 comments
Open

Query for all/owned projects/groups results in 404 #206

rmoreas opened this issue Feb 20, 2019 · 0 comments

Comments

@rmoreas
Copy link

rmoreas commented Feb 20, 2019

1. Provide a general summary of the issue in the Title above

Get-GitlabGroup and Get-GitlabProject results in an exception when using -All or -Owned parameters and no groups/projects are returned.

2. Describe Your Environment

  • Windows 10 build 1803
  • PSVersion 5.1.17134.590
  • Gitlab Community 11.7.5

3. Expected Behavior

When using switch parameters -All or -Owned, we should get a list of all or owned projects/groups.

4.Current Behavior

Example query reproducing the error:

Get-GitLabProject -Owned -Verbose
VERBOSE: Create GET Request
VERBOSE: Parameter Set Name: Owned
VERBOSE: URL: https://gitlab.mydomain.com/api/v4/projects/owned?archived=false&order_by=created_at&sort=desc&per_page=100
VERBOSE: GET
https://gitlab.mydomain.com/api/v4/projects/owned?archived=false&order_by=created_at&sort=desc&per_page=100 with
0-byte payload
QueryGitLabAPI :  -
At C:\Users\XXXXX\Documents\WindowsPowerShell\Modules\PSGitLab\3.0.1\PSGitLab.psm1:1307 char:5
+     QueryGitLabAPI -Request $Request -ObjectType 'GitLab.Project'
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,QueryGitLabAPI

When using the above called url (https://gitlab.mydomain.com/api/v4/projects/owned?archived=false&order_by=created_at&sort=desc&per_page=100) in a browser, it results in:

{"message":"404 Project Not Found"}

It looks to me that the constructed request url's are incorrect. In the current implementation the keyword owned and all (and starredfor projects) are appended to the url path for projects/groups when using while it should be a boolean attribute. Example:

https://gitlab.mydomain.com/api/v4/projects/owned

Should be:

https://gitlab.mydomain.com/api/v4/projects/?owned=true

See also API docs: https://docs.gitlab.com/ee/api/projects.html#list-all-projects.

The same applies to groups.

5. Possible Solution

When using the All, Starred or Owned parameter set in Get-GitlabProject and Get-GitlabGroup, the key/value @{all=$true}, @{starred=$true} or @{owned=$true} should be added respectively to the $GetUrlParameters hashtable instead of appending the keyword to the uri path.

Possible solution is to change the switch statement for the parameter set in Get-GitlabProject and Get-GitlabGroup. For projects it could be:

    switch ($PSCmdlet.ParameterSetName) {
        Projects { $Request.URI = "/projects$URLParameters"; break; }
        PerGroup { $Request.URI = "/groups/$GroupId/projects$URLParameters"; break; }
        Owned {
            $GetUrlParameters += @{owned=$true}
            $URLParameters = GetMethodParameters -GetURLParameters $GetUrlParameters
            $Request.URI = "/projects/$URLParameters"; break;
        }
        All {
            $GetUrlParameters += @{all=$true}
            $URLParameters = GetMethodParameters -GetURLParameters $GetUrlParameters
            $Request.URI = "/projects/$URLParameters"; break;
        }
        Starred {
            $GetUrlParameters += @{starred=$true}
            $URLParameters = GetMethodParameters -GetURLParameters $GetUrlParameters
            $Request.URI = "/projects/$URLParameters"; break;
        }
        Single { $Request.URI="/projects/$Id"; break; }
        default { Write-Error "Incorrect parameter set."; break; }
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant