组下所有项目的 Gitlab API [英] Gitlab API for all projects under group

查看:13
本文介绍了组下所有项目的 Gitlab API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取 Gitlab 中特定组下的所有项目的列表.这是示例场景:

I want to get a list of all the projects which are under a particular group in Gitlab. Here is the example scenario:

A 组 (id: 1) 有 3 个项目

Group A (id: 1) has 3 Project

A组/项目1

A组/项目2

A 组/项目 3

B 组(ID:2)有 5 个项目

Group B (id: 2) has 5 Projects

B 组/项目 1

B 组/项目 2

B 组/项目 3

B 组/项目 4

B 组/项目 5

现在,如果我点击其余 api GET/groups,它只会给我组列表.如果我点击其余 api GET/projects/all,它会给我一个所有项目的列表.

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

我正在寻找的是类似 GET/groups/:groupid/projects/all

即:该特定组的所有项目.就像我说 GET/groups/1/projects/all 一样,它会给我 Project 1、Project 2 和 Project 3.

That is: all the projects for that particular group. Like 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 loop over them to see if it matches my group name, but this will be lot of unnecessary parsing.

我怎样才能以更好的方式实现这一目标?

How can I achieve this in a better way?

我正在研究 Gitlab CE 7.2.1.我指的是 Gitlab API 文档

I am working on Gitlab CE 7.2.1. I am referring the Gitlab API documententation

推荐答案

我想做类似的事情,从多个组中获取所有项目.

I was looking to do something similar, getting all of the projects from a number of groups.

我可以看到有两种方法可以做到这一点,具体取决于您对小组的了解程度以及您需要它的动态程度.

There are 2 ways of doing this that I can see, depending on how much info you know about the group and how dynamic you need it to be.

选项 1

如果您知道所需组的 ID,则可以通过 ID 获取组,这将为您提供项目

If you know the IDs of the groups that you need, then you can get the group by ID and that will provide you with the projects

projects = Gitlab.group(group_id).projects

选项 2

如果您不知道组 ID 或需要能够更动态地传递组名称,则需要进行额外调用以获取所有组,循环遍历它们并获取各个组.这可能并不比你最初循环所有项目的想法更好,这取决于你有多少组/项目

If you don't know the group IDs or need to be able to pass in group names more dynamically, you will need to make an extra call to get all of the groups, loop through them and get the individual groups. This may not be any better than your original idea of looping over all of the projects, 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

我绝不是专家级的 Ruby 程序员,所以毫无疑问有更好的方法来实现这一点或改进代码,但这符合我的需要,因为它只需要偶尔运行,所以速度不是问题我

I am by no means an expert Ruby programmer, so there are no doubt far better ways of achieving this or improving the code, but this worked for my needs as it only needed to be run occasionally so speed was not an issue for me

这篇关于组下所有项目的 Gitlab API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