部署是部署特定引用(分支、SHA、标记)的请求。 GitHub 分发一个 deployment 事件,使外部服务可以在创建新部署时侦听并采取行动。 部署使开发者和组织能够围绕部署构建松散耦合的工具,而不必担心交付不同类型的应用程序(例如 Web 和本地应用程序)的实现细节。
部署状态允许外部服务将部署标记为 error、failure、pending、in_progress、queued 或 success 状态,以供侦听 deployment_status 事件的系统使用。
部署状态还可以包含可选的 description 和 log_url,强烈建议使用它们,因为它们使部署状态更有用。 log_url 是部署输出的完整 URL,description 是关于部署过程中所发生情况的高级摘要。
在创建新的部署和部署状态时,GitHub 将分发 deployment 和 deployment_status 事件。 这些事件允许第三方集成接收对部署请求的响应,并在取得进展时更新部署的状态。
下面是一个说明这些交互的工作方式的简单序列图。
+---------+ +--------+ +-----------+ +-------------+
| Tooling | | GitHub | | 3rd Party | | Your Server |
+---------+ +--------+ +-----------+ +-------------+
| | | |
| Create Deployment | | |
|--------------------->| | |
| | | |
| Deployment Created | | |
|<---------------------| | |
| | | |
| | Deployment Event | |
| |---------------------->| |
| | | SSH+Deploys |
| | |-------------------->|
| | | |
| | Deployment Status | |
| |<----------------------| |
| | | |
| | | Deploy Completed |
| | |<--------------------|
| | | |
| | Deployment Status | |
| |<----------------------| |
| | | |
请记住,GitHub 从未真正访问过您的服务器。 与部署事件的交互取决于第三方集成。 多个系统可以侦听部署事件,由其中每个系统来决定它们是否负责将代码推送到服务器、构建本地代码等。
请注意,repo_deployment OAuth 作用域授予对部署和部署状态的定向访问权限,但不授予对仓库代码的访问权限,而 public_repo 和repo 作用域还授予对代码的权限。
非活动部署
当您将部署状态设置为 success 时,同一仓库中所有先前的非瞬态、非生产环境部署将变成 inactive。 为避免这种情况,您可以在创建部署状态时将 auto_inactive 设置为 false。
您可以通过将 state 设为 inactive 来表示某个瞬态环境不再存在。 将 state 设为 inactive,表示部署在 GitHub 中 destroyed 并删除对它的访问权限。
List deployments
Simple filtering of deployments is available via query parameters:
get /repos/{owner}/{repo}/deployments参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
sha | string | query | The SHA recorded at creation time. 默认值: |
ref | string | query | The name of the ref. This can be a branch, tag, or SHA. 默认值: |
task | string | query | The name of the task for the deployment (e.g., 默认值: |
environment | string | query | The name of the environment that was deployed to (e.g., 默认值: |
per_page | integer | query | Results per page (max 100) 默认值: |
page | integer | query | Page number of the results to fetch. 默认值: |
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/deploymentsJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/deployments', {
owner: 'octocat',
repo: 'hello-world'
})Response
Status: 200 OK [
{
"url": "https://api.github.com/repos/octocat/example/deployments/1",
"id": 1,
"node_id": "MDEwOkRlcGxveW1lbnQx",
"sha": "a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d",
"ref": "topic-branch",
"task": "deploy",
"payload": {},
"original_environment": "staging",
"environment": "production",
"description": "Deploy request from hubot",
"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
},
"created_at": "2012-07-20T01:19:13Z",
"updated_at": "2012-07-20T01:19:13Z",
"statuses_url": "https://api.github.com/repos/octocat/example/deployments/1/statuses",
"repository_url": "https://api.github.com/repos/octocat/example",
"transient_environment": false,
"production_environment": true
}
]注:
Create a deployment
Deployments offer a few configurable parameters with certain defaults.
The ref parameter can be any named branch, tag, or SHA. At GitHub we often deploy branches and verify them
before we merge a pull request.
The environment parameter allows deployments to be issued to different runtime environments. Teams often have
multiple environments for verifying their applications, such as production, staging, and qa. This parameter
makes it easier to track which environments have requested deployments. The default environment is production.
The auto_merge parameter is used to ensure that the requested ref is not behind the repository's default branch. If
the ref is behind the default branch for the repository, we will attempt to merge it for you. If the merge succeeds,
the API will return a successful merge commit. If merge conflicts prevent the merge from succeeding, the API will
return a failure response.
By default, commit statuses for every submitted context must be in a success
state. The required_contexts parameter allows you to specify a subset of contexts that must be success, or to
specify contexts that have not yet been submitted. You are not required to use commit statuses to deploy. If you do
not require any contexts or create any commit statuses, the deployment will always succeed.
The payload parameter is available for any extra information that a deployment system might need. It is a JSON text
field that will be passed on when a deployment event is dispatched.
The task parameter is used by the deployment system to allow different execution paths. In the web world this might
be deploy:migrations to run schema changes on the system. In the compiled world this could be a flag to compile an
application with debugging enabled.
Users with repo or repo_deployment scopes can create a deployment for a given ref.
Merged branch response
You will see this response when GitHub automatically merges the base branch into the topic branch instead of creating a deployment. This auto-merge happens when:
- Auto-merge option is enabled in the repository
- Topic branch does not include the latest changes on the base branch, which is
masterin the response example - There are no merge conflicts
If there are no new commits in the base branch, a new request to create a deployment should give a successful response.
Merge conflict response
This error happens when the auto_merge option is enabled and when the default branch (in this case master), can't
be merged into the branch that's being deployed (in this case topic-branch), due to merge conflicts.
Failed commit status checks
This error happens when the required_contexts parameter indicates that one or more contexts need to have a success
status for the commit to be deployed, but one or more of the required contexts do not have a state of success.
post /repos/{owner}/{repo}/deployments参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
ref | string | body | Required. The ref to deploy. This can be a branch, tag, or SHA. |
task | string | body | Specifies a task to execute (e.g., 默认值: |
auto_merge | boolean | body | Attempts to automatically merge the default branch into the requested ref, if it's behind the default branch. 默认值: |
required_contexts | array of strings | body | The status contexts to verify against commit status checks. If you omit this parameter, GitHub verifies all unique contexts before creating a deployment. To bypass checking entirely, pass an empty array. Defaults to all unique contexts. |
payload | object or string or | body | JSON payload with extra information about the deployment. |
environment | string | body | Name for the target deployment environment (e.g., 默认值: |
description | string or null | body | Short description of the deployment. |
transient_environment | boolean | body | Specifies if the given environment is specific to the deployment and will no longer exist at some point in the future. Default: |
production_environment | boolean | body | Specifies if the given environment is one that end-users directly interact with. Default: |
代码示例
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/deployments \
-d '{"ref":"ref"}'JavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/deployments', {
owner: 'octocat',
repo: 'hello-world',
ref: 'ref'
})Simple example
Status: 201 Created {
"url": "https://api.github.com/repos/octocat/example/deployments/1",
"id": 1,
"node_id": "MDEwOkRlcGxveW1lbnQx",
"sha": "a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d",
"ref": "topic-branch",
"task": "deploy",
"payload": {},
"original_environment": "staging",
"environment": "production",
"description": "Deploy request from hubot",
"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
},
"created_at": "2012-07-20T01:19:13Z",
"updated_at": "2012-07-20T01:19:13Z",
"statuses_url": "https://api.github.com/repos/octocat/example/deployments/1/statuses",
"repository_url": "https://api.github.com/repos/octocat/example",
"transient_environment": false,
"production_environment": true
}Merged branch response
Status: 202 Accepted {
"message": "Auto-merged master into topic-branch on deployment."
}Conflict when there is a merge conflict or the commit's status checks failed
Status: 409 ConflictValidation failed
Status: 422 Unprocessable Entity注:
Get a deployment
get /repos/{owner}/{repo}/deployments/{deployment_id}参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
deployment_id | integer | path | deployment_id parameter |
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/deployments/42JavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/deployments/{deployment_id}', {
owner: 'octocat',
repo: 'hello-world',
deployment_id: 42
})Response
Status: 200 OK {
"url": "https://api.github.com/repos/octocat/example/deployments/1",
"id": 1,
"node_id": "MDEwOkRlcGxveW1lbnQx",
"sha": "a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d",
"ref": "topic-branch",
"task": "deploy",
"payload": {},
"original_environment": "staging",
"environment": "production",
"description": "Deploy request from hubot",
"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
},
"created_at": "2012-07-20T01:19:13Z",
"updated_at": "2012-07-20T01:19:13Z",
"statuses_url": "https://api.github.com/repos/octocat/example/deployments/1/statuses",
"repository_url": "https://api.github.com/repos/octocat/example",
"transient_environment": false,
"production_environment": true
}Resource not found
Status: 404 Not Found注:
Delete a deployment
If the repository only has one deployment, you can delete the deployment regardless of its status. If the repository has more than one deployment, you can only delete inactive deployments. This ensures that repositories with multiple deployments will always have an active deployment. Anyone with repo or repo_deployment scopes can delete a deployment.
To set a deployment as inactive, you must:
- Create a new deployment that is active so that the system has a record of the current state, then delete the previously active deployment.
- Mark the active deployment as inactive by adding any non-successful deployment status.
For more information, see "Create a deployment" and "Create a deployment status."
delete /repos/{owner}/{repo}/deployments/{deployment_id}参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
deployment_id | integer | path | deployment_id parameter |
代码示例
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/deployments/42JavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/deployments/{deployment_id}', {
owner: 'octocat',
repo: 'hello-world',
deployment_id: 42
})Response
Status: 204 No ContentResource not found
Status: 404 Not FoundValidation failed
Status: 422 Unprocessable Entity注:
环境
环境 API 允许您创建、配置和删除环境。 有关环境的更多信息,请参阅“使用环境进行部署”。 要管理环境密码,请参阅“密码”。
所有产品的公共仓库提供环境、环境保护规则和环境机密。 For access to environments in private repositories, you must use GitHub Enterprise. 更多信息请参阅“GitHub 的产品”。
Get all environments
Get all environments for a repository.
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.
get /repos/{owner}/{repo}/environments参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path |
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/environmentsJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/environments', {
owner: 'octocat',
repo: 'hello-world'
})Response
Status: 200 OK {
"total_count": 1,
"environments": [
{
"id": 161088068,
"node_id": "MDExOkVudmlyb25tZW50MTYxMDg4MDY4",
"name": "staging",
"url": "https://api.github.com/repos/github/hello-world/environments/staging",
"html_url": "https://github.com/github/hello-world/deployments/activity_log?environments_filter=staging",
"created_at": "2020-11-23T22:00:40Z",
"updated_at": "2020-11-23T22:00:40Z",
"protection_rules": [
{
"id": 3736,
"node_id": "MDQ6R2F0ZTM3MzY=",
"type": "wait_timer",
"wait_timer": 30
},
{
"id": 3755,
"node_id": "MDQ6R2F0ZTM3NTU=",
"type": "required_reviewers",
"reviewers": [
{
"type": "User",
"reviewer": {
"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
}
},
{
"type": "Team",
"reviewer": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
}
]
},
{
"id": 3756,
"node_id": "MDQ6R2F0ZTM3NTY=",
"type": "branch_policy"
}
],
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": true
}
}
]
}注:
Get 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.
get /repos/{owner}/{repo}/environments/{environment_name}参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
environment_name | string | path | The name of the environment |
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/environments/ENVIRONMENT_NAMEJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/environments/{environment_name}', {
owner: 'octocat',
repo: 'hello-world',
environment_name: 'environment_name'
})Response
Status: 200 OK {
"id": 161088068,
"node_id": "MDExOkVudmlyb25tZW50MTYxMDg4MDY4",
"name": "staging",
"url": "https://api.github.com/repos/github/hello-world/environments/staging",
"html_url": "https://github.com/github/hello-world/deployments/activity_log?environments_filter=staging",
"created_at": "2020-11-23T22:00:40Z",
"updated_at": "2020-11-23T22:00:40Z",
"protection_rules": [
{
"id": 3736,
"node_id": "MDQ6R2F0ZTM3MzY=",
"type": "wait_timer",
"wait_timer": 30
},
{
"id": 3755,
"node_id": "MDQ6R2F0ZTM3NTU=",
"type": "required_reviewers",
"reviewers": [
{
"type": "User",
"reviewer": {
"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
}
},
{
"type": "Team",
"reviewer": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
}
]
},
{
"id": 3756,
"node_id": "MDQ6R2F0ZTM3NTY=",
"type": "branch_policy"
}
],
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": true
}
}注:
Create or update an environment
Create or update an environment with protection rules, such as required reviewers. For more information about environment protection rules, see "Environments."
Note: Although you can use this operation to specify that only branches that match specified name patterns can deploy to this environment, you must use the UI to set the name patterns. For more information, see "Environments."
Note: To create or update secrets for an environment, see "Secrets."
You must authenticate using an access token with the repo scope to use this endpoint.
put /repos/{owner}/{repo}/environments/{environment_name}参数
| 名称 | 类型 | In | 描述 | ||||||
|---|---|---|---|---|---|---|---|---|---|
accept | string | header | Setting to | ||||||
owner | string | path | |||||||
repo | string | path | |||||||
environment_name | string | path | The name of the environment | ||||||
wait_timer | integer | body | The amount of time to delay a job after the job is initially triggered. The time (in minutes) must be an integer between 0 and 43,200 (30 days). | ||||||
reviewers | array of objects or null | body | The people or teams that may review jobs that reference the environment. You can list up to six users or teams as reviewers. The reviewers must have at least read access to the repository. Only one of the required reviewers needs to approve the job for it to proceed. | ||||||
Properties of the | |||||||||
| 名称 (类型) | 描述 |
|---|---|
type (string) | The type of reviewer. Must be one of: |
id (integer) | The id of the user or team who can review the deployment |
deployment_branch_policyThe type of deployment branch policy for this environment. To allow all branches to deploy, set to null.
Properties of thedeployment_branch_policyobject
| 名称 (类型) | 描述 |
|---|---|
protected_branches (boolean) | Required. Whether only branches with branch protection rules can deploy to this environment. If |
custom_branch_policies (boolean) | Required. Whether only branches that match the specified name patterns can deploy to this environment. If |
代码示例
Shell
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/environments/ENVIRONMENT_NAME \
-d '{"wait_timer":42}'JavaScript (@octokit/core.js)
await octokit.request('PUT /repos/{owner}/{repo}/environments/{environment_name}', {
owner: 'octocat',
repo: 'hello-world',
environment_name: 'environment_name',
wait_timer: 42
})Response
Status: 200 OK {
"id": 161088068,
"node_id": "MDExOkVudmlyb25tZW50MTYxMDg4MDY4",
"name": "staging",
"url": "https://api.github.com/repos/github/hello-world/environments/staging",
"html_url": "https://github.com/github/hello-world/deployments/activity_log?environments_filter=staging",
"created_at": "2020-11-23T22:00:40Z",
"updated_at": "2020-11-23T22:00:40Z",
"protection_rules": [
{
"id": 3736,
"node_id": "MDQ6R2F0ZTM3MzY=",
"type": "wait_timer",
"wait_timer": 30
},
{
"id": 3755,
"node_id": "MDQ6R2F0ZTM3NTU=",
"type": "required_reviewers",
"reviewers": [
{
"type": "User",
"reviewer": {
"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
}
},
{
"type": "Team",
"reviewer": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
}
]
},
{
"id": 3756,
"node_id": "MDQ6R2F0ZTM3NTY=",
"type": "branch_policy"
}
],
"deployment_branch_policy": {
"protected_branches": false,
"custom_branch_policies": true
}
}Validation error when the environment name is invalid or when protected_branches and custom_branch_policies in deployment_branch_policy are set to the same value
Status: 422 Unprocessable Entity注:
Delete an environment
You must authenticate using an access token with the repo scope to use this endpoint.
delete /repos/{owner}/{repo}/environments/{environment_name}参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
environment_name | string | path | The name of the environment |
代码示例
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/environments/ENVIRONMENT_NAMEJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/environments/{environment_name}', {
owner: 'octocat',
repo: 'hello-world',
environment_name: 'environment_name'
})Default response
Status: 204 No Content注:
部署密钥
You can launch projects from a repository on GitHub.com to your server by using a deploy key, which is an SSH key that grants access to a single repository. GitHub 将密钥的公共部分直接附加到仓库而不是个人用户帐户,密钥的私有部分仍保留在服务器上。 更多信息请参阅“交付部署”。
部署密钥可以使用以下 API 端点进行设置,也可以使用 GitHub 进行设置。 要了解如何在 GitHub 中设置部署密钥,请参阅“管理部署密钥”。
List deploy keys
get /repos/{owner}/{repo}/keys参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
per_page | integer | query | Results per page (max 100) 默认值: |
page | integer | query | Page number of the results to fetch. 默认值: |
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/keysJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/keys', {
owner: 'octocat',
repo: 'hello-world'
})Response
Status: 200 OK [
{
"id": 1,
"key": "ssh-rsa AAA...",
"url": "https://api.github.com/repos/octocat/Hello-World/keys/1",
"title": "octocat@octomac",
"verified": true,
"created_at": "2014-12-10T15:53:42Z",
"read_only": true
}
]注:
Create a deploy key
You can create a read-only deploy key.
post /repos/{owner}/{repo}/keys参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
title | string | body | A name for the key. |
key | string | body | Required. The contents of the key. |
read_only | boolean | body | If Deploy keys with write access can perform the same actions as an organization member with admin access, or a collaborator on a personal repository. For more information, see "Repository permission levels for an organization" and "Permission levels for a user account repository." |
代码示例
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/keys \
-d '{"key":"key"}'JavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/keys', {
owner: 'octocat',
repo: 'hello-world',
key: 'key'
})Response
Status: 201 Created {
"id": 1,
"key": "ssh-rsa AAA...",
"url": "https://api.github.com/repos/octocat/Hello-World/keys/1",
"title": "octocat@octomac",
"verified": true,
"created_at": "2014-12-10T15:53:42Z",
"read_only": true
}Validation failed
Status: 422 Unprocessable Entity注:
Get a deploy key
get /repos/{owner}/{repo}/keys/{key_id}参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
key_id | integer | path | key_id parameter |
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/keys/42JavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/keys/{key_id}', {
owner: 'octocat',
repo: 'hello-world',
key_id: 42
})Response
Status: 200 OK {
"id": 1,
"key": "ssh-rsa AAA...",
"url": "https://api.github.com/repos/octocat/Hello-World/keys/1",
"title": "octocat@octomac",
"verified": true,
"created_at": "2014-12-10T15:53:42Z",
"read_only": true
}Resource not found
Status: 404 Not Found注:
Delete a deploy key
Deploy keys are immutable. If you need to update a key, remove the key and create a new one instead.
delete /repos/{owner}/{repo}/keys/{key_id}参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
key_id | integer | path | key_id parameter |
代码示例
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/keys/42JavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/keys/{key_id}', {
owner: 'octocat',
repo: 'hello-world',
key_id: 42
})Response
Status: 204 No Content注:
List deployment statuses
Users with pull access can view deployment statuses for a deployment:
get /repos/{owner}/{repo}/deployments/{deployment_id}/statuses参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
deployment_id | integer | path | deployment_id parameter |
per_page | integer | query | Results per page (max 100) 默认值: |
page | integer | query | Page number of the results to fetch. 默认值: |
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/deployments/42/statusesJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/deployments/{deployment_id}/statuses', {
owner: 'octocat',
repo: 'hello-world',
deployment_id: 42
})Response
Status: 200 OK [
{
"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"
}
]Resource not found
Status: 404 Not Found注:
Create a deployment status
Users with push access can create deployment statuses for a given deployment.
GitHub Apps require read & write access to "Deployments" and read-only access to "Repo contents" (for private repos). OAuth Apps require the repo_deployment scope.
post /repos/{owner}/{repo}/deployments/{deployment_id}/statuses参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
deployment_id | integer | path | deployment_id parameter |
state | string | body | Required. The state of the status. Can be one of |
target_url | string | body | The 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_url | string | body | The full URL of the deployment's output. This parameter replaces |
description | string | body | A short description of the status. The maximum description length is 140 characters. |
environment | string | body | Name for the target deployment environment, which can be changed when setting a deploy status. For example, |
environment_url | string | body | Sets the URL for accessing your environment. Default: |
auto_inactive | boolean | body | Adds a new |
代码示例
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/deployments/42/statuses \
-d '{"state":"state"}'JavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/deployments/{deployment_id}/statuses', {
owner: 'octocat',
repo: 'hello-world',
deployment_id: 42,
state: 'state'
})Response
Status: 201 Created {
"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"
}Validation failed
Status: 422 Unprocessable Entity注:
Get a deployment status
Users with pull access can view a deployment status for a deployment:
get /repos/{owner}/{repo}/deployments/{deployment_id}/statuses/{status_id}参数
| 名称 | 类型 | In | 描述 |
|---|---|---|---|
accept | string | header | Setting to |
owner | string | path | |
repo | string | path | |
deployment_id | integer | path | deployment_id parameter |
status_id | integer | path |
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/deployments/42/statuses/42JavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/deployments/{deployment_id}/statuses/{status_id}', {
owner: 'octocat',
repo: 'hello-world',
deployment_id: 42,
status_id: 42
})Response
Status: 200 OK {
"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"
}Resource not found
Status: 404 Not Found