|
| 1 | +--- |
| 2 | +title:Pre-receive Environments |
| 3 | +--- |
| 4 | + |
| 5 | +#Pre-receive Environments |
| 6 | + |
| 7 | +{{#tip}} |
| 8 | + |
| 9 | + <aname="preview-period"></a> |
| 10 | + |
| 11 | + APIs for managing pre-receive hooks are currently available for developers to preview. |
| 12 | + During the preview period, the APIs may change without advance notice. |
| 13 | + |
| 14 | + To access the API you must provide a custom[media type](/v3/media) in the`Accept` header: |
| 15 | + |
| 16 | + application/vnd.github.eye-scream-preview |
| 17 | +
|
| 18 | +{{/tip}} |
| 19 | + |
| 20 | +{:toc} |
| 21 | + |
| 22 | +The Pre-receive Environments API allows you to create, list, update and delete environments for pre-receive hooks.*It is only available to[authenticated](/v3/#authentication) site administrators.* Normal users will receive a`404` response if they try to access it. |
| 23 | + |
| 24 | +Prefix all the endpoints for this API with the following URL: |
| 25 | + |
| 26 | +```command-line |
| 27 | +http(s)://<em>hostname</em>/api/v3 |
| 28 | +``` |
| 29 | + |
| 30 | +##Object attributes |
| 31 | + |
| 32 | +###Pre-receive Environment |
| 33 | + |
| 34 | +| Name| Type| Description| |
| 35 | +|-----------------------|-----------|----------------------------------------------------------------------------| |
| 36 | +|`name`|`string`| The name of the environment as displayed in the UI.| |
| 37 | +|`image_url`|`string`| URL to the tarball that will be downloaded and extracted.| |
| 38 | +|`default_environment`|`boolean`| Whether this is the default environment that ships with GitHub Enterprise.| |
| 39 | +|`download`|`object`| This environment's download status.| |
| 40 | +|`hooks_count`|`integer`| The number of pre-receive hooks that use this environment.| |
| 41 | + |
| 42 | +###Pre-receive Environment Download |
| 43 | + |
| 44 | +| Name| Type| Description| |
| 45 | +|-----------------|----------|---------------------------------------------------------| |
| 46 | +|`state`|`string`| The state of the most recent download.| |
| 47 | +|`downloaded_at`|`string`| The time when the most recent download started.| |
| 48 | +|`message`|`string`| On failure, this will have any error messages produced.| |
| 49 | + |
| 50 | +Possible values for`state` are`not_started`,`in_progress`,`success`,`failed`. |
| 51 | + |
| 52 | + |
| 53 | +##Get a single pre-receive environment |
| 54 | + |
| 55 | +GET /admin/pre-receive-environments/:id |
| 56 | + |
| 57 | +<%= headers 200 %> |
| 58 | +<%= json:pre_receive_environment %> |
| 59 | + |
| 60 | +##List pre-receive environments |
| 61 | + |
| 62 | +GET /admin/pre_receive_environments |
| 63 | + |
| 64 | +<%= headers 200,:pagination => default_pagination_rels %> |
| 65 | +<%= json:pre_receive_environments %> |
| 66 | + |
| 67 | +##Create a pre-receive environment |
| 68 | + |
| 69 | +POST /admin/pre_receive_environments |
| 70 | + |
| 71 | +###Parameters |
| 72 | + |
| 73 | +| Name| Type| Description| |
| 74 | +|-------------|----------|-------------------------------------------------------------------------| |
| 75 | +|`name`|`string`|**Required**. The new pre-receive environment's name.| |
| 76 | +|`image_url`|`string`|**Required**. URL from which to download a tarball of this environment.| |
| 77 | + |
| 78 | +<%= json\ |
| 79 | +:name => 'DevTools Hook Env', |
| 80 | +:image_url => 'https://my_file_server/path/to/devtools_env.tar.gz' |
| 81 | +%> |
| 82 | + |
| 83 | +###Response |
| 84 | + |
| 85 | +<%= headers 201 %> |
| 86 | +<%= json:pre_receive_environment_create %> |
| 87 | + |
| 88 | +##Edit a pre-receive environment |
| 89 | + |
| 90 | +PATCH /admin/pre_receive_environments/:id |
| 91 | + |
| 92 | +###Parameters |
| 93 | + |
| 94 | +| Name| Type| Description| |
| 95 | +|-------------|----------|-----------------------------------------------------------| |
| 96 | +|`name`|`string`| This pre-receive environment's new name.| |
| 97 | +|`image_url`|`string`| URL from which to download a tarball of this environment.| |
| 98 | + |
| 99 | +###Response |
| 100 | +<%= headers 200 %> |
| 101 | +<%= json:pre_receive_environment %> |
| 102 | + |
| 103 | +####Client Errors |
| 104 | + |
| 105 | +If you attempt to modify the default environment, you will get a response like this: |
| 106 | + |
| 107 | +<%= headers 422 %> |
| 108 | +<%= |
| 109 | + json:message => "Validation Failed", |
| 110 | +:errors =>[{ |
| 111 | +:resource =>:PreReceiveEnvironment, |
| 112 | +:code =>:custom, |
| 113 | +:message => 'Cannot modify or delete the default environment' |
| 114 | + }] |
| 115 | +%> |
| 116 | + |
| 117 | +##Delete a pre-receive environment |
| 118 | + |
| 119 | +DELETE /admin/pre_receive_environments/:id |
| 120 | + |
| 121 | +###Response |
| 122 | + |
| 123 | +<%= headers 204 %> |
| 124 | + |
| 125 | +####Client Errors |
| 126 | + |
| 127 | +If you attempt to delete an environment that cannot be deleted, you will get a response like this: |
| 128 | + |
| 129 | +<%= headers 422 %> |
| 130 | +<%= |
| 131 | + json:message => "Validation Failed", |
| 132 | +:errors =>[{ |
| 133 | +:resource =>:PreReceiveEnvironment, |
| 134 | +:code =>:custom, |
| 135 | +:message => 'Cannot modify or delete the default environment' |
| 136 | + }] |
| 137 | +%> |
| 138 | + |
| 139 | +The possible error messages are: |
| 140 | + |
| 141 | +-_Cannot modify or delete the default environment_ |
| 142 | +-_Cannot delete environment that has hooks_ |
| 143 | +-_Cannot delete environment when download is in progress_ |
| 144 | + |
| 145 | +##Get a pre-receive environment's download status |
| 146 | + |
| 147 | +In addition to seeing the download status at the`/admin/pre-receive-environments/:id`, there is also a separate endpoint for just the status. |
| 148 | + |
| 149 | +GET /admin/pre-receive-environments/:id/downloads/latest |
| 150 | + |
| 151 | +<%= headers 200 %> |
| 152 | +<%= json:pre_receive_environment_download_2 %> |
| 153 | + |
| 154 | +###Object attributes |
| 155 | + |
| 156 | +| Name| Type| Description| |
| 157 | +|-----------------|----------|---------------------------------------------------------| |
| 158 | +|`state`|`string`| The state of the most recent download.| |
| 159 | +|`downloaded_at`|`string`| The time when the most recent download started.| |
| 160 | +|`message`|`string`| On failure, this will have any error messages produced.| |
| 161 | + |
| 162 | +Possible values for`state` are`not_started`,`in_progress`,`success`,`failed`. |
| 163 | + |
| 164 | +##Trigger a pre-receive environment download |
| 165 | + |
| 166 | +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. |
| 167 | + |
| 168 | +POST /admin/pre_receive_environments/:id/downloads |
| 169 | + |
| 170 | +###Response |
| 171 | + |
| 172 | +<%= headers 202 %> |
| 173 | +<%= json:pre_receive_environment_download %> |
| 174 | + |
| 175 | +####Client Errors |
| 176 | + |
| 177 | +If a download cannot be triggered, you will get a reponse like this: |
| 178 | + |
| 179 | +<%= headers 422 %> |
| 180 | +<%= |
| 181 | + json:message => "Validation Failed", |
| 182 | +:errors =>[{ |
| 183 | +:resource =>:PreReceiveEnvironment, |
| 184 | +:code =>:custom, |
| 185 | +:message => 'Can not start a new download when a download is in progress' |
| 186 | + }] |
| 187 | +%> |
| 188 | + |
| 189 | +The possible error messages are: |
| 190 | + |
| 191 | +-_Cannot modify or delete the default environment_ |
| 192 | +-_Can not start a new download when a download is in progress_ |
| 193 | + |