Gitlab API适用于组下的所有项目(Gitlab API for all projects under group)

编程入门 行业动态 更新时间:2024-10-28 13:14:34
Gitlab API适用于组下的所有项目(Gitlab API for all projects under group)

我想获得Gitlab中特定组下所有项目的列表。 以下是示例场景:

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

A组/项目1

A组/项目2

A组/项目3

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

B组/项目1

B组/项目2

B组/项目3

B组/项目4

B组/项目5

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

我正在寻找的是一个像GET /groups/:groupid/projects/all

那就是:该特定组的所有项目。 就像我说GET /groups/1/projects/all它会给我Project 1, Project 2 and Project 3 。

我能想到的唯一方法是获取所有项目的列表并循环遍历它们以查看它是否与我的组名匹配,但这将是很多不必要的解析。

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

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

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

Group A (id: 1) has 3 Project

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 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.

What I am looking for, is an operation something like GET /groups/:groupid/projects/all

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?

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

最满意答案

我正在寻找类似的东西,从许多小组获得所有项目。

我可以看到有两种方法可以实现,具体取决于您对该组的了解程度以及您需要的动态程度。

选项1

如果您知道所需组的ID,则可以按ID获取组,并为您提供项目

projects = Gitlab.group(group_id).projects

选项2

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

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 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.

Option 1

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

Option 2

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

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

更多推荐

本文发布于:2023-08-01 09:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1356784.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   项目   API   Gitlab   projects

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!