适用于部署状态的 REST API 终结点
使用 REST API 管理部署状态。
List deployment statuses
Users with pull access can view deployment statuses for a deployment:
“List deployment statuses”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须具有以下权限集:
- "Deployments" repository permissions (read)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此终结点。
“List deployment statuses”的参数
| 名称, 类型, 说明 | 
|---|
| acceptstringSetting to  | 
| 名称, 类型, 说明 | 
|---|
| ownerstring 必须The account owner of the repository. The name is not case sensitive. | 
| repostring 必须The name of the repository without the  | 
| deployment_idinteger 必须deployment_id parameter | 
| 名称, 类型, 说明 | 
|---|
| per_pageintegerThe number of results per page (max 100). For more information, see "Using pagination in the REST API." 默认:  | 
| pageintegerThe page number of the results to fetch. For more information, see "Using pagination in the REST API." 默认:  | 
“List deployment statuses”的 HTTP 响应状态代码
| 状态代码 | 说明 | 
|---|---|
| 200 | OK | 
| 404 | Resource not found | 
“List deployment statuses”的示例代码
请求示例
curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/deployments/DEPLOYMENT_ID/statusesResponse
Status: 200[
  {
    "url": "http://HOSTNAME/repos/octocat/example/deployments/42/statuses/1",
    "id": 1,
    "node_id": "MDE2OkRlcGxveW1lbnRTdGF0dXMx",
    "state": "success",
    "creator": {
      "login": "octocat",
      "id": 1,
      "node_id": "MDQ6VXNlcjE=",
      "avatar_url": "http://github.com/images/error/octocat_happy.gif",
      "gravatar_id": "",
      "url": "http://HOSTNAME/users/octocat",
      "html_url": "http://github.com/octocat",
      "followers_url": "http://HOSTNAME/users/octocat/followers",
      "following_url": "http://HOSTNAME/users/octocat/following{/other_user}",
      "gists_url": "http://HOSTNAME/users/octocat/gists{/gist_id}",
      "starred_url": "http://HOSTNAME/users/octocat/starred{/owner}{/repo}",
      "subscriptions_url": "http://HOSTNAME/users/octocat/subscriptions",
      "organizations_url": "http://HOSTNAME/users/octocat/orgs",
      "repos_url": "http://HOSTNAME/users/octocat/repos",
      "events_url": "http://HOSTNAME/users/octocat/events{/privacy}",
      "received_events_url": "http://HOSTNAME/users/octocat/received_events",
      "type": "User",
      "site_admin": false
    },
    "description": "Deployment finished successfully.",
    "environment": "production",
    "target_url": "http://example.com/deployment/42/output",
    "created_at": "2012-07-20T01:19:13Z",
    "updated_at": "2012-07-20T01:19:13Z",
    "deployment_url": "http://HOSTNAME/repos/octocat/example/deployments/42",
    "repository_url": "http://HOSTNAME/repos/octocat/example",
    "environment_url": "http://test-branch.lab.acme.com",
    "log_url": "http://example.com/deployment/42/output"
  }
]Create a deployment status
Users with push access can create deployment statuses for a given deployment.
OAuth app tokens and personal access tokens (classic) need the repo_deployment scope to use this endpoint.
“Create a deployment status”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须具有以下权限集:
- "Deployments" repository permissions (write)
“Create a deployment status”的参数
| 名称, 类型, 说明 | 
|---|
| acceptstringSetting to  | 
| 名称, 类型, 说明 | 
|---|
| ownerstring 必须The account owner of the repository. The name is not case sensitive. | 
| repostring 必须The name of the repository without the  | 
| deployment_idinteger 必须deployment_id parameter | 
| 名称, 类型, 说明 | 
|---|
| statestring 必须The state of the status. When you set a transient deployment to  可以是以下选项之一:  | 
| target_urlstringThe target URL to associate with this status. This URL should contain output to keep the user updated while the task is running or serve as historical information for what happened in the deployment. Note 
It's recommended to use the  默认:  | 
| log_urlstringThe full URL of the deployment's output. This parameter replaces  默认:  | 
| descriptionstringA short description of the status. The maximum description length is 140 characters. 默认:  | 
| environmentstringName for the target deployment environment, which can be changed when setting a deploy status. For example,  | 
| environment_urlstringSets the URL for accessing your environment. Default:  默认:  | 
| auto_inactivebooleanAdds a new  | 
“Create a deployment status”的 HTTP 响应状态代码
| 状态代码 | 说明 | 
|---|---|
| 201 | Created | 
| 422 | Validation failed, or the endpoint has been spammed. | 
“Create a deployment status”的示例代码
请求示例
curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/deployments/DEPLOYMENT_ID/statuses \
  -d '{"environment":"production","state":"success","log_url":"http://example.com/deployment/42/output","description":"Deployment finished successfully."}'Response
