|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Github\Api; |
| 4 | + |
| 5 | +/** |
| 6 | + * Listing, creating and updating environments. |
| 7 | + * |
| 8 | + * @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28# |
| 9 | + */ |
| 10 | +class Environment extends AbstractApi |
| 11 | +{ |
| 12 | + /** |
| 13 | + * List environments for a particular repository. |
| 14 | + * |
| 15 | + * @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28##list-environments |
| 16 | + * |
| 17 | + * @param string $username the username of the user who owns the repository |
| 18 | + * @param string $repository the name of the repository |
| 19 | + * @param array $params query parameters to filter environments by (see link) |
| 20 | + * |
| 21 | + * @return array the environments requested |
| 22 | + */ |
| 23 | + public function all($username, $repository, array $params = []) |
| 24 | + { |
| 25 | + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments', $params); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Get a environment in selected repository. |
| 30 | + * |
| 31 | + * @param string $username the user who owns the repo |
| 32 | + * @param string $repository the name of the repo |
| 33 | + * @param string $name the name of the environment |
| 34 | + * |
| 35 | + * @return array |
| 36 | + */ |
| 37 | + public function show($username, $repository, $name) |
| 38 | + { |
| 39 | + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.$name); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Create or update a environment for the given username and repo. |
| 44 | + * |
| 45 | + * @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28#create-or-update-an-environment |
| 46 | + * |
| 47 | + * @param string $username the username |
| 48 | + * @param string $repository the repository |
| 49 | + * @param string $name the name of the environment |
| 50 | + * @param array $params the new environment data |
| 51 | + * |
| 52 | + * @return array information about the environment |
| 53 | + */ |
| 54 | + public function createOrUpdate($username, $repository, $name, array $params = []) |
| 55 | + { |
| 56 | + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments', $params); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Delete a environment for the given username and repo. |
| 61 | + * |
| 62 | + * @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28#delete-an-environment |
| 63 | + * |
| 64 | + * @return mixed null on success, array on error with 'message' |
| 65 | + */ |
| 66 | + public function remove(string $username, string $repository, string $name) |
| 67 | + { |
| 68 | + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.$name); |
| 69 | + } |
| 70 | +} |
0 commit comments