|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Github\Api; |
| 4 | + |
| 5 | +use Github\Exception\MissingArgumentException; |
| 6 | + |
| 7 | +/** |
| 8 | + * Listing, creating and updating deployments. |
| 9 | + * |
| 10 | + * @link https://developer.github.com/v3/repos/deployments/ |
| 11 | + */ |
| 12 | +class Deployment extends AbstractApi |
| 13 | +{ |
| 14 | + /** |
| 15 | + * List deployments for a particular repository |
| 16 | + * @link https://developer.github.com/v3/repos/deployments/#list-deployments |
| 17 | + * |
| 18 | + * @param string $username the username of the user who owns the repository |
| 19 | + * @param string $repository the name of the repository |
| 20 | + * @param array $params query parameters to filter deployments by (see link) |
| 21 | + * @return array the deployments requested |
| 22 | + */ |
| 23 | + public function all($username, $repository, array $params = array()) |
| 24 | + { |
| 25 | + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Create a new deployment for the given username and repo. |
| 30 | + * @link https://developer.github.com/v3/repos/deployments/#create-a-deployment |
| 31 | + * |
| 32 | + * Important: Once a deployment is created, it cannot be updated. Changes are indicated by creating new statuses. |
| 33 | + * @see updateStatus |
| 34 | + * |
| 35 | + * @param string $username the username |
| 36 | + * @param string $repository the repository |
| 37 | + * @param array $params the new deployment data |
| 38 | + * @return array information about the deployment |
| 39 | + * |
| 40 | + * @throws MissingArgumentException |
| 41 | + */ |
| 42 | + public function create($username, $repository, array $params) |
| 43 | + { |
| 44 | + if (!isset($params['ref'])) { |
| 45 | + throw new MissingArgumentException(array('ref')); |
| 46 | + } |
| 47 | + |
| 48 | + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Updates a deployment by creating a new status update. |
| 53 | + * @link https://developer.github.com/v3/repos/deployments/#create-a-deployment-status |
| 54 | + * |
| 55 | + * @param string $username the username |
| 56 | + * @param string $repository the repository |
| 57 | + * @param string $id the deployment number |
| 58 | + * @param array $params The information about the deployment update. |
| 59 | + * Must include a "state" field of pending, success, error, or failure. |
| 60 | + * May also be given a target_url and description, ßee link for more details. |
| 61 | + * @return array information about the deployment |
| 62 | + * |
| 63 | + * @throws MissingArgumentException |
| 64 | + */ |
| 65 | + public function updateStatus($username, $repository, $id, array $params) |
| 66 | + { |
| 67 | + if (!isset($params['state'])) { |
| 68 | + throw new MissingArgumentException(array('state')); |
| 69 | + } |
| 70 | + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Gets all of the status updates tied to a given deployment. |
| 75 | + * |
| 76 | + * @param string $username the username |
| 77 | + * @param string $repository the repository |
| 78 | + * @param int $id the deployment identifier |
| 79 | + * @return array the deployment statuses |
| 80 | + */ |
| 81 | + public function getStatuses($username, $repository, $id) { |
| 82 | + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses'); |
| 83 | + } |
| 84 | +} |
0 commit comments