|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Github\Api\PullRequest; |
| 4 | + |
| 5 | +use Github\Api\AbstractApi; |
| 6 | +use Github\Exception\InvalidArgumentException; |
| 7 | +use Github\Exception\MissingArgumentException; |
| 8 | + |
| 9 | +/** |
| 10 | + * API for accessing Pull Request Reviews from your Git/Github repositories. |
| 11 | + * |
| 12 | + * @link https://developer.github.com/v3/pulls/reviews/ |
| 13 | + * @author Christian Flothmann <[email protected]> |
| 14 | + */ |
| 15 | +class Review extends AbstractApi |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Get a listing of a pull request's reviews by the username, repository and pull request number. |
| 19 | + * |
| 20 | + * @link https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request |
| 21 | + * |
| 22 | + * @param string $username the username |
| 23 | + * @param string $repository the repository |
| 24 | + * @param int $pullRequest the pull request number |
| 25 | + * @param array $params a list of extra parameters. |
| 26 | + * |
| 27 | + * @return array array of pull request reviews for the pull request |
| 28 | + */ |
| 29 | + public function all($username, $repository, $pullRequest, array $params = []) |
| 30 | + { |
| 31 | + $parameters = array_merge([ |
| 32 | + 'page' => 1, |
| 33 | + 'per_page' => 30 |
| 34 | + ], $params); |
| 35 | + |
| 36 | + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews', $parameters); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Get a single pull request review by the username, repository, pull request number and the review id. |
| 41 | + * |
| 42 | + * @link https://developer.github.com/v3/pulls/reviews/#get-a-single-review |
| 43 | + * |
| 44 | + * @param string $username the username |
| 45 | + * @param string $repository the repository |
| 46 | + * @param int $pullRequest the pull request number |
| 47 | + * @param int $id the review id |
| 48 | + * |
| 49 | + * @return array the pull request review |
| 50 | + */ |
| 51 | + public function show($username, $repository, $pullRequest, $id) |
| 52 | + { |
| 53 | + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Delete a single pull request review by the username, repository, pull request number and the review id. |
| 58 | + * |
| 59 | + * @link https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review |
| 60 | + * |
| 61 | + * @param string $username the username |
| 62 | + * @param string $repository the repository |
| 63 | + * @param int $pullRequest the pull request number |
| 64 | + * @param int $id the review id |
| 65 | + * |
| 66 | + * @return array|string |
| 67 | + */ |
| 68 | + public function remove($username, $repository, $pullRequest, $id) |
| 69 | + { |
| 70 | + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Get comments for a single pull request review. |
| 75 | + * |
| 76 | + * @link https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review |
| 77 | + * |
| 78 | + * @param string $username the username |
| 79 | + * @param string $repository the repository |
| 80 | + * @param int $pullRequest the pull request number |
| 81 | + * @param int $id the review id |
| 82 | + * |
| 83 | + * @return array|string |
| 84 | + */ |
| 85 | + public function comments($username, $repository, $pullRequest, $id) |
| 86 | + { |
| 87 | + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/reviews/'.rawurlencode($id).'/comments'); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Create a pull request review by the username, repository and pull request number. |
| 92 | + * |
| 93 | + * @link https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review |
| 94 | + * |
| 95 | + * @param string $username the username |
| 96 | + * @param string $repository the repository |
| 97 | + * @param int $pullRequest the pull request number |
| 98 | + * @param array $params a list of extra parameters. |
| 99 | + * |
| 100 | + * @throws MissingArgumentException |
| 101 | + * |
| 102 | + * @return array the pull request review |
| 103 | + */ |
| 104 | + public function create($username, $repository, $pullRequest, array $params = []) |
| 105 | + { |
| 106 | + if (!isset($params['event'])) { |
| 107 | + throw new MissingArgumentException('event'); |
| 108 | + } |
| 109 | + |
| 110 | + if (!in_array($params['event'], ["APPROVE", "REQUEST_CHANGES", "COMMENT"], true)) { |
| 111 | + throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event'])); |
| 112 | + } |
| 113 | + |
| 114 | + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews', $params); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Submit a pull request review by the username, repository, pull request number and the review id. |
| 119 | + * |
| 120 | + * @link https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review |
| 121 | + * |
| 122 | + * @param string $username the username |
| 123 | + * @param string $repository the repository |
| 124 | + * @param int $pullRequest the pull request number |
| 125 | + * @param int $id the review id |
| 126 | + * @param array $params a list of extra parameters. |
| 127 | + * |
| 128 | + * @throws MissingArgumentException |
| 129 | + * |
| 130 | + * @return array the pull request review |
| 131 | + */ |
| 132 | + public function submit($username, $repository, $pullRequest, $id, array $params = []) |
| 133 | + { |
| 134 | + if (!isset($params['event'])) { |
| 135 | + throw new MissingArgumentException('event'); |
| 136 | + } |
| 137 | + |
| 138 | + if (!in_array($params['event'], ["APPROVE", "REQUEST_CHANGES", "COMMENT"], true)) { |
| 139 | + throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event'])); |
| 140 | + } |
| 141 | + |
| 142 | + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/events', $params); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Dismiss a pull request review by the username, repository, pull request number and the review id. |
| 147 | + * |
| 148 | + * @link https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review |
| 149 | + * |
| 150 | + * @param string $username the username |
| 151 | + * @param string $repository the repository |
| 152 | + * @param int $pullRequest the pull request number |
| 153 | + * @param int $id the review id |
| 154 | + * |
| 155 | + * @return array|string |
| 156 | + */ |
| 157 | + public function dismiss($username, $repository, $pullRequest, $id) |
| 158 | + { |
| 159 | + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/dismissals'); |
| 160 | + } |
| 161 | +} |
0 commit comments