跳至主要内容
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

OK

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": "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" } ]

创建部署状态

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

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

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

此端点适用于以下细粒度令牌类型

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

  • “部署”存储库权限(写入)

“创建部署状态”的参数

标头
名称、类型、描述
accept 字符串

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

路径参数
名称、类型、描述
owner 字符串 必需

存储库的帐户所有者。名称不区分大小写。

repo 字符串 必需

不带 .git 扩展名的存储库名称。名称不区分大小写。

deployment_id 整数 必需

deployment_id 参数

正文参数
名称、类型、描述
state string 必需

状态的状态。将瞬态部署设置为 inactive 时,该部署将在 GitHub 中显示为 destroyed

可以是以下之一: error, failure, inactive, in_progress, queued, pending, success

target_url string

与此状态关联的目标 URL。此 URL 应包含输出,以便在任务运行时让用户保持更新,或作为部署中发生事件的历史信息。注意:建议使用 log_url 参数,它取代了 target_url

默认: ""

log_url string

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

默认: ""

description string

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

默认: ""

environment string

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

environment_url string

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

默认: ""

auto_inactive boolean

向所有先前非瞬态、非生产环境部署添加新的 inactive 状态,这些部署与创建状态的部署具有相同的存储库和 environment 名称。inactive 状态仅添加到具有 success 状态的部署。默认值: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 integer Required

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

状态代码说明
200

OK

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" }