CreateFile - 创建文件

更新时间:
复制 MD 格式

通过 OpenAPI 创建代码库文件。

适用版本

中心版、Region版

服务接入点与授权信息

产品

资源

所需权限

代码管理

文件

读写

请求语法

中心版

POST https://{domain}/oapi/v1/codeup/organizations/{organizationId}/repositories/{repositoryId}/files

Region版

POST https://{domain}/oapi/v1/codeup/repositories/{repositoryId}/files

请求头

参数

类型

是否必填

描述

示例值

x-yunxiao-token

string

是

个人访问令牌。

pt-0fh3****0fbG_35af****0484

请求参数

参数

类型

位置

是否必填

描述

示例值

organizationId

string

path

  • 是:中心版

  • 否:Region版

组织 ID。

60d54f3daccf2bbd6659f3ad

repositoryId

string

path

是

代码库 ID 或者 URL-Encoder 编码的全路径。

2813489或者60de7a6852743a5162b5f957%2FDemoRepo

-

object

body

否

branch

string

body

是

分支名称。

demo-branch

commitMessage

string

body

是

提交信息,非空,不超过102400个字符。

create a file with content

content

string

body

是

文件内容。

file content

encoding

string

body

是

编码规则,可选值{text, base64},默认为 text。

text

filePath

string

body

是

文件路径,非空,一般不要使用包含特殊符号的文件路路径。

src/test/main.java

请求示例

中心版

curl -X 'POST' \
  'https://{domain}/oapi/v1/codeup/organizations/60d54f3daccf2bbd6659f3ad/repositories/2813489或者60de7a6852743a5162b5f957%2FDemoRepo/files' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484' \
  --data '
    {
        "branch": "demo-branch",
        "commitMessage": "create a file with content",
        "content": "file content",
        "encoding": "text",
        "filePath": "src/test/main.java"
    }'

Region版

curl -X 'POST' \
  'https://{domain}/oapi/v1/codeup/repositories/2813489或者60de7a6852743a5162b5f957%2FDemoRepo/files' \
  -H 'Content-Type: application/json' \
  -H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484' \
  --data '
    {
        "branch": "demo-branch",
        "commitMessage": "create a file with content",
        "content": "file content",
        "encoding": "text",
        "filePath": "src/test/main.java"
    }'

返回参数

参数

类型

描述

示例值

-

object

branch

string

分支名称。

master

filePath

string

文件路径。

src/test/main.java

返回示例

{
    "branch": "master",
    "filePath": "src/test/main.java"
}

错误码

访问错误码中心查看 API 相关错误码。