5

在 Gitlab 网页上,您可以检查一个分支在主分支之后或之前有多少次提交。我的问题是是否可以使用“gitlab API”获取有关此信息?我检查了文档,但不幸的是找不到任何东西。

4

2 回答 2

0

可以解决问题的特定 Gitlab API 是

GET /projects/:id/repository/compare

更多信息,请访问https://docs.gitlab.com/ee/api/repositories.html#compare-branches-tags-or-commits

执行示例为您带来区分 2 个分支的提交数量

curl -s --header "PRIVATE-TOKEN: <access_token>" "https://gitlab.com/api/v4/projects/<project_id>/repository/compare?from=<branch_name_behind_in_commits>&to=<branch_name_ahead_in_commits>&straight=true" | jq '. | .commits | length'
  1. master如果您想查看分支 behind的分支有多少提交feature。您应该将主添加到字段并在字段中添加from功能分支to
  2. master如果您想查看分支 ahead的分支有多少提交feature。您应该将功能分支添加到字段并在字段中添加from主分支to
于 2022-02-16T08:43:32.503 回答
0

在 MR API 中查找 include_diverged_commits_count: "true"(默认为 false):https ://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr 。

唯一令人沮丧的(恕我直言)是这似乎只能通过 MR API 获得,因此您需要首先创建一个 MR。

于 2021-09-17T09:00:33.417 回答