Skip to main content

We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the Actions REST API page.

预接收环境

使用 REST API 创建、列出、更新和删除预接收挂钩的环境。

关于预接收环境

这些终结点仅适用于经过身份验证的网站管理员。 普通用户将收到 404 响应。

对象属性

预接收环境

名称类型说明
namestringUI 中显示的环境名称。
image_urlstring将要下载并解压缩的 tarball 的 URL。
default_environmentboolean这是否是 GitHub Enterprise Server 附带的默认环境。
downloadobject此环境的下载状态。
hooks_countinteger使用此环境的预接收挂钩数量。

预接收环境下载

名称类型说明
statestring最近下载的状态。
downloaded_atstring最近下载开始的时间。
messagestring在失败时生成任何错误消息。

state 的可能值为 not_startedin_progresssuccessfailed

List pre-receive environments

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Query parameters
名称, Type, 说明
per_pageinteger

The number of results per page (max 100).

Default: 30

pageinteger

Page number of the results to fetch.

Default: 1

directionstring

The direction to sort the results by.

Default: desc

Can be one of: asc, desc

sortstring

Default: created

Can be one of: created, updated, name

HTTP response status codes

Status code说明
200

OK

Code samples

get/admin/pre-receive-environments
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments

Response

Status: 200
[ { "id": 1, "name": "Default", "image_url": "githubenterprise://internal", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/1", "html_url": "https://github.example.com/admin/pre-receive-environments/1", "default_environment": true, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 14, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/1/downloads/latest", "state": "not_started", "downloaded_at": "2016-05-26T07:42:53-05:00", "message": null } }, { "id": 2, "name": "DevTools Hook Env", "image_url": "https://my_file_server/path/to/devtools_env.tar.gz", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2", "html_url": "https://github.example.com/admin/pre-receive-environments/2", "default_environment": false, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 1, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest", "state": "success", "downloaded_at": "2016-05-26T07:42:53-05:00", "message": null } } ]

Create a pre-receive environment

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Body parameters
名称, Type, 说明
namestringRequired

The new pre-receive environment's name.

image_urlstringRequired

URL from which to download a tarball of this environment.

HTTP response status codes

Status code说明
201

Created

Code samples

post/admin/pre-receive-environments
curl \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments \ -d '{"name":"DevTools Hook Env","image_url":"https://my_file_server/path/to/devtools_env.tar.gz"}'

Response

Status: 201
{ "id": 2, "name": "DevTools Hook Env", "image_url": "https://my_file_server/path/to/devtools_env.tar.gz", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2", "html_url": "https://github.example.com/admin/pre-receive-environments/2", "default_environment": false, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 1, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest", "state": "not_started", "downloaded_at": null, "message": null } }

Get a pre-receive environment

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
pre_receive_environment_idintegerRequired

The unique identifier of the pre-receive environment.

HTTP response status codes

Status code说明
200

OK

Code samples

get/admin/pre-receive-environments/{pre_receive_environment_id}
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID

Response

Status: 200
{ "id": 2, "name": "DevTools Hook Env", "image_url": "https://my_file_server/path/to/devtools_env.tar.gz", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2", "html_url": "https://github.example.com/admin/pre-receive-environments/2", "default_environment": false, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 1, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest", "state": "not_started", "downloaded_at": null, "message": null } }

Update a pre-receive environment

You cannot modify the default environment. If you attempt to modify the default environment, you will receive a 422 Unprocessable Entity response.

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
pre_receive_environment_idintegerRequired

The unique identifier of the pre-receive environment.

Body parameters
名称, Type, 说明
namestring

This pre-receive environment's new name.

image_urlstring

URL from which to download a tarball of this environment.

HTTP response status codes

Status code说明
200

OK

422

Client Errors

Code samples

patch/admin/pre-receive-environments/{pre_receive_environment_id}
curl \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID \ -d '{"name":"DevTools Hook Env","image_url":"https://my_file_server/path/to/devtools_env.tar.gz"}'

Response

Status: 200
{ "id": 2, "name": "DevTools Hook Env", "image_url": "https://my_file_server/path/to/devtools_env.tar.gz", "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2", "html_url": "https://github.example.com/admin/pre-receive-environments/2", "default_environment": false, "created_at": "2016-05-20T11:35:45-05:00", "hooks_count": 1, "download": { "url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest", "state": "success", "downloaded_at": "2016-05-26T07:42:53-05:00", "message": null } }

Delete a pre-receive environment

If you attempt to delete an environment that cannot be deleted, you will receive a 422 Unprocessable Entity response.

The possible error messages are:

  • Cannot modify or delete the default environment
  • Cannot delete environment that has hooks
  • Cannot delete environment when download is in progress

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
pre_receive_environment_idintegerRequired

The unique identifier of the pre-receive environment.

HTTP response status codes

Status code说明
204

No Content

422

Client Errors

Code samples

delete/admin/pre-receive-environments/{pre_receive_environment_id}
curl \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID

Response

Status: 204

Start a pre-receive environment download

Triggers a new download of the environment tarball from the environment's image_url. When the download is finished, the newly downloaded tarball will overwrite the existing environment.

If a download cannot be triggered, you will receive a 422 Unprocessable Entity response.

The possible error messages are:

  • Cannot modify or delete the default environment
  • Can not start a new download when a download is in progress

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
pre_receive_environment_idintegerRequired

The unique identifier of the pre-receive environment.

HTTP response status codes

Status code说明
202

Accepted

422

Client Errors

Code samples

post/admin/pre-receive-environments/{pre_receive_environment_id}/downloads
curl \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID/downloads

Response

Status: 202
{ "url": "https://github.example.com/api/v3/admin/pre-receive-environments/3/downloads/latest", "state": "not_started", "downloaded_at": null, "message": null }

Get the download status for a pre-receive environment

In addition to seeing the download status at the "Get a pre-receive environment" endpoint, there is also this separate endpoint for just the download status.

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
pre_receive_environment_idintegerRequired

The unique identifier of the pre-receive environment.

HTTP response status codes

Status code说明
200

OK

Code samples

get/admin/pre-receive-environments/{pre_receive_environment_id}/downloads/latest
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-environments/PRE_RECEIVE_ENVIRONMENT_ID/downloads/latest

Response

Status: 200
{ "url": "https://github.example.com/api/v3/admin/pre-receive-environments/3/downloads/latest", "state": "success", "downloaded_at": "2016-05-26T07:42:53-05:00", "message": null }