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

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

问题描述

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

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


A组/项目1



A组/项目2

A组/ p>

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


B组/项目1

B组/项目2

B组/ p>

B组/项目4



B组/项目5


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



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



即:该特定组的所有项目。如果我说 GET / groups / 1 / projects / all ,它会给我项目1,项目2和项目3

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



我如何以更好的方式实现这一目标?



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

解决方案

我期待着做类似的事情,从多个组织获得所有项目。



有两种方法可以做到这一点,我可以看到,这取决于你对该团队了解多少信息以及你需要的动态程度。

选项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)
结束
结束

项目= []
groups.each do | group |
项目<< group.projects
end

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


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

解决方案

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

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

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