用于部署状态的 REST API 端点
使用 REST API 管理部署状态。
列出部署状态
拥有拉取访问权限的用户可以查看部署的部署状态
“列出部署状态”的细粒度访问令牌
此端点可以使用以下细粒度令牌类型:
细粒度令牌必须具有以下权限集
- “部署”代码仓库权限(读取)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。
“列出部署状态”的参数
名称,类型,描述 |
---|
accept 字符串建议设置为 |
名称,类型,描述 |
---|
owner 字符串 必填代码仓库的账户所有者。名称不区分大小写。 |
repo 字符串 必填不包含 |
deployment_id 整数 必填deployment_id 参数 |
名称,类型,描述 |
---|
per_page 整数每页结果数(最大 100)。更多信息,请参见“REST API 中的使用分页”。 默认值: |
page 整数要获取的结果的页码。更多信息,请参见“REST API 中的使用分页”。 默认值: |
“列出部署状态”的 HTTP 响应状态码
状态码 | 描述 |
---|---|
200 | 成功 |
404 | 资源未找到 |
“列出部署状态”的代码示例
请求示例
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 字符串建议设置为 |
名称,类型,描述 |
---|
owner 字符串 必填代码仓库的账户所有者。名称不区分大小写。 |
repo 字符串 必填不包含 |
deployment_id 整数 必填deployment_id 参数 |
名称,类型,描述 |
---|
state 字符串 必填状态的状态。当您将短暂部署设置为 可以是以下之一: |
target_url 字符串与该状态关联的目标 URL。此 URL 应包含输出,以便在任务运行期间随时更新用户,或者用作部署过程中发生情况的历史信息。 注意 建议使用 默认值: |
log_url 字符串部署输出的完整 URL。此参数替换 默认值: |
description 字符串状态的简短描述。最大描述长度为 140 个字符。 默认值: |
environment 字符串目标部署环境的名称,在设置部署状态时可以更改。例如, |
environment_url 字符串设置用于访问您的环境的 URL。默认值: 默认值: |
auto_inactive 布尔值为所有先前非瞬态、非生产环境的部署添加新的 |
“创建部署状态”的 HTTP 响应状态代码
状态码 | 描述 |
---|---|
201 | 已创建 |
422 | 验证失败,或端点已被滥用。 |
“创建部署状态”的代码示例
请求示例
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 字符串建议设置为 |
名称,类型,描述 |
---|
owner 字符串 必填代码仓库的账户所有者。名称不区分大小写。 |
repo 字符串 必填不包含 |
deployment_id 整数 必填deployment_id 参数 |
status_id 整数 必填 |
“获取部署状态”的 HTTP 响应状态代码
状态码 | 描述 |
---|---|
200 | 成功 |
404 | 资源未找到 |
“获取部署状态”的代码示例
请求示例
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" }