Gitlab API for all projects under a group

I want to get a list of all projects that are under a specific group in Gitlab. Here is an example script:

Group A (id: 1) has 3 projects

Group A / Project 1

Group A / Project 2

Group A / Project 3

Group B (id: 2) has 5 projects

Group B / Project 1

Group B / Project 2

Group B / Project 3

Group B / Project 4

Group B / Project 5

Now, if I remove the rest of the GET /groups api, it will only give me a list of groups. If I remove the remaining api GET /projects/all , it will give me a list of all projects.

What I'm looking for is an operation like GET /groups/:groupid/projects/all

That is: all projects for this particular group. For example, if I say GET /groups/1/projects/all , it will give me Project 1, Project 2 and Project 3 .

The only way I can think of is to get a list of all the projects and iterate over them to see if this is the name of my group, but it will be a lot of unnecessary analysis.

How can I achieve this better?

I am working on Gitlab CE 7.2.1. I mean the Gitlab API documentation

+3
git gitlab gitlab-ci
Jul 19 '15 at 6:05
source share
3 answers

I was looking for something similar, getting all the projects from several groups.

There are two ways to do this, which I can see, depending on how much information you know about the group and how dynamic you need it.

Option 1

If you know the identifiers of the groups that you need, you can get the group by identifier and provide you with projects

projects = Gitlab.group(group_id).projects

Option 2

If you do not know the group identifiers or should be able to transfer group names more dynamically, you will need to make an additional call to get all the groups, go through them and get individual groups. It may not be better than your initial idea of ​​the cycle for all projects, it depends on how many groups / projects you have

 groups = [] Gitlab.groups.each do |group| if ['your_group_name', 'another_group_name'].include? group.name groups << Gitlab.group(group.id) end end projects = [] groups.each do |group| projects << group.projects end 

I am by no means a specialist in Ruby programming, so there is no doubt that they are much better suited for this or improve the code, but it worked for my needs, as it was needed only from time to time, so speed was not a problem for me

+1
Jul 31 '15 at 9:33
source share

I tested Gitlab 8.0. Its group API can provide a list of projects in a specific group. Just send a GET request to http://gitlab.example.com/api/v3/groups/[group_id]?private_token=xxxxxxxxxxxx with your personal token.

For example: http://gitlab.example.com/api/v3/groups/3?private_token=xxxxxxxxxxxxx .

In the JSON response, the list is an array under the projects key.

+3
Oct 02 '15 at 8:54
source share

This is pretty handy if you use curl.

Just use this code.

curl --header "PRIVATE-TOKEN: xxxxxxxxxxxxxxx" http://gitlab.your_namespace.com/api/v4/groups/your_group/projects

0
Apr 6 '17 at 11:39 on
source share



All Articles