3

According to the python-gitlab documentation, I need a gitlab.cfg file that should look something like this:

[global]
default = gitlabcom
ssl_verify = true
timeout = 30


[gitlabcom]
url = https://gitlab.com/
private_token = PERSONAL_ACCESS_TOKEN
api_version = 4

and then I should be able to list my projects with

gitlab -c gitlab.cfg project list

however, this gives me a list of projects that are not mine, e.g. (the list varies):

id: 13784565
path: 2019-08-25-form-from-classes

id: 13784562
path: faq

id: 13784561
path: curso-web-playground

id: 13784560
...

If I use curl I get the expected results:

curl --header "PRIVATE-TOKEN: PERSONAL_ACCESS_TOKEN" "https://gitlab.com/api/v4/groups/42424242/projects"

(where 42424242 is my group id).

I can't find any documentation on how to do this with gitlab.com (as opposed to a privately hosted gitlab instance).

2 Answers 2

1

I've found a hacky way to do it (hopefully someone will come up with a better answer):

gitlab -c gitlab.cfg -o json -f projects group get --id 42424242  | jq .projects[].name

where

gitlab -c gitlab.cfg -o json -f projects group get --id 42424242

gets all the data for the single group with id 42424242, as json (-o json) and prints only the projects field (-f projects - this can be skipped). The returned value looks like

{
    "projects": [
        {...lots of fields..., "name": "<project-name>", ...even more fields...}
        ...
    ]
}

then I pipe through jq (https://stedolan.github.io/jq/)

 | jq .projects[].name

which says, go into projects (.projects), iterate over all items in the list (.projects[]), and then extract the name from each list item (.projects[].name).

The result is:

"project1"
"project2"
"project3"
...
1

The project list command takes -h (help) flag:

(dev) go|c:\srv\tmp\gitlabtst> gitlab -c gitlab.cfg project list -h
usage: gitlab project list [-h] [--sudo SUDO] [--search SEARCH]
                           [--owned OWNED] [--starred STARRED]
                           [--archived ARCHIVED] [--visibility VISIBILITY]
                           [--order-by ORDER_BY] [--sort SORT]
                           [--simple SIMPLE] [--membership MEMBERSHIP]
                           [--statistics STATISTICS]
                           [--with-issues-enabled WITH_ISSUES_ENABLED]
                           [--with-merge-requests-enabled WITH_MERGE_REQUESTS_ENABLED]
                           [--with-custom-attributes WITH_CUSTOM_ATTRIBUTES]
                           [--page PAGE] [--per-page PER_PAGE] [--all]

To list all my projects is therefore:

gitlab -c gitlab.cfg project list --owned=1 --all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.