We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the new Branches, Collaborators, Commits, Deploy Keys, Deployments, GitHub Pages, Releases, Metrics, Webhooks REST API pages.
部署分支策略
使用 REST API 管理自定义部署分支策略。
关于部署分支策略
可以使用 REST API 指定分支必须匹配才能部署到环境的自定义名称模式。 环境的 deployment_branch_policy.custom_branch_policies
属性必须设置为 true
才能使用这些终结点。 若要更新环境的 deployment_branch_policy
,请参阅“创建或更新环境”。
有关将环境部署限制为某些分支的详细信息,请参阅“使用环境进行部署”。
List deployment branch policies
Lists the deployment branch policies for an environment.
Anyone with read access to the repository can use this endpoint. If the repository is private, you must use an access token with the repo
scope. GitHub Apps must have the actions:read
permission to use this endpoint.
参数
标头 |
---|
名称, 类型, 说明 |
accept stringSetting to |
路径参数 |
名称, 类型, 说明 |
owner string必须The account owner of the repository. The name is not case sensitive. |
repo string必须The name of the repository. The name is not case sensitive. |
environment_name string必须The name of the environment. |
查询参数 |
名称, 类型, 说明 |
per_page integerThe number of results per page (max 100). 默认: |
page integerPage number of the results to fetch. 默认: |
HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
代码示例
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies
Response
Status: 200
{
"total_count": 2,
"branch_policies": [
{
"id": 361471,
"node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjE0NzE=",
"name": "release/*"
},
{
"id": 361472,
"node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjE0NzI=",
"name": "main"
}
]
}
Create a deployment branch policy
Creates a deployment branch policy for an environment.
You must authenticate using an access token with the repo
scope to use this endpoint. GitHub Apps must have the administration:write
permission for the repository to use this endpoint.
参数
标头 |
---|
名称, 类型, 说明 |
accept stringSetting to |
路径参数 |
名称, 类型, 说明 |
owner string必须The account owner of the repository. The name is not case sensitive. |
repo string必须The name of the repository. The name is not case sensitive. |
environment_name string必须The name of the environment. |
正文参数 |
名称, 类型, 说明 |
name string必须The name pattern that branches must match in order to deploy to the environment. Wildcard characters will not match |
HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
303 | Response if the same branch name pattern already exists |
404 | Not Found or |
代码示例
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies \
-d '{"name":"release/*"}'
Response
Status: 200
{
"id": 364662,
"node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjQ2NjI=",
"name": "release/*"
}
Get a deployment branch policy
Gets a deployment branch policy for an environment.
Anyone with read access to the repository can use this endpoint. If the repository is private, you must use an access token with the repo
scope. GitHub Apps must have the actions:read
permission to use this endpoint.
参数
标头 |
---|
名称, 类型, 说明 |
accept stringSetting to |
路径参数 |
名称, 类型, 说明 |
owner string必须The account owner of the repository. The name is not case sensitive. |
repo string必须The name of the repository. The name is not case sensitive. |
environment_name string必须The name of the environment. |
branch_policy_id integer必须The unique identifier of the branch policy. |
HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
代码示例
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID
Response
Status: 200
{
"id": 364662,
"node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjQ2NjI=",
"name": "release/*"
}
Update a deployment branch policy
Updates a deployment branch policy for an environment.
You must authenticate using an access token with the repo
scope to use this endpoint. GitHub Apps must have the administration:write
permission for the repository to use this endpoint.
参数
标头 |
---|
名称, 类型, 说明 |
accept stringSetting to |
路径参数 |
名称, 类型, 说明 |
owner string必须The account owner of the repository. The name is not case sensitive. |
repo string必须The name of the repository. The name is not case sensitive. |
environment_name string必须The name of the environment. |
branch_policy_id integer必须The unique identifier of the branch policy. |
正文参数 |
名称, 类型, 说明 |
name string必须The name pattern that branches must match in order to deploy to the environment. Wildcard characters will not match |
HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
代码示例
curl \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID \
-d '{"name":"release/*"}'
Response
Status: 200
{
"id": 364662,
"node_id": "MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjQ2NjI=",
"name": "release/*"
}
Delete a deployment branch policy
Deletes a deployment branch policy for an environment.
You must authenticate using an access token with the repo
scope to use this endpoint. GitHub Apps must have the administration:write
permission for the repository to use this endpoint.
参数
标头 |
---|
名称, 类型, 说明 |
accept stringSetting to |
路径参数 |
名称, 类型, 说明 |
owner string必须The account owner of the repository. The name is not case sensitive. |
repo string必须The name of the repository. The name is not case sensitive. |
environment_name string必须The name of the environment. |
branch_policy_id integer必须The unique identifier of the branch policy. |
HTTP 响应状态代码
状态代码 | 说明 |
---|---|
204 | No Content |
代码示例
curl \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies/BRANCH_POLICY_ID
Response
Status: 204