Status: 201{
  "url": "http://HOSTNAME/repos/octocat/example/deployments/42/statuses/1",
  "id": 1,
  "node_id": "MDE2OkRlcGxveW1lbnRTdGF0dXMx",
  "state": "success",
  "creator": {
    "login": "octocat",
    "id": 1,
    "node_id": "MDQ6VXNlcjE=",
    "avatar_url": "http://github.com/images/error/octocat_happy.gif",
    "gravatar_id": "",
    "url": "http://HOSTNAME/users/octocat",
    "html_url": "http://github.com/octocat",
    "followers_url": "http://HOSTNAME/users/octocat/followers",
    "following_url": "http://HOSTNAME/users/octocat/following{/other_user}",
    "gists_url": "http://HOSTNAME/users/octocat/gists{/gist_id}",
    "starred_url": "http://HOSTNAME/users/octocat/starred{/owner}{/repo}",
    "subscriptions_url": "http://HOSTNAME/users/octocat/subscriptions",
    "organizations_url": "http://HOSTNAME/users/octocat/orgs",
    "repos_url": "http://HOSTNAME/users/octocat/repos",
    "events_url": "http://HOSTNAME/users/octocat/events{/privacy}",
    "received_events_url": "http://HOSTNAME/users/octocat/received_events",
    "type": "User",
    "site_admin": false
  },
  "description": "Deployment finished successfully.",
  "environment": "production",
  "target_url": "http://example.com/deployment/42/output",
  "created_at": "2012-07-20T01:19:13Z",
  "updated_at": "2012-07-20T01:19:13Z",
  "deployment_url": "http://HOSTNAME/repos/octocat/example/deployments/42",
  "repository_url": "http://HOSTNAME/repos/octocat/example",
  "environment_url": "http://test-branch.lab.acme.com",
  "log_url": "http://example.com/deployment/42/output"
}Get a deployment status
Users with pull access can view a deployment status for a deployment:
“Get a deployment status”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须具有以下权限集:
- "Deployments" repository permissions (read)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此终结点。
“Get a deployment status”的参数
| 名称, 类型, 说明 | 
|---|
| acceptstringSetting to  | 
| 名称, 类型, 说明 | 
|---|
| ownerstring 必须The account owner of the repository. The name is not case sensitive. | 
| repostring 必须The name of the repository without the  | 
| deployment_idinteger 必须deployment_id parameter | 
| status_idinteger 必须 | 
“Get a deployment status”的 HTTP 响应状态代码
| 状态代码 | 说明 | 
|---|---|
| 200 | OK | 
| 404 | Resource not found | 
“Get a deployment status”的示例代码
请求示例
curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/deployments/DEPLOYMENT_ID/statuses/STATUS_IDResponse
Status: 200{
  "url": "http://HOSTNAME/repos/octocat/example/deployments/42/statuses/1",
  "id": 1,
  "node_id": "MDE2OkRlcGxveW1lbnRTdGF0dXMx",
  "state": "success",
  "creator": {
    "login": "octocat",
    "id": 1,
    "node_id": "MDQ6VXNlcjE=",
    "avatar_url": "http://github.com/images/error/octocat_happy.gif",
    "gravatar_id": "",
    "url": "http://HOSTNAME/users/octocat",
    "html_url": "http://github.com/octocat",
    "followers_url": "http://HOSTNAME/users/octocat/followers",
    "following_url": "http://HOSTNAME/users/octocat/following{/other_user}",
    "gists_url": "http://HOSTNAME/users/octocat/gists{/gist_id}",
    "starred_url": "http://HOSTNAME/users/octocat/starred{/owner}{/repo}",
    "subscriptions_url": "http://HOSTNAME/users/octocat/subscriptions",
    "organizations_url": "http://HOSTNAME/users/octocat/orgs",
    "repos_url": "http://HOSTNAME/users/octocat/repos",
    "events_url": "http://HOSTNAME/users/octocat/events{/privacy}",
    "received_events_url": "http://HOSTNAME/users/octocat/received_events",
    "type": "User",
    "site_admin": false
  },
  "description": "Deployment finished successfully.",
  "environment": "production",
  "target_url": "http://example.com/deployment/42/output",
  "created_at": "2012-07-20T01:19:13Z",
  "updated_at": "2012-07-20T01:19:13Z",
  "deployment_url": "http://HOSTNAME/repos/octocat/example/deployments/42",
  "repository_url": "http://HOSTNAME/repos/octocat/example",
  "environment_url": "http://test-branch.lab.acme.com",
  "log_url": "http://example.com/deployment/42/output"
}