Pre-receive Environments

APIs for managing pre-receive hooks are currently available for developers to preview. During the preview period, the APIs may change without advance notice.

To access the API you must provide a custom media type in the Accept header:

  application/vnd.github.eye-scream-preview

The Pre-receive Environments API allows you to create, list, update and delete environments for pre-receive hooks. It is only available to authenticated site administrators. Normal users will receive a 404 response if they try to access it.

Prefix all the endpoints for this API with the following URL:

http(s)://hostname/api/v3

Object attributes

Pre-receive Environment

Name Type Description
name string The name of the environment as displayed in the UI.
image_url string URL to the tarball that will be downloaded and extracted.
default_environment boolean Whether this is the default environment that ships with GitHub Enterprise.
download object This environment's download status.
hooks_count integer The number of pre-receive hooks that use this environment.

Pre-receive Environment Download

Name Type Description
state string The state of the most recent download.
downloaded_at string The time when the most recent download started.
message string On failure, this will have any error messages produced.

Possible values for state are not_started, in_progress, success, failed.

Get a single pre-receive environment

GET /admin/pre-receive-environments/:id
Status: 200 OK
{
  "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
  }
}

List pre-receive environments

GET /admin/pre-receive-environments
Status: 200 OK
Link: <https://api.github.com/resource?page=2>; rel="next",
      <https://api.github.com/resource?page=5>; rel="last"
[
  {
    "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

POST /admin/pre-receive-environments

Parameters

Name Type Description
name string Required. The new pre-receive environment's name.
image_url string Required. URL from which to download a tarball of this environment.
{
  "name": "DevTools Hook Env",
  "image_url": "https://my_file_server/path/to/devtools_env.tar.gz"
}

Response

Status: 201 Created
{
  "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
  }
}

Edit a pre-receive environment

PATCH /admin/pre-receive-environments/:id

Parameters

Name Type Description
name string This pre-receive environment's new name.
image_url string URL from which to download a tarball of this environment.

Response

Status: 200 OK
{
  "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
  }
}

Client Errors

If you attempt to modify the default environment, you will get a response like this:

Status: 422 Unprocessable Entity
{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "PreReceiveEnvironment",
      "code": "custom",
      "message": "Cannot modify or delete the default environment"
    }
  ]
}

Delete a pre-receive environment

DELETE /admin/pre-receive-environments/:id

Response

Status: 204 No Content

Client Errors

If you attempt to delete an environment that cannot be deleted, you will get a response like this:

Status: 422 Unprocessable Entity
{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "PreReceiveEnvironment",
      "code": "custom",
      "message": "Cannot modify or delete the default environment"
    }
  ]
}

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

Get a pre-receive environment's download status

In addition to seeing the download status at the /admin/pre-receive-environments/:id, there is also a separate endpoint for just the status.

GET /admin/pre-receive-environments/:id/downloads/latest
Status: 200 OK
{
  "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
}

Object attributes

Name Type Description
state string The state of the most recent download.
downloaded_at string The time when the most recent download started.
message string On failure, this will have any error messages produced.

Possible values for state are not_started, in_progress, success, failed.

Trigger 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.

POST /admin/pre-receive-environments/:id/downloads

Response

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

Client Errors

If a download cannot be triggered, you will get a reponse like this:

Status: 422 Unprocessable Entity
{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "PreReceiveEnvironment",
      "code": "custom",
      "message": "Can not start a new download when a download is in progress"
    }
  ]
}

The possible error messages are:

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