# 库以及文件操作
如果使用 project_full_path,确保 project_full_path 编码过,例子:/api/v3/projects/--> diaspora%2Fdiaspora (/ 编码 %2F)
# 下载存档的项目版本库
下载项目版本库的存档
GET /api/v3/projects/:id/repository/archive
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| sha | string(可选) | commit hash 值、分支名或 tag(默认默认分支) |
| file_paths | String(可选) | 限定为下载指定路径的文件 |
| format | String(可选) | 支持的 format 格式有".zip"、".tar"、“.tar.gz”、".tar.xz"、".tar.bz2"(默认为.zip 格式) |
| is_project_path_wrapped | boolean(可选) | 将项目名作为目录打包进去 (默认:false) |
注意:
1.本接口仅限下载<5GB 大小的 Git 仓库,如超出请使用 git clone 代替
2.为规范安全合理使用,各应用平台通过本接口下载"整仓(未指定 file_paths)"时限制 20 次/天,下载指定file_paths时限制2500次/天
如有疑问请联系工蜂助手
返回值:
zip下载流
# 获取原始文件内容
通过 提交的 hash 和路径获取文件的原始内容
GET /api/v3/projects/:id/repository/blobs/:sha
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| sha | string | commit hash 值、分支名或 tag |
| file_path | string | 文件路径 (文件名) |
返回值:
返回文件原始内容,示例:
package com.tencent.code.tgit.dao;
import java.util.List;
import com.github.pagehelper.Page;
import com.tencent.code.tgit.model.gitlab.Member;
import com.tencent.code.tgit.model.gitlab.MemberUserWrapper;
# 获取 blob 原始内容
通过文件 blob sha 获取文件的原始内容
GET /api/v3/projects/:id/repository/raw_blobs/:sha
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| sha | string | blob sha |
返回值:
返回文件原始内容,示例:
package com.tencent.code.tgit.dao;
import java.util.List;
import com.github.pagehelper.Page;
import com.tencent.code.tgit.model.gitlab.Member;
import com.tencent.code.tgit.model.gitlab.MemberUserWrapper;
# 获取差异内容
通过对比分支,提交或者 tags 获取差异内容
GET /api/v3/projects/:id/repository/compare
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| to | string | 源分支:提交的 hash、分支 或 tag |
| from | string(可选) | 目标分支:提交的 hash、分支 或 tag,不传时表示比较to与其第一 parent |
| straight | boolean(可选) | true:两个点比较差异,false:三个点比较差异。默认是 false |
| path | string(可选) | 文件路径 |
返回值:
{
"commit": {
"id": "845f510dd055c5c5c7754f272a149f49772c7e28",
"short_id": "845f510d",
"title": "更新文件 11",
"author_name": "git_user1",
"author_email": "git_user1@tencent.com",
"created_at": "2022-04-07T09:45:05+0000",
"message": "更新文件 11"
},
"base_commit": {
"id": "a2ca606079cb4b0e46c3cb7f680b49c321751c28",
"short_id": "a2ca6060",
"title": "更新文件 561111 ",
"author_name": "git_user1",
"author_email": "git_user1@tencent.com",
"created_at": "2022-04-06T02:02:24+0000",
"message": "更新文件 561111 "
},
"commits": [
{
"id": "845f510dd055c5c5c7754f272a149f49772c7e28",
"short_id": "845f510d",
"title": "更新文件 11",
"author_name": "git_user1",
"author_email": "git_user1@tencent.com",
"created_at": "2022-04-07T09:45:05+0000",
"message": "更新文件 11"
}
],
"diffs": [
{
"old_path": "11",
"new_path": "11",
"a_mode": 33188,
"b_mode": 33188,
"diff": "--- a/11\n+++ b/11\n@@ -1 +1,2 @@\n-!update\n\\ No newline at end of file\n+!update\n+1111\n\\ No newline at end of file\n",
"new_file": false,
"renamed_file": false,
"deleted_file": false,
"is_too_large": false,
"is_collapse": false,
"additions": 2,
"deletions": 1
}
],
"compare_timeout": false,
"compare_same_ref": false,
"over_flow": false,
"files_total": 1,
"commits_total": 1,
"ahead_by": 0,
"behind_by": 1
}
# 获取差异 commits
通过对比分支,提交或者 tags 获取差异 commits,对应git log <from>..<to>命令
GET /api/v3/projects/:id/repository/compare/commits
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| from | string | 目标分支:提交的 hash、分支 或 tag |
| to | string | 源分支:提交的 hash、分支 或 tag |
| page | integer(可选) | 分页(默认值:1) |
| per_page | integer(可选) | 默认页面大小(默认值:20,最大值:10000) |
| paths | array of string(可选) | 文件的完整路径 (作为 urlParam 时/需转义为%2f, 作为 body 时不用) |
注意:参数 paths 最长允许传 200 个元素,可使用路径前缀,不用“/”开头
返回值:
[
{
"id": "e9c5aa72c9e22592ee2611d896b730c1a95cc339",
"short_id": "e9c5aa72"
"title": "xxx",
"author_name": "git_user1",
"author_email": "git_user1@tencent.com",
"created_at": "2015-03-13T09:51:06+0000",
"message": "xxx"
},
{
"id": "11a63fa022906668338166ce7f2e7bf35d502285",
"short_id": "11a63fa0"
"title": "xxx",
"author_name": "git_user1",
"author_email": "git_user1@tencent.com",
"created_at": "2015-03-13T09:51:06+0000",
"message": "xxx"
}
]
# 获取差异文件列表
通过对比分支,提交或者 tags 获取差异文件列表
GET /api/v3/projects/:id/repository/compare/changed_files/list
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| to | string | 源分支:提交的 hash、分支 或 tag |
| from | string(可选) | 目标分支:提交的 hash、分支 或 tag,不传时表示比较to与其第一 parent |
| straight | boolean(可选) | true:两个点比较差异;false:三个点比较差异。默认是 false |
| calc_lines | boolean(可选) | true:计算文件变更行数;false:不计算文件变更行数,传 false 返回速度更快。默认值是 true,推荐传 false |
| page | integer(可选) | 分页(默认值:1) |
| per_page | integer(可选) | 默认页面大小(默认值:200,最大值:1000) |
| paths | array of string(可选) | 文件路径 |
返回值:
[
{
"old_path": "/dev/null",
"new_path": "xxxxxxxx",
"a_mode": 0,
"b_mode": 33188,
"new_file": true,
"renamed_file": false,
"deleted_file": false,
"additions":1,
"deletions":2
},
{
"old_path": "README.md",
"new_path": "README.md",
"a_mode": 33188,
"b_mode": 33188,
"new_file": false,
"renamed_file": false,
"deleted_file": false,
"additions": 1,
"deletions": 1
}
]
# 获取版本库文件和目录列表
返回项目版本库文件和目录列表。
GET /api/v3/projects/:id/repository/tree
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| ref_name | string(可选) | commit hash 值、分支 或 tag,默认:默认分支 |
| path | string(可选) | 文件路径 |
| max_depth | integer(可选) | 遍历目录最大深度(-1表示不限制,深度从1开始),默认:1 |
| page | integer(可选) | 分页页号(从1开始),默认:1 |
| per_page | integer(可选) | 每页的数量,默认:10000 |
| merge_alone_dir | boolean(可选) | 是否合并并深入遍历单一连续目录,仅当max_depth为1时有效。如a目录仅有子目录b,b下仅有文件c,结果为a/b,而非a。默认:true |
返回值:
[
{
"id": "23c22934e8b4f901dd264cdd100d2f7c339014f5",
"name": "GroupMilestoneStateStatistics.java",
"type": "blob",
"mode": "100644"
},
{
"id": "30a6e86afd0d641b8e9715a6eab5165a71e56e80",
"name": "GroupMilestoneStatistics.java",
"type": "blob",
"mode": "100644"
},
{
"id": "69756319f6abcc246c11c932a3c07c923800544c",
"name": "GroupStatisticsById.java",
"type": "blob",
"mode": "100644"
},
{
"id": "28bdc11874295c5722276a63502010acb92cd9b6",
"name": "GroupTypeStatistics.java",
"type": "blob",
"mode": "100644"
},
{
"id": "b7899b52f700434959e228532171eebdc8a91bd5",
"name": "TGitErrorStatistics.java",
"type": "blob",
"mode": "100644"
}
]
# 获取单个文件内容和信息
取得一个特定文件的文件内容和一些文件信息,如名称、大小、所在提交等,文件内容content用 Base64 编码,解析时请注意解码。
GET /api/v3/projects/:id/repository/files
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| ref | string | ref可以是SHA, branch name, tag name |
| file_path | string | 文件路径(文件名) |
返回值:
{
"file_name": "foo.h",
"file_path": "src/controller/",
"size": 15,
"ref": "master",
"blob_id": "37c36524713aa8083f787066a9ed0c0d2f82bbb4",
"blob_type": "blob",
"blob_mode": "100644",
"commit_id": "b5e3f65af2fd6d2895414a679290cad7664217b3",
"content": "I2lmbmRlZiBXT1JLVFJFRV9ICiNkZWZpbmUgV09SS1RSRUVfSAoKI2luY2x1ZGUgInJlZnMuaCIKCnN0cnVjdCBzdHJidWY7CgpzdHJ1Y3Qgd29ya3RyZWUgewoJY2hhciAqcGF0aDsKCWNoYXIgKmlkOwoJY2hhciAqaGVhZF9yZWY7CQkvKiBOVUxMIGlmIEhFQUQgaXMgYnJva2VuIG9yIGRldGFjaGVkICovCgljaGFyICpsb2NrX3JlYXNvbjsJLyogaW50ZXJuYWwgdXNlICovCglzdHJ1Y3Qgb2JqZWN0X2lkIGhlYWRfb2lkOwoJaW50IGlzX2RldGFjaGVkOwoJaW50IGlzX2JhcmU7CglpbnQgaXNfY3VycmVudDsKCWludCBsb2NrX3JlYXNvbl92YWxpZDsKfTs=",
"encoding": "base64"
}
若查询的文件大小超过 2M,或者非文本文件,content 会返回 null
# 新增文件
允许您向项目版本库创建文件
POST /api/v3/projects/:id/repository/files
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| file_path | string | 文件路径 (文件名) |
| branch_name | string | 分支 名 |
| encoding | string(可选) | 内容编码,可选:text、base64,默认:text |
| content | string | 内容 |
| commit_message | string | 描述信息 |
返回值:
{
"file_path": "controller",
"file_name": "controller",
"branch_name": "master",
"commit": {
"id": "6269835cafdd89e6d8b8d4a4e3738c79206c1d06",
"message": "推送新内容",
"parent_ids": [
"11a63fa022906668338166ce7f2e7bf35d502285"
],
"authored_date": "2012-06-07T07:38:33+0000",
"author_name": "git_user1",
"author_email": "git_user1@tencent.com",
"committed_date": "2012-06-07T07:38:33+0000",
"committer_name": "git_user1",
"committer_email": "git_user1@tencent.com",
"title": "推送新内容",
"created_at": "2012-06-07T07:38:33+0000",
"short_id": "6269835c"
}
}
# 删除文件
删除项目版本库文件
DELETE /api/v3/projects/:id/repository/files
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| file_path | string | 文件路径(文件名) |
| branch_name | string | 分支名 |
| commit_message | string | 描述 |
返回值:
{
"file_path": "controller",
"file_name": "controller",
"branch_name": "master",
"commit": {
"id": "6269835cafdd89e6d8b8d4a4e3738c79206c1d06",
"message": "推送新内容",
"parent_ids": [
"11a63fa022906668338166ce7f2e7bf35d502285"
],
"authored_date": "2012-06-07T07:38:33+0000",
"author_name": "git_user1",
"author_email": "git_user1@tencent.com",
"committed_date": "2012-06-07T07:38:33+0000",
"committer_name": "git_user1",
"committer_email": "git_user1@tencent.com",
"title": "推送新内容",
"created_at": "2012-06-07T07:38:33+0000",
"short_id": "6269835c"
}
}
# 编辑文件
更新项目版本库文件
PUT /api/v3/projects/:id/repository/files
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| file_path | string | 文件路径(文件名) |
| branch_name | string | 分支名 |
| encoding | string(可选) | 内容编码,可选:text、base64,默认:text |
| content | string | 内容 |
| commit_message | string | 注释 |
返回值:
{
"file_path": "controller",
"file_name": "controller",
"branch_name": "master",
"commit": {
"id": "6269835cafdd89e6d8b8d4a4e3738c79206c1d06",
"message": "推送新内容",
"parent_ids": [
"11a63fa022906668338166ce7f2e7bf35d502285"
],
"authored_date": "2012-06-07T07:38:33+0000",
"author_name": "git_user1",
"author_email": "git_user1@tencent.com",
"committed_date": "2012-06-07T07:38:33+0000",
"committer_name": "git_user1",
"committer_email": "git_user1@tencent.com",
"title": "推送新内容",
"created_at": "2012-06-07T07:38:33+0000",
"short_id": "6269835c"
}
}
# 批量提交修改文件
在一次 commit 中,完成新增/删除/编辑多个文件。限制类型为文本,数量为 200。
POST /api/v3/projects/:id/repository/files/batch
请将参数以 json 的格式放置在 request 请求体中。 参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| branch_name | string | 分支名称 |
| commit_message | string | 提交信息 |
| add_files | fileParam[] | 新增文件: 参数说明 [{"path":"","content":""}] |
| edit_files | fileParam[] | 修改文件: 参数说明 [{"path":"","content":""}] |
| delete_path | string[] | 删除文件 |
Body 举例:
{
"branch_name": "dev",
"commit_message" : "test",
// add_files、edit_files、delete_path 不能全都为空
"add_files":[{"path":"test/file_commita01.txt","content":"测试新增文件"}],
"edit_files": [{"path":"edit.txt","content":"修改文件"}],
"delete_path": ["del.txt"]
}
返回值:
{
"add_path": [
"test/file_commita01.txt"
],
"branch_name": "dev",
"delete_path": [
"del.txt"
],
"edit_path": [
"edit.txt"
],
"commit": {
"id": "6269835cafdd89e6d8b8d4a4e3738c79206c1d06",
"message": "推送新内容",
"parent_ids": [
"11a63fa022906668338166ce7f2e7bf35d502285"
],
"authored_date": "2012-06-07T07:38:33+0000",
"author_name": "git_user1",
"author_email": "git_user1@tencent.com",
"committed_date": "2012-06-07T07:38:33+0000",
"committer_name": "git_user1",
"committer_email": "git_user1@tencent.com",
"title": "推送新内容",
"created_at": "2012-06-07T07:38:33+0000",
"short_id": "6269835c"
}
}
# 查看文件的提交历史
获取文件历史信息,每个历史范围包括行和相应的提交信息,请求量大建议使用【批量查看文件的提交历史】接口
GET /api/v3/projects/:id/repository/files/:file_path/blame
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| file_path | string | 文件的完整路径(/需转义为%2f) |
| ref | string | 提交的 hash、分支 或 tag |
| line_number | integer(可选) | 指定行号 |
返回值:
[
{
"commit": {
"id": "985a073c8849d4dc52a5b513b507862d00ac917a",
"message": "close ##24,"
"parent_ids": [
"bfc7d86b226250328484816a3a4b646559aee6bc"
],
"authored_date": "2019-09-19T10:47:58+0000",
"author_name": "zhou",
"author_email": "zhou@tencent.com",
"committed_date": "2019-09-19T10:47:58+0000",
"committer_name": "zhou",
"committer_email": "zhou@tencent.com",
"title": "close ##24,",
"short_id": "985a073c",
"created_at": "2019-09-19T10:47:58+0000"
},
"lines": [
"like"
],
"numbers": [
2
]
},
{
"commit": {
"id": "cd7419600a3a666b267143df8bac6bd66abd5815",
"message": "hello",
"parent_ids": [
"37cd7661d84d4dsc7a37d4c2609b9667428b3dfb"
],
"authored_date": "2019-09-20T07:23:43+0000",
"author_name": "zhou",
"author_email": "zhou@tencent.com",
"committed_date": "2019-09-20T07:23:43+0000",
"committer_name": "zhou",
"committer_email": "v_cshzhou@tencent.com",
"title": "hello",
"short_id": "cd741960",
"created_at": "2019-09-20T07:23:43+0000"
},
"lines": [
"hello message "
]
}
]
# 批量查看文件的提交历史
批量获取文件历史信息,每个历史范围包括行和相应的提交信息,批量文件数不能超过 20 个
POST /api/v3/projects/:id/repository/files/blames
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| file_path | List <string> | 文件的完整路径,格式是数组 |
| ref | string(可选) | 提交的 hash、分支 或 tag,不传默认为 HEAD |
| region_map | map(可选) | 指定过滤范围,请查看演示请求体 |
示例请求体:
{
"ref": "master",
"file_path": [
"README.md",
"abb.txt"
],
"region_map": { // 指定blame的行范围,非必传,不传默认为整个文件
"abb.txt": [ // 文件名
{
"start": 2, // blame起始行,注意:0行是第一行
"length": 1 // 从起始行(包含)开始,需要blame的总行数
}
]
}
}
返回值:
[
{
"fileName": "abb.txt",
"annotateds": [
{
"commit": null,
"lines": [
"jdhajkshdka",
"dajksdhak"
]
},
{
"commit": {
"id": "350973b805b96afe5dad99c0f6884087a08385f5",
"message": "fix: 解决 lfs 出现 bean 注册失败问题 --other\n",
"parent_ids": [
"f90ae5d410fc79bba2663f4db861f16535a3a60b"
],
"authored_date": "2024-05-27T12:14:42+0000",
"author_name": "zhangsan",
"author_email": "zhangsan@tencent.com",
"committed_date": "2024-05-27T12:14:42+0000",
"committer_name": "zhangsan",
"committer_email": "zhangsan@tencent.com",
"title": "fix: 解决 lfs 出现 bean 注册失败问题 --other",
"created_at": "2024-05-27T12:14:42+0000",
"short_id": "350973b8"
},
"lines": [
"djkashdka"
]
},
{
"commit": null,
"lines": [
"daksdhjka",
"dajkdhak",
"dhasjkdha"
]
}
]
},
{
"fileName": "README.md",
"annotateds": [
{
"commit": {
"id": "c221fa7d16d7e7b4000da005285605d120f252e7",
"message": "添加新文件",
"parent_ids": [],
"authored_date": "2024-05-27T11:17:26+0000",
"author_name": "zhangsan",
"author_email": "zhangsan@tencent.com",
"committed_date": "2024-05-27T11:17:26+0000",
"committer_name": "zhangsan",
"committer_email": "zhangsan@tencent.com",
"title": "添加新文件",
"created_at": "2024-05-27T11:17:26+0000",
"short_id": "c221fa7d"
},
"lines": [
"the first\r"
]
},
{
"commit": {
"id": "af888bf4013f7151ecca8dd40d453c78ef82e15c",
"message": "更新文件 README.md33",
"parent_ids": [
"c221fa7d16d7e7b4000da005285605d120f252e7"
],
"authored_date": "2024-05-27T11:18:07+0000",
"author_name": "zhangsan",
"author_email": "zhangsan@tencent.com",
"committed_date": "2024-05-27T11:18:07+0000",
"committer_name": "zhangsan",
"committer_email": "zhangsan@tencent.com",
"title": "更新文件 README.md33",
"created_at": "2024-05-27T11:18:07+0000",
"short_id": "af888bf4"
},
"lines": [
"the 2\r",
"the 3\r",
"the 3\r",
"the 3the 3\r",
"the 3\r",
"the 3\r",
"the 3\r",
"the 3\r"
]
}
]
}
]
# 新增版本库锁
允许您向项目版本库指定目录或文件创建文件锁或目录锁
POST /api/v3/projects/:id/repository/locks
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| path | string | 文件的完整路径(/需转义为%2f) |
| branch | string | 分支名 |
| lock_type | integer | 锁类型,默认值为 0 代表文件,值为 1 代表目录锁 |
| lock_msg | string(可选) | 描述信息 |
返回值:
{
"locks": [
{
"lock_uid": "f7ed3dc97a8e7a708d78a92399793115339c2e29",
"project_id": 1234,
"branch": "master",
"path": "README.md",
"owner": "jack",
"lock_type": 0,
"created_at": "2022-12-05T09:30:09+0000"
}
],
"status": "lock_success"
}
# 批量新增版本库锁
允许您向项目版本库批量增加目录或文件创建文件锁或目录锁
POST /api/v3/projects/:id/repository/locks/batchCreate
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| paths | array of string | 文件的完整路径(作为 urlParam 时/需转义为%2f, 作为 body 时不用) /a/b,/c/d,/e/f |
| branch | string | 分支名 |
| lock_type | integer | 锁类型,默认值为 0 代表文件,值为 1 代表目录锁 |
| lock_msg | string(可选) | 描述信息 |
注意:参数 paths 只能全部是目录路径或者文件路径,且批量路径情况下,不支持/(根目录) 虚拟路径
返回值:
{
"locks": [
{
"lock_uid": "f7ed3dc97a8e7a708d78a92399793115339c2e29",
"project_id": 1234,
"branch": "master",
"path": "README.md",
"owner": "jack",
"lock_type": 0,
"created_at": "2022-12-05T09:30:09+0000"
}
],
"status": "lock_success"
}
# 删除版本库锁
删除版本库指定文件锁或目录锁,版本库分支 master 以上权限可以删除它人的锁,通过路径 (path) 删除锁时,必须带分支 (branch) 参数
DELETE /api/v3/projects/:id/repository/locks
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| lock_uid | string | 锁的惟一 uid 标识 |
| path | string | 锁的路径 |
| branch | string(可选) | 分支名 |
返回值:
{
"status": "no_lock/delete_failed",
"lock_uid": "e9fa70543880f7a4974578de49e8498bd47dc786",
"path": "/app/models/key.rb"
}
# 批量删除版本库锁
批量删除版本库指定文件锁或目录锁,版本库分支 master 以上权限可以删除它人的锁,参数 lock_uids 和 paths 限制长度是 1000,如果两个参数同时有值,优先以 lock_uids 为准, 通过路径 (paths) 删除锁时,必须带分支 (branch) 参数
DELETE /api/v3/projects/:id/repository/locks/batchDelete
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| lock_uids | List<string> | 锁的惟一 uid 标识 x..x1,x..x2 |
| paths | List<string> | 锁的路径 /a/b,/c/d,/e/f |
| branch | string(可选) | 分支名 |
返回值:
{
"status": "no_lock/delete_failed",
"lock_uids": ["e9fa70543880f7a4974578de49e8498bd47dc786"],
"paths": ["/app/models/key.rb"]
}
# 查看版本库锁
获取版本库的锁信息
GET /api/v3/projects/:id/repository/locks
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| path | string(可选) | 文件的完整路径(/需转义为%2f) |
| branch | string(可选) | 分支名 |
| lock_type | integer(可选) | 锁类型,不传值代表所有类型,值为 0 代表文件锁,值为 1 代表目录锁 |
| owner | string(可选) | 锁的创建者(仅支持单个用户) |
| page | integer(可选) | 分页页号(从1开始),默认:1 |
| per_page | integer(可选) | 每页的数量,默认:10000 |
返回值:
[
{
"lock_uid": "e9fa70533980f7a4974578de49e8498bd47dc786",
"project_id": 1234,
"branch": "test",
"path": "/app/models/key.rb",
"owner": "jackchan",
"lock_type": 0,
"created_at": "2019-09-24T09:34:48+0000"
},
{
"lock_uid": "e9fa70543880f7a4974578de49e8498bd47dc786",
"project_id": 1234,
"branch": "test",
"path": "/app/models/key.txt",
"owner": "jackchan",
"lock_type": 0,
"created_at": "2019-09-24T09:34:48+0000"
}
]
# 下载项目版本库的原始 lfs 文件
下载项目版本库的原始 lfs 文件
GET /api/v3/projects/:id/repository/lfs/file
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| ref | string | commit hash 值、分支名或 tag |
| file_path | String | 限定为下载指定路径的文件(/需转义为%2f) |
返回值:
下载流
# 上传或更新项目版本库的 lfs 文件
上传或更新项目版本库的 lfs 文件(大小限制目前默认是 100M)
POST /api/v3/projects/:id/repository/lfs/file
curl -X POST localhost/api/v3/projects/:id/repository/lfs/file
-F file=@/data/test/gc.png
-F 'private_token=abcdefghijk'
-F 'ref=master'
-F 'file_path=test.csr'
-F 'commit_message=test'
-F 'opt_type=REPLACE‘
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| file | string | 需要上传或更新的文件本地路径 (格式:@local_file_path) |
| ref | string | commit hash 值、分支名或 tag |
| file_path | String | 限定为下载指定路径的文件(/需转义为%2f) |
| opt_type | string | 上传或更新类型 (类型:ADD / REPLACE) |
| commit_message | string | 提交或更新的记录信息 |
返回值:
200或相关状态码
# 新增 Blob 评论
新增 Blob 评论
POST /api/v3/projects/:id/repository/blobs/:sha/notes
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| sha | string | commit hash 值、分支名或 tag |
| note | string | 评论内容 |
| path | string | 文件路径 |
| line | integer | 行号 |
返回值:
{
"id": 25214842,
"parent_id": null,
"body": "测试 blob",
"attachment": null,
"author": {
"id": 15597,
"username": "git_user",
"web_url": "http://git.tencent.com/u/git_user",
"name": "git_user",
"state": "active",
"avatar_url": "https://git.tencent.com/common/images/avatar/default_user_avatar.png"
},
"created_at": "2024-08-09T06:09:13+0000",
"system": false,
"risk": 0,
"resolve_state": 0,
"line_code": "442292b8a7efeabbe4cc176709b833b1792140ec_5_5",
"commit_id": "bf97e6167c9bfcdca7a1ae1a1a0d12f25673caca",
"file_path": "pom.xml",
"note_position": {
"origin_position": {
"note_id": 25214842,
"left_line_num": 5,
"right_line_num": 5,
"base_commit_sha": null,
"start_commit_sha": null,
"head_commit_sha": null,
"new_path": "pom.xml",
"old_path": "pom.xml"
},
"outdate_position": null,
"latest_position": {
"note_id": 25214842,
"left_line_num": 5,
"right_line_num": 5,
"base_commit_sha": null,
"start_commit_sha": null,
"head_commit_sha": null,
"new_path": "pom.xml",
"old_path": "pom.xml"
}
},
"note": "测试 blob"
}
# 编辑 Blob 评论
编辑 Blob 评论
PUT /api/v3/projects/:id/repository/blobs/:sha/notes/:note_id
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| sha | string | commit hash 值、分支名或 tag |
| note_id | integer | 评论的 id |
| path | string | 文件路径 |
| body | string | 评论内容 |
返回值:
{
"id": 25214833,
"parent_id": null,
"body": "测试 blob--更新",
"attachment": null,
"author": {
"id": 15597,
"username": "git_user",
"web_url": "http://git.tencent.com/u/git_user",
"name": "git_user",
"state": "active",
"avatar_url": "https://git.tencent.com/common/images/avatar/default_user_avatar.png"
},
"created_at": "2024-08-08T07:19:08+0000",
"system": false,
"risk": 0,
"resolve_state": 1,
"line_code": "442292b8a7efeabbe4cc176709b833b1792140ec_13_13",
"commit_id": "14fc6d3cf8d81262196082ae05185cb09cac3da9",
"file_path": "pom.xml",
"note_position": {
"origin_position": {
"note_id": 25214833,
"left_line_num": 13,
"right_line_num": 13,
"base_commit_sha": "01f1fdcb2f82ab780401265fe5d5ced0caeb68f4",
"start_commit_sha": "14fc6d3cf8d81262196082ae05185cb09cac3da9",
"head_commit_sha": "01f1fdcb2f82ab780401265fe5d5ced0caeb68f4",
"new_path": "pom.xml",
"old_path": "pom.xml"
},
"outdate_position": null,
"latest_position": {
"note_id": 25214833,
"left_line_num": 13,
"right_line_num": 13,
"base_commit_sha": "01f1fdcb2f82ab780401265fe5d5ced0caeb68f4",
"start_commit_sha": "14fc6d3cf8d81262196082ae05185cb09cac3da9",
"head_commit_sha": "01f1fdcb2f82ab780401265fe5d5ced0caeb68f4",
"new_path": "pom.xml",
"old_path": "pom.xml"
}
},
"note": "测试 blob--更新"
}
# 查询 Blob 评论
查询 Blob 评论
GET /api/v3/projects/:id/repository/blobs/:sha/notes
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| sha | string | commit hash 值、分支名或 tag |
| path | string | 文件路径 |
| page | integer(可选) | 页码 |
| per_page | integer(可选) | 分页数,默认 20,最大 100 |
返回值:
[
{
"id": 25214838,
"parent_id": 25214831,
"body": "测试 blobji",
"attachment": null,
"author": {
"id": 15597,
"username": "git_user",
"web_url": "http://git.tencent.com/u/git_user",
"name": "git_user",
"state": "active",
"avatar_url": "https://git.tencent.com/common/images/avatar/default_user_avatar.png"
},
"created_at": "2024-08-08T11:36:47+0000",
"system": false,
"risk": 0,
"resolve_state": 0,
"line_code": "442292b8a7efeabbe4cc176709b833b1792140ec_6_6",
"commit_id": "14fc6d3cf8d81262196082ae05185cb09cac3da9",
"file_path": "pom.xml",
"note_position": null,
"note": "测试 blobji"
}
]
# 回复 Blob 评论
回复 Blob 评论
POST /api/v3/projects/:id/repository/blobs/:sha/notes/:note_id/replies
参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| id | integer 或 string | 项目 ID 或 项目全路径 project_full_path |
| sha | string | commit hash 值、分支名或 tag |
| note_id | integer | 评论的 id |
| body | string | 评论内容 |
返回值:
{
"id": 25214838,
"parent_id": 25214831,
"body": "测试 blobji",
"attachment": null,
"author": {
"id": 15597,
"username": "git_user",
"web_url": "http://git.tencent.com/u/git_user",
"name": "git_user",
"state": "active",
"avatar_url": "https://git.tencent.com/common/images/avatar/default_user_avatar.png"
},
"created_at": "2024-08-08T11:36:47+0000",
"system": false,
"risk": 0,
"resolve_state": 0,
"line_code": "442292b8a7efeabbe4cc176709b833b1792140ec_6_6",
"commit_id": "14fc6d3cf8d81262196082ae05185cb09cac3da9",
"file_path": "pom.xml",
"note_position": null,
"note": "测试 blobji"
}