gitlab API-如何从问题创建分支

时间:2019-04-08 11:59:15

标签: linux gitlab gitlab-api

在git实验室中,您可以创建一个问题,然后在该问题中创建一个分支。该分支链接到问题(我认为是由于分支名称开头的问题编号),这样,当您对该分支执行合并请求时,它将自动关闭问题。

所以我的问题是-如何通过API做到这一点?我可以创建问题,但是在问题API中(据我所知)没有控件可以创建相关分支。

有可能吗?

能够一口气创建分支问题会很高兴-但我认为这不可能吗?

2 个答案:

答案 0 :(得分:1)

Ok - its not perhaps the best answer, but here is what I came up with for a interim solution (in linux bash):

  1. Raise the issue store response in cmd_resp
  2. Extract the issue ID: echo $cmd_resp | grep -o -P '(?<=iid":).*(?=,"project_id)'. Where the issue ID is found by looking for: iid":<ISSUE-ID>,"project_id
  3. Create a branch with the name: <ISSUE-ID>-some-branch-name - by having the issue ID at the start of the branch name, gitlab automatically makes a relation to that issue.

So - its quite a simple approach, but it does not feel very integrated. I would still prefer to do that from the point of view of the issue.

答案 1 :(得分:1)

无法通过问题API创建与问题相关的分支。

但是,这与RESTful API的设计方式一致。如果要创建分支,则需要向分支API发出POST请求。

POST /projects/:id/repository/branches

您已经发现,GitLab非常擅长自动将问题,MR和分支链接在一起。 对于要链接到问题的分支,只需使用问题ID开始分支即可。但是,通常将合并请求链接到问题就足够了。我认为,您实际上不必关心分支机构。您以后可以通过issue-> MR-> branch

访问分支

每当MR的描述文本链接到问题时(例如#1),合并请求就会链接到问题。如果您将问题ID添加到 Closes 语句中,则在MR解决后该问题也将关闭。

因此,您可以简单地通过API创建分支,并根据需要命名。然后,根据该问题创建一个MR,并在您的MR描述中添加Closes #1,其中1是您的问题ID。

此外,我建议使用更复杂的REST客户端。您不必自己解析问题ID。已将其正确设置为JSON响应中的字段。