git - 按分支和消息过滤 gitlab 提交 - gitlab API
问题描述
我正在编写使用 gitlab api 的应用程序。
为此,我想通过分支和提交消息搜索/过滤提交。
但是 Gitlab 支持两个端点,它们是
搜索 :
/api/v4/projects/24/search?scope=commits&search=fixed
这将仅按消息过滤,而不是按分支过滤。
从提交 api
/projects/:id/repository/commits
即使这种支持也只支持少数参数。
但我想过滤为特定分支完成的提交。
解决方案
不要认为您可以在单个 api 调用中通过消息和分支获得过滤响应。
- 您可以使用 commits api 来获取按分支过滤的所有提交,然后您可以在应用程序中按消息过滤它们。
GET /projects/:id/repository/commits?ref_name=<your branch name>
示例响应:
[
{
"id": "ed899a2f4b50b4370feeea94676502b42383c746",
"short_id": "ed899a2f4b5",
"title": "Replace sanitize with escape once",
"author_name": "Example User",
"author_email": "user@example.com",
"authored_date": "2012-09-20T11:50:22+03:00",
"committer_name": "Administrator",
"committer_email": "admin@example.com",
"committed_date": "2012-09-20T11:50:22+03:00",
"created_at": "2012-09-20T11:50:22+03:00",
"message": "Replace sanitize with escape once", ----> Message
"parent_ids": [
"6104942438c14ec7bd21c6cd5bd995272b3faff6"
],
"web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
}
]
- 或者您可以先按消息搜索,然后获取提交所属的引用列表,
GET /projects/:id/repository/commits/:sha/refs
但这将需要两个 API 调用,一个是获取按消息过滤的提交,然后是获取提交所属的引用列表。
[
{"type": "branch", "name": "'test'"},
{"type": "branch", "name": "add-balsamiq-file"},
{"type": "branch", "name": "wip"},
{"type": "tag", "name": "v1.1.0"}
]
推荐阅读
- reactjs - 反应本机元素工具提示给出错误
- python - 确定输入数组中的元素满足2个引用数组条件的索引,而不在python中使用循环
- javascript - VueJS提交延迟导致数据错误
- matlab - 对于运行良好的代码,“这种类型的变量不支持点索引”?
- css - CSS 适用于其他浏览器,但不适用于 Internet Explorer
- c# - 将扫描的pdf插入数据库c#
- python - 如何将变化的变量从一个脚本导入到另一个?
- git - 压缩您拉出的分支上的所有提交
- python - 如果不是系统键盘,如何连接蓝牙键盘?
- python - 无法从我的 .flaskenv 文件中导入值