Repositories API

Repositories API

获取项目中存储库文件和目录的列表. 如果可公开访问该存储库,则无需身份验证即可访问此端点.

此命令提供的功能与命令基本相同. 有关更多信息,请参阅Git internals 文档中的Tree Objects部分.

Parameters:

  • id (必填)-经过身份验证的用户拥有的 ID 或URL 编码路径
  • path (可选)-存储库中的路径. 用于获取子目录的内容
  • ref (可选)-存储库分支或标记的名称,或者如果未提供默认分支的名称
  • recursive (可选)-用于获取递归树的布尔值(默认为 false)
  • per_page (可选)-每页显示的结果数. 如果未指定,则默认为20
  1. [ { "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.

  1. GET /projects/:id/repository/blobs/:sha

Parameters:

  • id (必填)-经过身份验证的用户拥有的项目的 ID 或
  • sha (必填)-Blob SHA
  1. GET /projects/:id/repository/blobs/:sha/raw

Parameters:

  • id (必填)-经过身份验证的用户拥有的项目的 ID 或
  • sha (必填)-Blob SHA

Get file archive

获取存储库的存档. 如果可公开访问该存储库,则无需身份验证即可访问此端点.

该端点的速率限制阈值为每分钟 5 个请求.

format是归档格式的可选后缀. 默认值为tar.gz 选项是tar.gztar.bz2tbztbz2 , , bz2tarzip . 例如,指定archive.zip将以 ZIP 格式发送存档.

Parameters:

  • sha (可选)-提交要下载的 SHA. 可以使用标签,分支引用或 SHA. 如果未指定,则默认为默认分支的尖端. 例如:
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.com/api/v4/projects/<project_id>/repository/archive?sha=<commit_sha>"
  1. GET /projects/:id/repository/compare

Parameters:

  • id (必填)-经过身份验证的用户拥有的 ID 或URL 编码路径
  • from (必填)-提交 SHA 或分支名称
  • to (必需)-提交 SHA 或分支名称
  • straight (可选)-比较方法,对于fromto之间( from .. to )之间的直接比较,为true对于使用合并基数( fromto )’比较 false . 默认值为false .
  1. GET /projects/:id/repository/compare?from=master&to=feature

Response:

Contributors

获取存储库贡献者列表. 如果可公开访问该存储库,则无需身份验证即可访问此端点.

  1. GET /projects/:id/repository/contributors

Parameters:

  • id (必填)-经过身份验证的用户拥有的项目的 ID 或
  • order_by (可选)-返回按nameemailcommits (按提交日期排序)字段排序的贡献者. 默认为commits
  • sort (可选)-返回贡献者按ascdesc顺序排序. 默认为asc

Response:

  1. [{ "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 }]

    响应示例:

    1. { "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" }