Repositories API
- List repository tree
- Get a blob from repository
- Raw blob content
- Get file archive
- Compare branches, tags or commits
- Contributors
- Merge Base
Repositories API
List repository tree
获取项目中存储库文件和目录的列表. 如果可公开访问该存储库,则无需身份验证即可访问此端点.
此命令提供的功能与git ls-tree
命令基本相同. 有关更多信息,请参阅Git internals 文档中的Tree Objects部分.
GET /projects/:id/repository/tree
Parameters:
id
(必填)-经过身份验证的用户拥有的项目的 ID 或URL 编码路径path
(可选)-存储库中的路径. 用于获取子目录的内容ref
(可选)-存储库分支或标记的名称,或者如果未提供默认分支的名称recursive
(可选)-用于获取递归树的布尔值(默认为 false)per_page
(可选)-每页显示的结果数. 如果未指定,则默认为20
[ { "id": "a1e8f8d745cc87e3a9248358d9352bb7f9a0aeba", "name": "html", "type": "tree", "path": "files/html", "mode": "040000" }, { "id": "4535904260b1082e14f867f7a24fd8c21495bde3", "name": "images", "type": "tree", "path": "files/images", "mode": "040000" }, { "id": "31405c5ddef582c5a9b7a85230413ff90e2fe720", "name": "js", "type": "tree", "path": "files/js", "mode": "040000" }, { "id": "cc71111cfad871212dc99572599a568bfe1e7e00", "name": "lfs", "type": "tree", "path": "files/lfs", "mode": "040000" }, { "id": "fd581c619bf59cfdfa9c8282377bb09c2f897520", "name": "markdown", "type": "tree", "path": "files/markdown", "mode": "040000" }, { "id": "23ea4d11a4bdd960ee5320c5cb65b5b3fdbc60db", "name": "ruby", "type": "tree", "path": "files/ruby", "mode": "040000" }, { "id": "7d70e02340bac451f281cecf0a980907974bd8be", "name": "whitespace", "type": "blob", "path": "files/whitespace", "mode": "100644" } ]
Get a blob from repository
Allows you to receive information about blob in repository like size and content. Note that blob content is Base64 encoded. This endpoint can be accessed without authentication if the repository is publicly accessible.
GET /projects/:id/repository/blobs/:sha
Parameters:
Raw blob content
通过 blob SHA 获取 blob 的原始文件内容. 如果可公开访问该存储库,则无需身份验证即可访问此端点.
GET /projects/:id/repository/blobs/:sha/raw
Parameters:
Get file archive
获取存储库的存档. 如果可公开访问该存储库,则无需身份验证即可访问此端点.
该端点的速率限制阈值为每分钟 5 个请求.
GET /projects/:id/repository/archive[.format]
format
是归档格式的可选后缀. 默认值为tar.gz
选项是tar.gz
, tar.bz2
, tbz
, tbz2
, tb2
, bz2
, tar
和zip
. 例如,指定archive.zip
将以 ZIP 格式发送存档.
Parameters:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.com/api/v4/projects/<project_id>/repository/archive?sha=<commit_sha>"
Compare branches, tags or commits
如果可公开访问该存储库,则无需身份验证即可访问此端点. 请注意,如果达到差异限制 ,差异可能会有一个空的差异字符串.
GET /projects/:id/repository/compare
Parameters:
id
(必填)-经过身份验证的用户拥有的项目的 ID 或URL 编码路径from
(必填)-提交 SHA 或分支名称to
(必需)-提交 SHA 或分支名称straight
(可选)-比较方法,对于from
和to
之间(from
..to
)之间的直接比较,为true
对于使用合并基数(from
…to
)’比较to
false
. 默认值为false
.
GET /projects/:id/repository/compare?from=master&to=feature
Response:
{ "commit": { "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1", "short_id": "12d65c8dd2b", "title": "JS fix", "author_name": "Example User", "author_email": "user@example.com", "created_at": "2014-02-27T10:27:00+02:00" }, "commits": [{ "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1", "short_id": "12d65c8dd2b", "title": "JS fix", "author_name": "Example User", "author_email": "user@example.com", "created_at": "2014-02-27T10:27:00+02:00" }], "diffs": [{ "old_path": "files/js/application.js", "new_path": "files/js/application.js", "a_mode": null, "b_mode": "100644", "diff": "--- a/files/js/application.js\n+++ b/files/js/application.js\n@@ -24,8 +24,10 @@\n //= require g.raphael-min\n //= require g.bar-min\n //= require branch-graph\n-//= require highlightjs.min\n-//= require ace/ace\n //= require_tree .\n //= require d3\n //= require underscore\n+\n+function fix() { \n+ alert(\"Fixed\")\n+}", "new_file": false, "renamed_file": false, "deleted_file": false }], "compare_timeout": false, "compare_same_ref": false }
Contributors
获取存储库贡献者列表. 如果可公开访问该存储库,则无需身份验证即可访问此端点.
GET /projects/:id/repository/contributors
Parameters:
id
(必填)-经过身份验证的用户拥有的项目的 ID 或URL 编码路径order_by
(可选)-返回按name
,email
或commits
(按提交日期排序)字段排序的贡献者. 默认为commits
sort
(可选)-返回贡献者按asc
或desc
顺序排序. 默认为asc
Response:
[{ "name": "Example User", "email": "example@example.com", "commits": 117, "additions": 2097, "deletions": 517 }, { "name": "Sample User", "email": "sample@example.com", "commits": 33, "additions": 338, "deletions": 244 }]
Merge Base
获取 2 个或更多引用(提交 SHA,分支名称或标签)的公共祖先.
GET /projects/:id/repository/merge_base
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer/string | yes | 项目的 ID 或URL 编码的路径 |
refs |
array | yes | 裁判找到共同的祖先,可以传递多个裁判 |
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/merge_base?refs[]=304d257dcb821665ab5110318fc58a007bd104ed&refs[]=0031876facac3f2b2702a0e53a26e89939a42209"
响应示例:
{ "id": "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863", "short_id": "1a0b36b3", "title": "Initial commit", "created_at": "2014-02-27T08:03:18.000Z", "parent_ids": [], "message": "Initial commit\n", "author_name": "Example User", "author_email": "user@example.com", "authored_date": "2014-02-27T08:03:18.000Z", "committer_name": "Example User", "committer_email": "user@example.com", "committed_date": "2014-02-27T08:03:18.000Z" }