gitApi操作需求
所需提供参数列表
参数名称 | 描述 |
---|---|
PRIVATE-TOKEN | 用于操作gitapi权限所需的token |
projectId | 当前git项目的id |
author_email | 提交人邮箱 |
author_name | 提交人名称 |
commit_message | 提交信息 |
1、搜索restful项目的projectId
https://xxx.xxx.com/api/v4/projects?private_token=xxxxxxxxxxxxxxxx&per_page=100&page=0&order_by=name
通过api返回结果查询当前项目id
2、获取文件内容
1、请求URL
https://xxx.xxx.com/regression/restapi/-/raw/{filePath}?inline=false
2、请求方式
POST
3、请求参数
请求参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
filePath | true | String | 带项目平台的文件全路径 a/b/c/d.txt |
4、测试请求示例
curl -k --location --request GET 'https://xxx.xxx.com/regression/restapi/-/raw/a/b/c/d.txt ?inline=false'
5、返回结果
文件具体内容
3、提交新的文件
1、请求URL
https://xxx.xxx.com/api/v4/projcts/{projectId}/repository/files/{fileName}
2、请求方式
POST
3、请求参数
请求参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
projectId | true | String | 当前项目编号 |
fileName | true | String | 需要存储的git目录 |
branch | true | String | 所需提交的分支 |
author_email | true | String | 提交人邮箱 |
author_name | true | String | 提交人名称 |
content | true | String | 文件内容 |
commit_message | true | String | 提交描述 |
4、测试请求示例
curl -k --location --request POST 'https://xxx.xxx.com/api/v4/projects/280/repository/files/readme12?branch=master&author_email=ffeng@qq.com&author_name=ffeng&content=xxxyyy&commit_message=createfile' \
--header 'PRIVATE-TOKEN: xxxxxxxxxxxxxx'
4、更新文件内容
1、请求URL
https://xxx.xxx.com/api/v4/projcts/{projectId}/repository/files/{fileName}
2、请求方式
PUT
3、请求参数
请求参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
projectId | true | String | 当前项目编号 |
fileName | true | String | 需要存储的git目录 |
branch | true | String | 所需提交的分支 |
author_email | true | String | 提交人邮箱 |
author_name | true | String | 提交人名称 |
content | true | String | 文件内容 |
commit_message | true | String | 提交描述 |
4、测试请求示例
**TIP:**文件路径必须存在,否则报错
curl -k --location --request PUT 'https://xxx.xxx.com/api/v4/projects/280/repository/files/readme12?branch=master&author_email=ffeng@qq.com&author_name=ffeng&content=xxxyyy&commit_message=createfile' \
--header 'PRIVATE-TOKEN: xxxxxxxxxxxxxxx'
5、删除文件
1、请求URL
https://xxx.xxx.com/api/v4/projcts/{projectId}/repository/files/{fileName}
2、请求方式
DELETE
3、请求参数
请求参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
projectId | true | String | 当前项目编号 |
fileName | true | String | 需要存储的git目录 |
branch | true | String | 所需提交的分支 |
author_email | true | String | 提交人邮箱 |
author_name | true | String | 提交人名称 |
commit_message | true | String | 提交描述 |
4、测试请求示例
**TIP:**文件路径必须存在,否则报错
curl -k --location --request DELETE 'https://xxx.xxx.com/api/v4/projects/280/repository/files/readme12?branch=master&author_email=ffeng@qq.com&author_name=ffeng&commit_message=createfile' \
--header 'PRIVATE-TOKEN: xxxxxxxxxxxxxxxxx'