跳到主要内容
REST API 现在已版本化。 更多信息,请参见“关于 API 版本控制”。

用于部署状态的 REST API 端点

使用 REST API 管理部署状态。

列出部署状态

拥有拉取访问权限的用户可以查看部署的部署状态

“列出部署状态”的细粒度访问令牌

此端点可以使用以下细粒度令牌类型:

细粒度令牌必须具有以下权限集

  • “部署”代码仓库权限(读取)

如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。

“列出部署状态”的参数

请求头
名称,类型,描述
accept 字符串

建议设置为application/vnd.github+json

路径参数
名称,类型,描述
owner 字符串 必填

代码仓库的账户所有者。名称不区分大小写。

repo 字符串 必填

不包含.git扩展名的代码仓库名称。名称不区分大小写。

deployment_id 整数 必填

deployment_id 参数

查询参数
名称,类型,描述
per_page 整数

每页结果数(最大 100)。更多信息,请参见“REST API 中的使用分页”。

默认值: 30

page 整数

要获取的结果的页码。更多信息,请参见“REST API 中的使用分页”。

默认值: 1

“列出部署状态”的 HTTP 响应状态码

状态码描述
200

成功

404

资源未找到

“列出部署状态”的代码示例

请求示例

get/repos/{owner}/{repo}/deployments/{deployment_id}/statuses
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/deployments/DEPLOYMENT_ID/statuses

响应

状态:200
[ { "url": "https://api.github.com/repos/octocat/example/deployments/42/statuses/1", "id": 1, "node_id": "MDE2OkRlcGxveW1lbnRTdGF0dXMx", "state": "success", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "description": "部署成功完成。", "environment": "production", "target_url": "https://example.com/deployment/42/output", "created_at": "2012-07-20T01:19:13Z", "updated_at": "2012-07-20T01:19:13Z", "deployment_url": "https://api.github.com/repos/octocat/example/deployments/42", "repository_url": "https://api.github.com/repos/octocat/example", "environment_url": "https://test-branch.lab.acme.com", "log_url": "https://example.com/deployment/42/output" } ]

创建部署状态

拥有推送访问权限的用户可以为给定的部署创建部署状态。

OAuth 应用令牌和个人访问令牌(经典)需要repo_deployment作用域才能使用此端点。

“创建部署状态”的细粒度访问令牌

此端点可以使用以下细粒度令牌类型:

细粒度令牌必须具有以下权限集

  • “部署”代码仓库权限(写入)

“创建部署状态”的参数

请求头
名称,类型,描述
accept 字符串

建议设置为application/vnd.github+json

路径参数
名称,类型,描述
owner 字符串 必填

代码仓库的账户所有者。名称不区分大小写。

repo 字符串 必填

不包含.git扩展名的代码仓库名称。名称不区分大小写。

deployment_id 整数 必填

deployment_id 参数

正文参数
名称,类型,描述
state 字符串 必填

状态的状态。当您将短暂部署设置为inactive时,部署将在 GitHub 中显示为destroyed

可以是以下之一:errorfailureinactivein_progressqueuedpendingsuccess

target_url 字符串

与该状态关联的目标 URL。此 URL 应包含输出,以便在任务运行期间随时更新用户,或者用作部署过程中发生情况的历史信息。

注意

建议使用log_url参数,它替换了target_url

默认值: ""

log_url 字符串

部署输出的完整 URL。此参数替换target_url。我们将继续接受target_url以支持旧版用法,但我们建议将target_url替换为log_url。设置log_url将自动将target_url设置为相同的值。默认值:""

默认值: ""

description 字符串

状态的简短描述。最大描述长度为 140 个字符。

默认值: ""

environment 字符串

目标部署环境的名称,在设置部署状态时可以更改。例如,productionstagingqa。如果未定义,则将使用部署上先前状态的环境(如果存在)。否则,将使用部署的环境。

environment_url 字符串

设置用于访问您的环境的 URL。默认值:""

默认值: ""

auto_inactive 布尔值

为所有先前非瞬态、非生产环境的部署添加新的inactive状态,这些部署与创建的状态的部署具有相同的代码库和environment名称。只有具有success状态的部署才会添加inactive状态。默认值:true

“创建部署状态”的 HTTP 响应状态代码

状态码描述
201

已创建

422

验证失败,或端点已被滥用。

“创建部署状态”的代码示例

请求示例

post/repos/{owner}/{repo}/deployments/{deployment_id}/statuses
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/deployments/DEPLOYMENT_ID/statuses \ -d '{"environment":"production","state":"success","log_url":"https://example.com/deployment/42/output","description":"Deployment finished successfully."}'

响应

状态:201
{ "url": "https://api.github.com/repos/octocat/example/deployments/42/statuses/1", "id": 1, "node_id": "MDE2OkRlcGxveW1lbnRTdGF0dXMx", "state": "success", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "description": "Deployment finished successfully.", "environment": "production", "target_url": "https://example.com/deployment/42/output", "created_at": "2012-07-20T01:19:13Z", "updated_at": "2012-07-20T01:19:13Z", "deployment_url": "https://api.github.com/repos/octocat/example/deployments/42", "repository_url": "https://api.github.com/repos/octocat/example", "environment_url": "https://test-branch.lab.acme.com", "log_url": "https://example.com/deployment/42/output" }

获取部署状态

拥有拉取访问权限的用户可以查看部署的状态。

“获取部署状态”的细粒度访问令牌

此端点可以使用以下细粒度令牌类型:

细粒度令牌必须具有以下权限集

  • “部署”代码仓库权限(读取)

如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。

“获取部署状态”的参数

请求头
名称,类型,描述
accept 字符串

建议设置为application/vnd.github+json

路径参数
名称,类型,描述
owner 字符串 必填

代码仓库的账户所有者。名称不区分大小写。

repo 字符串 必填

不包含.git扩展名的代码仓库名称。名称不区分大小写。

deployment_id 整数 必填

deployment_id 参数

status_id 整数 必填

“获取部署状态”的 HTTP 响应状态代码

状态码描述
200

成功

404

资源未找到

“获取部署状态”的代码示例

请求示例

get/repos/{owner}/{repo}/deployments/{deployment_id}/statuses/{status_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/deployments/DEPLOYMENT_ID/statuses/STATUS_ID

响应

状态:200
{ "url": "https://api.github.com/repos/octocat/example/deployments/42/statuses/1", "id": 1, "node_id": "MDE2OkRlcGxveW1lbnRTdGF0dXMx", "state": "success", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "description": "Deployment finished successfully.", "environment": "production", "target_url": "https://example.com/deployment/42/output", "created_at": "2012-07-20T01:19:13Z", "updated_at": "2012-07-20T01:19:13Z", "deployment_url": "https://api.github.com/repos/octocat/example/deployments/42", "repository_url": "https://api.github.com/repos/octocat/example", "environment_url": "https://test-branch.lab.acme.com", "log_url": "https://example.com/deployment/42/output" }