部署是部署特定引用(分支、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
并� 除对它的访问权限。
get /repos/{owner}/{repo}/deployments
参数
Name | Type | In | Description |
---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
sha |
string | query |
The SHA recorded at creation time. Default:none |
ref |
string | query |
The name of the ref. This can be a branch, tag, or SHA. Default:none |
task |
string | query |
The name of the task for the deployment (e.g., none |
environment |
string | query |
The name of the environment that was deployed to (e.g., none |
per_page |
integer | query |
Results per page (max 100) Default:30 |
page |
integer | query |
Page number of the results to fetch. Default:1 |
代� �示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
http(s)://{hostname}/api/v3/repos/octocat/hello-world/deployments
JavaScript (@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
}
]
Notes
预览通知
The inactive
state and the log_url
, environment_url
, and auto_inactive
parameters are currently available for developers to preview. Please see the blog post for full details.
To access the API during the preview period, you must provide a custom media type in the Accept
header:
application/vnd.github.ant-man-preview+json
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 Enterprise Server 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
master
in 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
参数
Name | Type | In | Description |
---|---|---|---|
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., deploy |
auto_merge |
boolean | body |
Attempts to automatically merge the default branch into the requested ref, if it's behind the default branch. Default:true |
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 | body |
JSON payload with extra information about the deployment. |
environment |
string | body |
Name for the target deployment environment (e.g., production |
description |
string or nullable | body |
Short description of the deployment. Default:
|
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: false |
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" \
http(s)://{hostname}/api/v3/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 Conflict
Validation failed
Status: 422 Unprocessable Entity
Notes
预览通知
The inactive
state and the log_url
, environment_url
, and auto_inactive
parameters are currently available for developers to preview. Please see the blog post for full details.
To access the API during the preview period, you must provide a custom media type in the Accept
header:
application/vnd.github.ant-man-preview+json
get /repos/{owner}/{repo}/deployments/{deployment_id}
参数
Name | Type | In | Description |
---|---|---|---|
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" \
http(s)://{hostname}/api/v3/repos/octocat/hello-world/deployments/42
JavaScript (@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
Notes
预览通知
New features in the Deployments API on GitHub are currently available during a public beta. Please see the blog post for full details.
To access the new environment
parameter, the two new values for the state
parameter (in_progress
and queued
), and use auto_inactive
on production deployments during the public beta period, you must provide the following custom media type in the Accept
header:
application/vnd.github.flash-preview+json
The inactive
state and the log_url
, environment_url
, and auto_inactive
parameters are currently available for developers to preview. Please see the blog post for full details.
To access the API during the preview period, you must provide a custom media type in the Accept
header:
application/vnd.github.ant-man-preview+json
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}
参数
Name | Type | In | Description |
---|---|---|---|
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" \
http(s)://{hostname}/api/v3/repos/octocat/hello-world/deployments/42
JavaScript (@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 Content
Resource not found
Status: 404 Not Found
Validation failed
Status: 422 Unprocessable Entity
Notes
部署状态
get /repos/{owner}/{repo}/deployments/{deployment_id}/statuses
参数
Name | Type | In | Description |
---|---|---|---|
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) Default:30 |
page |
integer | query |
Page number of the results to fetch. Default:1 |
代� �示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
http(s)://{hostname}/api/v3/repos/octocat/hello-world/deployments/42/statuses
JavaScript (@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
Notes
预览通知
New features in the Deployments API on GitHub are currently available during a public beta. Please see the blog post for full details.
To access the new environment
parameter, the two new values for the state
parameter (in_progress
and queued
), and use auto_inactive
on production deployments during the public beta period, you must provide the following custom media type in the Accept
header:
application/vnd.github.flash-preview+json
The inactive
state and the log_url
, environment_url
, and auto_inactive
parameters are currently available for developers to preview. Please see the blog post for full details.
To access the API during the preview period, you must provide a custom media type in the Accept
header:
application/vnd.github.ant-man-preview+json
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
参数
Name | Type | In | Description |
---|---|---|---|
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. Default:
|
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" \
http(s)://{hostname}/api/v3/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
Notes
预览通知
New features in the Deployments API on GitHub are currently available during a public beta. Please see the blog post for full details.
To access the new environment
parameter, the two new values for the state
parameter (in_progress
and queued
), and use auto_inactive
on production deployments during the public beta period, you must provide the following custom media type in the Accept
header:
application/vnd.github.flash-preview+json
The inactive
state and the log_url
, environment_url
, and auto_inactive
parameters are currently available for developers to preview. Please see the blog post for full details.
To access the API during the preview period, you must provide a custom media type in the Accept
header:
application/vnd.github.ant-man-preview+json
get /repos/{owner}/{repo}/deployments/{deployment_id}/statuses/{status_id}
参数
Name | Type | In | Description |
---|---|---|---|
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" \
http(s)://{hostname}/api/v3/repos/octocat/hello-world/deployments/42/statuses/42
JavaScript (@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
Notes
预览通知
New features in the Deployments API on GitHub are currently available during a public beta. Please see the blog post for full details.
To access the new environment
parameter, the two new values for the state
parameter (in_progress
and queued
), and use auto_inactive
on production deployments during the public beta period, you must provide the following custom media type in the Accept
header:
application/vnd.github.flash-preview+json
The inactive
state and the log_url
, environment_url
, and auto_inactive
parameters are currently available for developers to preview. Please see the blog post for full details.
To access the API during the preview period, you must provide a custom media type in the Accept
header:
application/vnd.github.ant-man-preview+json
部署密钥
You can launch projects from a repository on your GitHub Enterprise Server instance to your server by using a deploy key, which is an SSH key that grants access to a single repository. GitHub Enterprise Server 将密钥的公共部分直接附� 到仓库而不是个人用户帐户,密钥的私有部分仍保留在服务器上。 更多信息请参阅“交付部署”。
部署密钥可以使用以下 API 端点进行设置,也可以使用 GitHub 进行设置。 要了解如何在 GitHub 中设置部署密钥,请参阅“管理部署密钥”。
get /repos/{owner}/{repo}/keys
参数
Name | Type | In | Description |
---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
per_page |
integer | query |
Results per page (max 100) Default:30 |
page |
integer | query |
Page number of the results to fetch. Default:1 |
代� �示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
http(s)://{hostname}/api/v3/repos/octocat/hello-world/keys
JavaScript (@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
}
]
Notes
post /repos/{owner}/{repo}/keys
参数
Name | Type | In | Description |
---|---|---|---|
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" \
http(s)://{hostname}/api/v3/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
Notes
get /repos/{owner}/{repo}/keys/{key_id}
参数
Name | Type | In | Description |
---|---|---|---|
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" \
http(s)://{hostname}/api/v3/repos/octocat/hello-world/keys/42
JavaScript (@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
Notes
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}
参数
Name | Type | In | Description |
---|---|---|---|
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" \
http(s)://{hostname}/api/v3/repos/octocat/hello-world/keys/42
JavaScript (@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