├── .editorconfig ├── .phan └── config.php ├── LICENSE ├── README.md ├── SECURITY.md ├── composer.json ├── docs ├── index.md └── overview.md └── src ├── AbstractGithubObject.php ├── AbstractPackage.php ├── Github.php └── Package ├── Activity.php ├── Activity ├── Events.php ├── Feeds.php ├── Notifications.php ├── Starring.php └── Watching.php ├── Authorization.php ├── Data.php ├── Data ├── Blobs.php ├── Commits.php ├── Refs.php ├── Tags.php └── Trees.php ├── Emojis.php ├── Gists.php ├── Gists └── Comments.php ├── Gitignore.php ├── Graphql.php ├── Issues.php ├── Issues ├── Assignees.php ├── Comments.php ├── Events.php ├── Labels.php └── Milestones.php ├── Markdown.php ├── Meta.php ├── Orgs.php ├── Orgs ├── Hooks.php ├── Members.php └── Teams.php ├── Pulls.php ├── Pulls └── Comments.php ├── Repositories.php ├── Repositories ├── Branches.php ├── Collaborators.php ├── Comments.php ├── Commits.php ├── Contents.php ├── Deployments.php ├── Downloads.php ├── Forks.php ├── Hooks.php ├── Keys.php ├── Merging.php ├── Pages.php ├── Releases.php ├── Statistics.php └── Statuses.php ├── Search.php ├── Users.php ├── Users ├── Emails.php ├── Followers.php └── Keys.php └── Zen.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # Unix-style newlines with a newline ending every file 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | These versions are currently being supported with security updates: 6 | 7 | | Version | Supported | 8 | | ------- | ------------------ | 9 | | 2.0.x | :white_check_mark: | 10 | | 1.7.x | :white_check_mark: | 11 | | < 1.7 | :x: | 12 | 13 | ## Reporting a Vulnerability 14 | 15 | To report a security issue in the core Joomla! CMS or Framework, or with a joomla.org website, please submit 16 | [the form on our portal](https://developer.joomla.org/security/contact-the-team.html) containing as much detail 17 | as possible about the issue. Additional information about our security team and their processes may be found on 18 | our [Security page](https://developer.joomla.org/security.html). 19 | 20 | To report an issue in a Joomla! extension, please submit it to the [Vulnerable Extensions List](https://vel.joomla.org/submit-vel). 21 | 22 | For support with a site which has been attacked, please visit the [Joomla! Forum](https://forum.joomla.org/viewforum.php?f=714). 23 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "joomla/github", 3 | "type": "joomla-package", 4 | "description": "Joomla Github Package", 5 | "keywords": ["joomla", "framework", "github"], 6 | "homepage": "https://github.com/joomla-framework/github-api", 7 | "license": "GPL-2.0-or-later", 8 | "require": { 9 | "php": "^8.1.0", 10 | "joomla/http": "^3.0", 11 | "joomla/registry": "^3.0", 12 | "joomla/uri": "^3.0" 13 | }, 14 | "require-dev": { 15 | "phpunit/phpunit": "^9.5.28", 16 | "squizlabs/php_codesniffer": "^3.7.2", 17 | "phpstan/phpstan": "^1.10.7", 18 | "phan/phan": "^5.4.2" 19 | }, 20 | "autoload": { 21 | "psr-4": { 22 | "Joomla\\Github\\": "src/" 23 | } 24 | }, 25 | "autoload-dev": { 26 | "psr-4": { 27 | "Joomla\\Github\\Tests\\": "Tests/" 28 | } 29 | }, 30 | "minimum-stability": "dev", 31 | "extra": { 32 | "branch-alias": { 33 | "dev-2.0-dev": "2.0-dev", 34 | "dev-3.x-dev": "3.0-dev" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | * [Overview](overview.md) 2 | -------------------------------------------------------------------------------- /docs/overview.md: -------------------------------------------------------------------------------- 1 | # Github API package 2 | 3 | TODO 4 | -------------------------------------------------------------------------------- /src/AbstractGithubObject.php: -------------------------------------------------------------------------------- 1 | options = $options ?: new Registry(); 94 | $this->client = $client ?: (new HttpFactory())->getHttp($this->options); 95 | 96 | $this->package = \get_class($this); 97 | $this->package = substr($this->package, strrpos($this->package, '\\') + 1); 98 | } 99 | 100 | /** 101 | * Method to build and return a full request URL for the request. This method will 102 | * add appropriate pagination details if necessary and also prepend the API url 103 | * to have a complete URL for the request. 104 | * 105 | * @param string $path URL to inflect 106 | * @param integer $page Page to request 107 | * @param integer $limit Number of results to return per page 108 | * 109 | * @return Uri 110 | * 111 | * @since 1.0 112 | */ 113 | protected function fetchUrl($path, $page = 0, $limit = 0) 114 | { 115 | // Get a new Uri object focusing the api url and given path. 116 | $uri = new Uri($this->options->get('api.url') . $path); 117 | 118 | if ($this->options->get('gh.token', false)) { 119 | // Use oAuth authentication 120 | $headers = $this->client->getOption('headers', []); 121 | 122 | if (!isset($headers['Authorization'])) { 123 | $headers['Authorization'] = 'token ' . $this->options->get('gh.token'); 124 | $this->client->setOption('headers', $headers); 125 | } 126 | } else { 127 | // Use basic authentication 128 | if ($this->options->get('api.username', false)) { 129 | $uri->setUser($this->options->get('api.username')); 130 | } 131 | 132 | if ($this->options->get('api.password', false)) { 133 | $uri->setPass($this->options->get('api.password')); 134 | } 135 | } 136 | 137 | // If we have a defined page number add it to the JUri object. 138 | if ($page > 0) { 139 | $uri->setVar('page', (int) $page); 140 | } 141 | 142 | // If we have a defined items per page add it to the JUri object. 143 | if ($limit > 0) { 144 | $uri->setVar('per_page', (int) $limit); 145 | } 146 | 147 | return $uri; 148 | } 149 | 150 | /** 151 | * Process the response and decode it. 152 | * 153 | * @param Response $response The response. 154 | * @param integer $expectedCode The expected "good" code. 155 | * 156 | * @return mixed 157 | * 158 | * @since 1.0 159 | * @throws UnexpectedResponseException 160 | */ 161 | protected function processResponse(Response $response, $expectedCode = 200) 162 | { 163 | // Validate the response code. 164 | if ($response->code != $expectedCode) { 165 | // Decode the error response and throw an exception. 166 | $error = json_decode($response->body); 167 | $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; 168 | 169 | throw new UnexpectedResponseException($response, $message, $response->code); 170 | } 171 | 172 | return json_decode($response->body); 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/AbstractPackage.php: -------------------------------------------------------------------------------- 1 | package = \get_class($this); 35 | $this->package = substr($this->package, strrpos($this->package, '\\') + 1); 36 | } 37 | 38 | /** 39 | * Magic method to lazily create API objects 40 | * 41 | * @param string $name Name of property to retrieve 42 | * 43 | * @since 1.0 44 | * @throws \InvalidArgumentException 45 | * 46 | * @return AbstractPackage GitHub API package object. 47 | */ 48 | public function __get($name) 49 | { 50 | $class = '\\Joomla\\Github\\Package\\' . $this->package . '\\' . ucfirst($name); 51 | 52 | if (class_exists($class) == false) { 53 | throw new \InvalidArgumentException( 54 | sprintf( 55 | 'Argument %1$s produced an invalid class name: %2$s in package %3$s', 56 | $name, 57 | $class, 58 | $this->package 59 | ) 60 | ); 61 | } 62 | 63 | if (isset($this->$name) == false) { 64 | $this->$name = new $class($this->options, $this->client); 65 | } 66 | 67 | return $this->$name; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Github.php: -------------------------------------------------------------------------------- 1 | options = $options ?: new Registry(); 67 | 68 | // Setup the default user agent if not already set. 69 | if (!$this->getOption('userAgent')) { 70 | $this->setOption('userAgent', 'JGitHub/2.0'); 71 | } 72 | 73 | // Setup the default API url if not already set. 74 | if (!$this->getOption('api.url')) { 75 | $this->setOption('api.url', 'https://api.github.com'); 76 | } 77 | 78 | $this->client = $client ?: (new HttpFactory())->getHttp($this->options); 79 | } 80 | 81 | /** 82 | * Magic method to lazily create API objects 83 | * 84 | * @param string $name Name of property to retrieve 85 | * 86 | * @return AbstractGithubObject GitHub API object (gists, issues, pulls, etc). 87 | * 88 | * @since 1.0 89 | * @throws \InvalidArgumentException If $name is not a valid sub class. 90 | */ 91 | public function __get($name) 92 | { 93 | $class = 'Joomla\\Github\\Package\\' . ucfirst($name); 94 | 95 | if (class_exists($class)) { 96 | if (isset($this->$name) == false) { 97 | $this->$name = new $class($this->options, $this->client); 98 | } 99 | 100 | return $this->$name; 101 | } 102 | 103 | throw new \InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class)); 104 | } 105 | 106 | /** 107 | * Get an option from the GitHub instance. 108 | * 109 | * @param string $key The name of the option to get. 110 | * 111 | * @return mixed The option value. 112 | * 113 | * @since 1.0 114 | */ 115 | public function getOption($key) 116 | { 117 | return isset($this->options[$key]) ? $this->options[$key] : null; 118 | } 119 | 120 | /** 121 | * Set an option for the GitHub instance. 122 | * 123 | * @param string $key The name of the option to set. 124 | * @param mixed $value The option value to set. 125 | * 126 | * @return GitHub This object for method chaining. 127 | * 128 | * @since 1.0 129 | */ 130 | public function setOption($key, $value) 131 | { 132 | $this->options[$key] = $value; 133 | 134 | return $this; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/Package/Activity.php: -------------------------------------------------------------------------------- 1 | processResponse( 36 | $this->client->get($this->fetchUrl($path)) 37 | ); 38 | } 39 | 40 | /** 41 | * List repository events. 42 | * 43 | * @param string $owner Repository owner. 44 | * @param string $repo Repository name. 45 | * 46 | * @return object 47 | * 48 | * @since 1.0 49 | */ 50 | public function getRepository($owner, $repo) 51 | { 52 | // Build the request path. 53 | $path = '/repos/' . $owner . '/' . $repo . '/events'; 54 | 55 | return $this->processResponse( 56 | $this->client->get($this->fetchUrl($path)) 57 | ); 58 | } 59 | 60 | /** 61 | * List issue events for a repository. 62 | * 63 | * @param string $owner Repository owner. 64 | * @param string $repo Repository name. 65 | * 66 | * @return object 67 | * 68 | * @since 1.0 69 | */ 70 | public function getIssue($owner, $repo) 71 | { 72 | // Build the request path. 73 | $path = '/repos/' . $owner . '/' . $repo . '/issues/events'; 74 | 75 | return $this->processResponse( 76 | $this->client->get($this->fetchUrl($path)) 77 | ); 78 | } 79 | 80 | /** 81 | * List public events for a network of repositories. 82 | * 83 | * @param string $owner Repository owner. 84 | * @param string $repo Repository name. 85 | * 86 | * @return object 87 | * 88 | * @since 1.0 89 | */ 90 | public function getNetwork($owner, $repo) 91 | { 92 | // Build the request path. 93 | $path = '/networks/' . $owner . '/' . $repo . '/events'; 94 | 95 | return $this->processResponse( 96 | $this->client->get($this->fetchUrl($path)) 97 | ); 98 | } 99 | 100 | /** 101 | * List public events for an organization. 102 | * 103 | * @param string $org Organization. 104 | * 105 | * @return object 106 | * 107 | * @since 1.0 108 | */ 109 | public function getOrg($org) 110 | { 111 | // Build the request path. 112 | $path = '/orgs/' . $org . '/events'; 113 | 114 | return $this->processResponse( 115 | $this->client->get($this->fetchUrl($path)) 116 | ); 117 | } 118 | 119 | /** 120 | * List events that a user has received. 121 | * 122 | * These are events that you’ve received by watching repos and following users. 123 | * If you are authenticated as the given user, you will see private events. 124 | * Otherwise, you’ll only see public events. 125 | * 126 | * @param string $user User name. 127 | * 128 | * @return object 129 | * 130 | * @since 1.0 131 | */ 132 | public function getUser($user) 133 | { 134 | // Build the request path. 135 | $path = '/users/' . $user . '/received_events'; 136 | 137 | return $this->processResponse( 138 | $this->client->get($this->fetchUrl($path)) 139 | ); 140 | } 141 | 142 | /** 143 | * List public events that a user has received. 144 | * 145 | * @param string $user User name. 146 | * 147 | * @return object 148 | * 149 | * @since 1.0 150 | */ 151 | public function getUserPublic($user) 152 | { 153 | // Build the request path. 154 | $path = '/users/' . $user . '/received_events/public'; 155 | 156 | return $this->processResponse( 157 | $this->client->get($this->fetchUrl($path)) 158 | ); 159 | } 160 | 161 | /** 162 | * List events performed by a user. 163 | * 164 | * If you are authenticated as the given user, you will see your private events. 165 | * Otherwise, you’ll only see public events. 166 | * 167 | * @param string $user User name. 168 | * 169 | * @return object 170 | * 171 | * @since 1.0 172 | */ 173 | public function getByUser($user) 174 | { 175 | // Build the request path. 176 | $path = '/users/' . $user . '/events'; 177 | 178 | return $this->processResponse( 179 | $this->client->get($this->fetchUrl($path)) 180 | ); 181 | } 182 | 183 | /** 184 | * List public events performed by a user. 185 | * 186 | * @param string $user User name. 187 | * 188 | * @return object 189 | * 190 | * @since 1.0 191 | */ 192 | public function getByUserPublic($user) 193 | { 194 | // Build the request path. 195 | $path = '/users/' . $user . '/events/public'; 196 | 197 | return $this->processResponse( 198 | $this->client->get($this->fetchUrl($path)) 199 | ); 200 | } 201 | 202 | /** 203 | * List events for an organization. 204 | * 205 | * This is the user’s organization dashboard. 206 | * You must be authenticated as the user to view this. 207 | * 208 | * @param string $user User name. 209 | * @param string $org Organisation. 210 | * 211 | * @return object 212 | * 213 | * @since 1.0 214 | */ 215 | public function getUserOrg($user, $org) 216 | { 217 | // Build the request path. 218 | $path = '/users/' . $user . '/events/orgs/' . $org; 219 | 220 | return $this->processResponse( 221 | $this->client->get($this->fetchUrl($path)) 222 | ); 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /src/Package/Activity/Feeds.php: -------------------------------------------------------------------------------- 1 | processResponse( 36 | $this->client->get($this->fetchUrl($path)) 37 | ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Package/Activity/Notifications.php: -------------------------------------------------------------------------------- 1 | fetchUrl($path); 43 | 44 | if ($all) { 45 | $uri->setVar('all', 1); 46 | } 47 | 48 | if ($participating) { 49 | $uri->setVar('participating', 1); 50 | } 51 | 52 | if ($since) { 53 | $uri->setVar('since', $since->format(\DateTime::RFC3339)); 54 | } 55 | 56 | if ($before) { 57 | $uri->setVar('before', $before->format(\DateTime::RFC3339)); 58 | } 59 | 60 | return $this->processResponse($this->client->get($uri)); 61 | } 62 | 63 | /** 64 | * List your notifications in a repository. 65 | * 66 | * List all notifications for the current user. 67 | * 68 | * @param string $owner Repository owner. 69 | * @param string $repo Repository name. 70 | * @param boolean $all True to show notifications marked as read. 71 | * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. 72 | * @param ?\DateTimeInterface $since Only show notifications updated after the given time. 73 | * @param ?\DateTimeInterface $before Only show notifications updated before the given time. 74 | * 75 | * @return object 76 | * 77 | * @since 1.0 78 | */ 79 | public function getListRepository( 80 | $owner, 81 | $repo, 82 | $all = true, 83 | $participating = true, 84 | \DateTimeInterface $since = null, 85 | \DateTimeInterface $before = null 86 | ) { 87 | // Build the request path. 88 | $path = '/repos/' . $owner . '/' . $repo . '/notifications'; 89 | 90 | $uri = $this->fetchUrl($path); 91 | 92 | if ($all) { 93 | $uri->setVar('all', 1); 94 | } 95 | 96 | if ($participating) { 97 | $uri->setVar('participating', 1); 98 | } 99 | 100 | if ($since) { 101 | $uri->setVar('since', $since->format(\DateTime::RFC3339)); 102 | } 103 | 104 | if ($before) { 105 | $uri->setVar('before', $before->format(\DateTime::RFC3339)); 106 | } 107 | 108 | return $this->processResponse($this->client->get($uri)); 109 | } 110 | 111 | /** 112 | * Mark as read. 113 | * 114 | * Marking a notification as “read” removes it from the default view on GitHub.com. 115 | * 116 | * @param boolean $unread Changes the unread status of the threads. 117 | * @param boolean $read Inverse of “unread”. 118 | * @param ?\DateTimeInterface $lastReadAt Describes the last point that notifications were checked. 119 | * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. 120 | * 121 | * @return object 122 | * 123 | * @since 1.0 124 | */ 125 | public function markRead($unread = true, $read = true, \DateTimeInterface $lastReadAt = null) 126 | { 127 | // Build the request path. 128 | $path = '/notifications'; 129 | 130 | $data = [ 131 | 'unread' => $unread, 132 | 'read' => $read, 133 | ]; 134 | 135 | if ($lastReadAt) { 136 | $data['last_read_at'] = $lastReadAt->format(\DateTime::RFC3339); 137 | } 138 | 139 | return $this->processResponse( 140 | $this->client->put($this->fetchUrl($path), json_encode($data)), 141 | 205 142 | ); 143 | } 144 | 145 | /** 146 | * Mark notifications as read in a repository. 147 | * 148 | * Marking all notifications in a repository as “read” removes them from the default view on GitHub.com. 149 | * 150 | * @param string $owner Repository owner. 151 | * @param string $repo Repository name. 152 | * @param boolean $unread Changes the unread status of the threads. 153 | * @param boolean $read Inverse of “unread”. 154 | * @param ?\DateTimeInterface $lastReadAt Describes the last point that notifications were checked. 155 | * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. 156 | * 157 | * @return object 158 | * 159 | * @since 1.0 160 | */ 161 | public function markReadRepository($owner, $repo, $unread, $read, \DateTimeInterface $lastReadAt = null) 162 | { 163 | // Build the request path. 164 | $path = '/repos/' . $owner . '/' . $repo . '/notifications'; 165 | 166 | $data = [ 167 | 'unread' => $unread, 168 | 'read' => $read, 169 | ]; 170 | 171 | if ($lastReadAt) { 172 | $data['last_read_at'] = $lastReadAt->format(\DateTime::RFC3339); 173 | } 174 | 175 | return $this->processResponse( 176 | $this->client->put($this->fetchUrl($path), json_encode($data)), 177 | 205 178 | ); 179 | } 180 | 181 | /** 182 | * View a single thread. 183 | * 184 | * @param integer $id The thread id. 185 | * 186 | * @return object 187 | * 188 | * @since 1.0 189 | */ 190 | public function viewThread($id) 191 | { 192 | // Build the request path. 193 | $path = '/notifications/threads/' . $id; 194 | 195 | return $this->processResponse( 196 | $this->client->get($this->fetchUrl($path)) 197 | ); 198 | } 199 | 200 | /** 201 | * Mark a thread as read. 202 | * 203 | * @param integer $id The thread id. 204 | * @param boolean $unread Changes the unread status of the threads. 205 | * @param boolean $read Inverse of “unread”. 206 | * 207 | * @return object 208 | * 209 | * @since 1.0 210 | */ 211 | public function markReadThread($id, $unread = true, $read = true) 212 | { 213 | // Build the request path. 214 | $path = '/notifications/threads/' . $id; 215 | 216 | $data = [ 217 | 'unread' => $unread, 218 | 'read' => $read, 219 | ]; 220 | 221 | return $this->processResponse( 222 | $this->client->patch($this->fetchUrl($path), json_encode($data)), 223 | 205 224 | ); 225 | } 226 | 227 | /** 228 | * Get a Thread Subscription. 229 | * 230 | * This checks to see if the current user is subscribed to a thread. 231 | * You can also get a Repository subscription. 232 | * 233 | * @param integer $id The thread id. 234 | * 235 | * @return object 236 | * 237 | * @since 1.0 238 | */ 239 | public function getThreadSubscription($id) 240 | { 241 | // Build the request path. 242 | $path = '/notifications/threads/' . $id . '/subscription'; 243 | 244 | return $this->processResponse( 245 | $this->client->get($this->fetchUrl($path)) 246 | ); 247 | } 248 | 249 | /** 250 | * Set a Thread Subscription. 251 | * 252 | * This lets you subscribe to a thread, or ignore it. Subscribing to a thread is unnecessary 253 | * if the user is already subscribed to the repository. Ignoring a thread will mute all 254 | * future notifications (until you comment or get @mentioned). 255 | * 256 | * @param integer $id The thread id. 257 | * @param boolean $subscribed Determines if notifications should be received from this thread. 258 | * @param boolean $ignored Determines if all notifications should be blocked from this thread. 259 | * 260 | * @return object 261 | * 262 | * @since 1.0 263 | */ 264 | public function setThreadSubscription($id, $subscribed, $ignored) 265 | { 266 | // Build the request path. 267 | $path = '/notifications/threads/' . $id . '/subscription'; 268 | 269 | $data = [ 270 | 'subscribed' => $subscribed, 271 | 'ignored' => $ignored, 272 | ]; 273 | 274 | return $this->processResponse( 275 | $this->client->put($this->fetchUrl($path), json_encode($data)) 276 | ); 277 | } 278 | 279 | /** 280 | * Delete a Thread Subscription. 281 | * 282 | * @param integer $id The thread id. 283 | * 284 | * @return object 285 | * 286 | * @since 1.0 287 | */ 288 | public function deleteThreadSubscription($id) 289 | { 290 | // Build the request path. 291 | $path = '/notifications/threads/' . $id . '/subscription'; 292 | 293 | return $this->processResponse( 294 | $this->client->delete($this->fetchUrl($path)), 295 | 204 296 | ); 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /src/Package/Activity/Starring.php: -------------------------------------------------------------------------------- 1 | processResponse( 39 | $this->client->get($this->fetchUrl($path)) 40 | ); 41 | } 42 | 43 | /** 44 | * List repositories being starred. 45 | * 46 | * List repositories being starred by a user. 47 | * 48 | * @param string $user User name. 49 | * @param string $sort One of `created` (when the repository was starred) or `updated` (when it was last pushed to). 50 | * @param string $direction One of `asc` (ascending) or `desc` (descending). 51 | * 52 | * @return object 53 | * 54 | * @since 1.0 55 | * @throws \InvalidArgumentException 56 | */ 57 | public function getRepositories($user = '', $sort = 'created', $direction = 'desc') 58 | { 59 | $allowedSort = ['created', 'updated']; 60 | $allowedDir = ['asc', 'desc']; 61 | 62 | if (!\in_array($sort, $allowedSort)) { 63 | throw new \InvalidArgumentException( 64 | sprintf( 65 | 'The sorting value is invalid. Allowed values are: %s', 66 | implode(', ', $allowedSort) 67 | ) 68 | ); 69 | } 70 | 71 | if (!\in_array($direction, $allowedDir)) { 72 | throw new \InvalidArgumentException( 73 | sprintf( 74 | 'The direction value is invalid. Allowed values are: %s', 75 | implode(', ', $allowedDir) 76 | ) 77 | ); 78 | } 79 | 80 | // Build the request path. 81 | $path = ($user) 82 | ? '/users/' . $user . '/starred' 83 | : '/user/starred'; 84 | 85 | $uri = $this->fetchUrl($path); 86 | $uri->setVar('sort', $sort); 87 | $uri->setVar('direction', $direction); 88 | 89 | // Send the request. 90 | return $this->processResponse($this->client->get($uri)); 91 | } 92 | 93 | /** 94 | * Check if you are starring a repository. 95 | * 96 | * Requires for the user to be authenticated. 97 | * 98 | * @param string $owner Repository owner. 99 | * @param string $repo Repository name. 100 | * 101 | * @return boolean 102 | * 103 | * @since 1.0 104 | * @throws \UnexpectedValueException 105 | */ 106 | public function check($owner, $repo) 107 | { 108 | // Build the request path. 109 | $path = '/user/starred/' . $owner . '/' . $repo; 110 | 111 | $response = $this->client->get($this->fetchUrl($path)); 112 | 113 | switch ($response->code) { 114 | case '204': 115 | // This repository is watched by you. 116 | return true; 117 | 118 | case '404': 119 | // This repository is not watched by you. 120 | return false; 121 | } 122 | 123 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); 124 | } 125 | 126 | /** 127 | * Star a repository. 128 | * 129 | * Requires for the user to be authenticated. 130 | * 131 | * @param string $owner Repository owner. 132 | * @param string $repo Repository name. 133 | * 134 | * @return object 135 | * 136 | * @since 1.0 137 | */ 138 | public function star($owner, $repo) 139 | { 140 | // Build the request path. 141 | $path = '/user/starred/' . $owner . '/' . $repo; 142 | 143 | return $this->processResponse( 144 | $this->client->put($this->fetchUrl($path), ''), 145 | 204 146 | ); 147 | } 148 | 149 | /** 150 | * Unstar a repository. 151 | * 152 | * Requires for the user to be authenticated. 153 | * 154 | * @param string $owner Repository owner. 155 | * @param string $repo Repository name. 156 | * 157 | * @return object 158 | * 159 | * @since 1.0 160 | */ 161 | public function unstar($owner, $repo) 162 | { 163 | // Build the request path. 164 | $path = '/user/starred/' . $owner . '/' . $repo; 165 | 166 | return $this->processResponse( 167 | $this->client->delete($this->fetchUrl($path)), 168 | 204 169 | ); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/Package/Activity/Watching.php: -------------------------------------------------------------------------------- 1 | processResponse( 39 | $this->client->get($this->fetchUrl($path)) 40 | ); 41 | } 42 | 43 | /** 44 | * List repositories being watched. 45 | * 46 | * List repositories being watched by a user. 47 | * 48 | * @param string $user User name. 49 | * 50 | * @return mixed 51 | * 52 | * @since 1.0 53 | */ 54 | public function getRepositories($user = '') 55 | { 56 | // Build the request path. 57 | $path = ($user) 58 | ? '/users/' . $user . '/subscriptions' 59 | : '/user/subscriptions'; 60 | 61 | return $this->processResponse( 62 | $this->client->get($this->fetchUrl($path)) 63 | ); 64 | } 65 | 66 | /** 67 | * Get a Repository Subscription. 68 | * 69 | * @param string $owner Repository owner. 70 | * @param string $repo Repository name. 71 | * 72 | * @return object 73 | * 74 | * @since 1.0 75 | */ 76 | public function getSubscription($owner, $repo) 77 | { 78 | // Build the request path. 79 | $path = '/repos/' . $owner . '/' . $repo . '/subscription'; 80 | 81 | return $this->processResponse( 82 | $this->client->get($this->fetchUrl($path)) 83 | ); 84 | } 85 | 86 | /** 87 | * Set a Repository Subscription. 88 | * 89 | * @param string $owner Repository owner. 90 | * @param string $repo Repository name. 91 | * @param boolean $subscribed Determines if notifications should be received from this thread. 92 | * @param boolean $ignored Determines if all notifications should be blocked from this thread. 93 | * 94 | * @return object 95 | * 96 | * @since 1.0 97 | */ 98 | public function setSubscription($owner, $repo, $subscribed, $ignored) 99 | { 100 | // Build the request path. 101 | $path = '/repos/' . $owner . '/' . $repo . '/subscription'; 102 | 103 | $data = [ 104 | 'subscribed' => $subscribed, 105 | 'ignored' => $ignored, 106 | ]; 107 | 108 | return $this->processResponse( 109 | $this->client->put($this->fetchUrl($path), json_encode($data)) 110 | ); 111 | } 112 | 113 | /** 114 | * Delete a Repository Subscription. 115 | * 116 | * @param string $owner Repository owner. 117 | * @param string $repo Repository name. 118 | * 119 | * @return object 120 | * 121 | * @since 1.0 122 | */ 123 | public function deleteSubscription($owner, $repo) 124 | { 125 | // Build the request path. 126 | $path = '/repos/' . $owner . '/' . $repo . '/subscription'; 127 | 128 | return $this->processResponse( 129 | $this->client->delete($this->fetchUrl($path)), 130 | 204 131 | ); 132 | } 133 | 134 | /** 135 | * Check if you are watching a repository (LEGACY). 136 | * 137 | * Requires for the user to be authenticated. 138 | * 139 | * @param string $owner Repository owner. 140 | * @param string $repo Repository name. 141 | * 142 | * @return boolean 143 | * 144 | * @since 1.0 145 | * @throws \UnexpectedValueException 146 | */ 147 | public function check($owner, $repo) 148 | { 149 | // Build the request path. 150 | $path = '/user/subscriptions/' . $owner . '/' . $repo; 151 | 152 | $response = $this->client->get($this->fetchUrl($path)); 153 | 154 | switch ($response->code) { 155 | case '204': 156 | // This repository is watched by you. 157 | return true; 158 | 159 | case '404': 160 | // This repository is not watched by you. 161 | return false; 162 | } 163 | 164 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); 165 | } 166 | 167 | /** 168 | * Watch a repository (LEGACY). 169 | * 170 | * Requires for the user to be authenticated. 171 | * 172 | * @param string $owner Repository owner. 173 | * @param string $repo Repository name. 174 | * 175 | * @return object 176 | * 177 | * @since 1.0 178 | */ 179 | public function watch($owner, $repo) 180 | { 181 | // Build the request path. 182 | $path = '/user/subscriptions/' . $owner . '/' . $repo; 183 | 184 | return $this->processResponse( 185 | $this->client->put($this->fetchUrl($path), ''), 186 | 204 187 | ); 188 | } 189 | 190 | /** 191 | * Stop watching a repository (LEGACY). 192 | * 193 | * Requires for the user to be authenticated. 194 | * 195 | * @param string $owner Repository owner. 196 | * @param string $repo Repository name. 197 | * 198 | * @return object 199 | * 200 | * @since 1.0 201 | */ 202 | public function unwatch($owner, $repo) 203 | { 204 | // Build the request path. 205 | $path = '/user/subscriptions/' . $owner . '/' . $repo; 206 | 207 | return $this->processResponse( 208 | $this->client->delete($this->fetchUrl($path)), 209 | 204 210 | ); 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /src/Package/Data.php: -------------------------------------------------------------------------------- 1 | processResponse( 44 | $this->client->get($this->fetchUrl($path)) 45 | ); 46 | } 47 | 48 | /** 49 | * Create a Blob. 50 | * 51 | * @param string $owner Repository owner. 52 | * @param string $repo Repository name. 53 | * @param string $content The content of the blob. 54 | * @param string $encoding The encoding to use. 55 | * 56 | * @return object 57 | * 58 | * @since 1.0 59 | */ 60 | public function create($owner, $repo, $content, $encoding = 'utf-8') 61 | { 62 | // Build the request path. 63 | $path = '/repos/' . $owner . '/' . $repo . '/git/blobs'; 64 | 65 | $data = [ 66 | 'content' => $content, 67 | 'encoding' => $encoding, 68 | ]; 69 | 70 | return $this->processResponse( 71 | $this->client->post($this->fetchUrl($path), json_encode($data)), 72 | 201 73 | ); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Package/Data/Commits.php: -------------------------------------------------------------------------------- 1 | processResponse( 38 | $this->client->get($this->fetchUrl($path)) 39 | ); 40 | } 41 | 42 | /** 43 | * Create a Commit. 44 | * 45 | * @param string $owner The name of the owner of the GitHub repository. 46 | * @param string $repo The name of the GitHub repository. 47 | * @param string $message The commit message. 48 | * @param string $tree SHA of the tree object this commit points to. 49 | * @param array $parents Array of the SHAs of the commits that were the parents of this commit. 50 | * If omitted or empty, the commit will be written as a root commit. 51 | * For a single parent, an array of one SHA should be provided. 52 | * For a merge commit, an array of more than one should be provided. 53 | * 54 | * @since 1.0 55 | * 56 | * @return object 57 | */ 58 | public function create($owner, $repo, $message, $tree, array $parents = []) 59 | { 60 | // Build the request path. 61 | $path = '/repos/' . $owner . '/' . $repo . '/git/commits'; 62 | 63 | $data = json_encode( 64 | ['message' => $message, 'tree' => $tree, 'parents' => $parents] 65 | ); 66 | 67 | // Send the request. 68 | return $this->processResponse( 69 | $response = $this->client->post($this->fetchUrl($path), $data), 70 | 201 71 | ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Package/Data/Refs.php: -------------------------------------------------------------------------------- 1 | processResponse($this->client->get($this->fetchUrl($path))); 42 | } 43 | 44 | /** 45 | * Get all References. 46 | * 47 | * @param string $user The name of the owner of the GitHub repository. 48 | * @param string $repo The name of the GitHub repository. 49 | * @param string $namespace Optional sub-namespace to limit the returned references. 50 | * @param integer $page Page to request 51 | * @param integer $limit Number of results to return per page 52 | * 53 | * @return object 54 | * 55 | * @since 1.0 56 | * @throws \DomainException 57 | */ 58 | public function getList($user, $repo, $namespace = '', $page = 0, $limit = 0) 59 | { 60 | // Build the request path. 61 | $path = '/repos/' . $user . '/' . $repo . '/git/refs'; 62 | 63 | if (!empty($namespace)) { 64 | $path .= '/' . $namespace; 65 | } 66 | 67 | // Send the request. 68 | return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); 69 | } 70 | 71 | /** 72 | * Create a Reference. 73 | * 74 | * @param string $user The name of the owner of the GitHub repository. 75 | * @param string $repo The name of the GitHub repository. 76 | * @param string $ref The name of the fully qualified reference. 77 | * @param string $sha The SHA1 value to set this reference to. 78 | * 79 | * @return object 80 | * 81 | * @since 1.0 82 | * @throws \DomainException 83 | */ 84 | public function create($user, $repo, $ref, $sha) 85 | { 86 | // Build the request path. 87 | $path = '/repos/' . $user . '/' . $repo . '/git/refs'; 88 | 89 | // Build the request data. 90 | $data = json_encode( 91 | [ 92 | 'ref' => $ref, 93 | 'sha' => $sha, 94 | ] 95 | ); 96 | 97 | // Send the request. 98 | return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); 99 | } 100 | 101 | /** 102 | * Update a Reference. 103 | * 104 | * @param string $user The name of the owner of the GitHub repository. 105 | * @param string $repo The name of the GitHub repository. 106 | * @param string $ref The reference to update. 107 | * @param string $sha The SHA1 value to set the reference to. 108 | * @param boolean $force Whether the update should be forced. Default to false. 109 | * 110 | * @return object 111 | * 112 | * @since 1.0 113 | * @throws \DomainException 114 | */ 115 | public function edit($user, $repo, $ref, $sha, $force = false) 116 | { 117 | // Build the request path. 118 | $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref; 119 | 120 | // Create the data object. 121 | $data = new \stdClass(); 122 | 123 | // If a title is set add it to the data object. 124 | if ($force) { 125 | $data->force = true; 126 | } 127 | 128 | $data->sha = $sha; 129 | 130 | // Encode the request data. 131 | $data = json_encode($data); 132 | 133 | // Send the request. 134 | return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); 135 | } 136 | 137 | /** 138 | * Delete a Reference 139 | * 140 | * @param string $owner The name of the owner of the GitHub repository. 141 | * @param string $repo The name of the GitHub repository. 142 | * @param string $ref The reference to update. 143 | * 144 | * @return object 145 | * 146 | * @since 1.0 147 | */ 148 | public function delete($owner, $repo, $ref) 149 | { 150 | // Build the request path. 151 | $path = '/repos/' . $owner . '/' . $repo . '/git/refs/' . $ref; 152 | 153 | return $this->processResponse( 154 | $this->client->delete($this->fetchUrl($path)), 155 | 204 156 | ); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/Package/Data/Tags.php: -------------------------------------------------------------------------------- 1 | processResponse( 42 | $this->client->get($this->fetchUrl($path)) 43 | ); 44 | } 45 | 46 | /** 47 | * Create a Tag Object 48 | * 49 | * Note that creating a tag object does not create the reference that makes a tag in Git. 50 | * If you want to create an annotated tag in Git, you have to do this call to create the tag object, 51 | * and then create the refs/tags/[tag] reference. If you want to create a lightweight tag, 52 | * you simply have to create the reference - this call would be unnecessary. 53 | * 54 | * @param string $owner The name of the owner of the GitHub repository. 55 | * @param string $repo The name of the GitHub repository. 56 | * @param string $tag The tag string. 57 | * @param string $message The tag message. 58 | * @param string $object The SHA of the git object this is tagging. 59 | * @param string $type The type of the object we’re tagging. Normally this is a commit but it can also be a tree or a blob. 60 | * @param string $taggerName The name of the author of the tag. 61 | * @param string $taggerEmail The email of the author of the tag. 62 | * @param string $taggerDate Timestamp of when this object was tagged. 63 | * 64 | * @return object 65 | * 66 | * @since 1.0 67 | */ 68 | public function create($owner, $repo, $tag, $message, $object, $type, $taggerName, $taggerEmail, $taggerDate) 69 | { 70 | // Build the request path. 71 | $path = '/repos/' . $owner . '/' . $repo . '/git/tags'; 72 | 73 | $data = [ 74 | 'tag' => $tag, 75 | 'message' => $message, 76 | 'object' => $object, 77 | 'type' => $type, 78 | 'tagger' => [ 79 | 'name' => $taggerName, 80 | 'email' => $taggerEmail, 81 | 'date' => $taggerDate, 82 | ], 83 | ]; 84 | 85 | return $this->processResponse( 86 | $this->client->post($this->fetchUrl($path), json_encode($data)), 87 | 201 88 | ); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Package/Data/Trees.php: -------------------------------------------------------------------------------- 1 | processResponse( 40 | $this->client->get($this->fetchUrl($path)) 41 | ); 42 | } 43 | 44 | /** 45 | * Get a Tree Recursively 46 | * 47 | * @param string $owner The name of the owner of the GitHub repository. 48 | * @param string $repo The name of the GitHub repository. 49 | * @param string $sha The SHA1 value to set the reference to. 50 | * 51 | * @since 1.0 52 | * 53 | * @return object 54 | */ 55 | public function getRecursively($owner, $repo, $sha) 56 | { 57 | // Build the request path. 58 | $path = '/repos/' . $owner . '/' . $repo . '/git/trees/' . $sha . '?recursive=1'; 59 | 60 | return $this->processResponse( 61 | $this->client->get($this->fetchUrl($path)) 62 | ); 63 | } 64 | 65 | /** 66 | * Create a Tree. 67 | * 68 | * The tree creation API will take nested entries as well. If both a tree and a nested path 69 | * modifying that tree are specified, it will overwrite the contents of that tree with the 70 | * new path contents and write a new tree out. 71 | * 72 | * Parameters for the tree: 73 | * 74 | * tree.path 75 | * String of the file referenced in the tree 76 | * tree.mode 77 | * String of the file mode - one of 100644 for file (blob), 100755 for executable (blob), 78 | * 040000 for subdirectory (tree), 160000 for submodule (commit) or 120000 for a blob 79 | * that specifies the path of a symlink 80 | * tree.type 81 | * String of blob, tree, commit 82 | * tree.sha 83 | * String of SHA1 checksum ID of the object in the tree 84 | * tree.content 85 | * String of content you want this file to have - GitHub will write this blob out and use 86 | * that SHA for this entry. Use either this or tree.sha 87 | * 88 | * @param string $owner The name of the owner of the GitHub repository. 89 | * @param string $repo The name of the GitHub repository. 90 | * @param array $tree Array of Hash objects (of path, mode, type and sha) specifying a tree structure 91 | * @param string $baseTree The SHA1 of the tree you want to update with new data. 92 | * 93 | * @return object 94 | * 95 | * @since 1.0 96 | */ 97 | public function create($owner, $repo, $tree, $baseTree = '') 98 | { 99 | // Build the request path. 100 | $path = '/repos/' . $owner . '/' . $repo . '/git/trees'; 101 | 102 | $data = []; 103 | 104 | $data['tree'] = $tree; 105 | 106 | if ($baseTree) { 107 | $data['base_tree'] = $baseTree; 108 | } 109 | 110 | return $this->processResponse( 111 | $this->client->post($this->fetchUrl($path), json_encode($data)), 112 | 201 113 | ); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/Package/Emojis.php: -------------------------------------------------------------------------------- 1 | processResponse($this->client->get($this->fetchUrl($path))); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Package/Gists/Comments.php: -------------------------------------------------------------------------------- 1 | $body, 43 | ] 44 | ); 45 | 46 | // Send the request. 47 | return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); 48 | } 49 | 50 | /** 51 | * Delete a comment. 52 | * 53 | * @param integer $commentId The id of the comment to delete. 54 | * 55 | * @return void 56 | * 57 | * @since 1.0 58 | * @throws \DomainException 59 | */ 60 | public function delete($commentId) 61 | { 62 | // Build the request path. 63 | $path = '/gists/comments/' . (int) $commentId; 64 | 65 | // Send the request. 66 | $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); 67 | } 68 | 69 | /** 70 | * Edit a comment. 71 | * 72 | * @param integer $commentId The id of the comment to update. 73 | * @param string $body The new body text for the comment. 74 | * 75 | * @return object 76 | * 77 | * @since 1.0 78 | * @throws \DomainException 79 | */ 80 | public function edit($commentId, $body) 81 | { 82 | // Build the request path. 83 | $path = '/gists/comments/' . (int) $commentId; 84 | 85 | // Build the request data. 86 | $data = json_encode( 87 | [ 88 | 'body' => $body, 89 | ] 90 | ); 91 | 92 | // Send the request. 93 | return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); 94 | } 95 | 96 | /** 97 | * Get a single comment. 98 | * 99 | * @param integer $commentId The comment id to get. 100 | * 101 | * @return object 102 | * 103 | * @since 1.0 104 | * @throws \DomainException 105 | */ 106 | public function get($commentId) 107 | { 108 | // Build the request path. 109 | $path = '/gists/comments/' . (int) $commentId; 110 | 111 | // Send the request. 112 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 113 | } 114 | 115 | /** 116 | * List comments on a gist. 117 | * 118 | * @param integer $gistId The gist number. 119 | * @param integer $page The page number from which to get items. 120 | * @param integer $limit The number of items on a page. 121 | * 122 | * @return object 123 | * 124 | * @since 1.0 125 | * @throws \DomainException 126 | */ 127 | public function getList($gistId, $page = 0, $limit = 0) 128 | { 129 | // Build the request path. 130 | $path = '/gists/' . (int) $gistId . '/comments'; 131 | 132 | // Send the request. 133 | return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/Package/Gitignore.php: -------------------------------------------------------------------------------- 1 | processResponse( 42 | $this->client->get($this->fetchUrl($path)) 43 | ); 44 | } 45 | 46 | /** 47 | * Get a single template 48 | * 49 | * @param string $name The name of the template 50 | * @param boolean $raw Raw output 51 | * 52 | * @return mixed|string 53 | * 54 | * @since 1.0 55 | * @throws UnexpectedResponseException 56 | */ 57 | public function get($name, $raw = false) 58 | { 59 | // Build the request path. 60 | $path = '/gitignore/templates/' . $name; 61 | 62 | $headers = []; 63 | 64 | if ($raw) { 65 | $headers['Accept'] = 'application/vnd.github.raw+json'; 66 | } 67 | 68 | $response = $this->client->get($this->fetchUrl($path), $headers); 69 | 70 | // Validate the response code. 71 | if ($response->code != 200) { 72 | // Decode the error response and throw an exception. 73 | $error = json_decode($response->body); 74 | $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; 75 | 76 | throw new UnexpectedResponseException($response, $message, $response->code); 77 | } 78 | 79 | return ($raw) ? $response->body : json_decode($response->body); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Package/Graphql.php: -------------------------------------------------------------------------------- 1 | 'application/vnd.github.v4+json', 40 | 'Content-Type' => 'application/json', 41 | ]; 42 | 43 | $data = [ 44 | 'query' => $query, 45 | ]; 46 | 47 | if (!empty($variables)) { 48 | $data['variables'] = $variables; 49 | } 50 | 51 | // Send the request. 52 | return $this->processResponse( 53 | $this->client->post($this->fetchUrl($path), json_encode($data), $headers) 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Package/Issues/Assignees.php: -------------------------------------------------------------------------------- 1 | processResponse( 42 | $this->client->get($this->fetchUrl($path)) 43 | ); 44 | } 45 | 46 | /** 47 | * Check assignee. 48 | * 49 | * You may check to see if a particular user is an assignee for a repository. 50 | * If the given assignee login belongs to an assignee for the repository, a 204 header 51 | * with no content is returned. 52 | * Otherwise a 404 status code is returned. 53 | * 54 | * @param string $owner The name of the owner of the GitHub repository. 55 | * @param string $repo The name of the GitHub repository. 56 | * @param string $assignee The assignees login name. 57 | * 58 | * @return boolean 59 | * 60 | * @since 1.0 61 | * @throws \DomainException 62 | */ 63 | public function check($owner, $repo, $assignee) 64 | { 65 | // Build the request path. 66 | $path = '/repos/' . $owner . '/' . $repo . '/assignees/' . $assignee; 67 | 68 | try { 69 | $response = $this->client->get($this->fetchUrl($path)); 70 | 71 | if ($response->code == 204) { 72 | return true; 73 | } 74 | 75 | throw new UnexpectedResponseException($response, 'Invalid response: ' . $response->code); 76 | } catch (\DomainException $e) { 77 | if (isset($response->code) && $response->code == 404) { 78 | return false; 79 | } 80 | 81 | throw $e; 82 | } 83 | } 84 | 85 | /** 86 | * Add assignees to an Issue 87 | * 88 | * This call adds the users passed in the assignees key (as their logins) to the issue. 89 | * 90 | * @param string $owner The name of the owner of the GitHub repository. 91 | * @param string $repo The name of the GitHub repository. 92 | * @param integer $number The issue number to add assignees to. 93 | * @param string[] $assignees The logins for GitHub users to assign to this issue. 94 | * 95 | * @return object 96 | * 97 | * @since 1.4.0 98 | * @throws \DomainException 99 | */ 100 | public function add($owner, $repo, $number, array $assignees) 101 | { 102 | // Build the request path. 103 | $path = "/repos/$owner/$repo/issues/$number/assignees"; 104 | 105 | $data = json_encode( 106 | [ 107 | 'assignees' => $assignees, 108 | ] 109 | ); 110 | 111 | return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); 112 | } 113 | 114 | /** 115 | * Remove assignees from an Issue 116 | * 117 | * This call removes the users passed in the assignees key (as their logins) from the issue. 118 | * 119 | * @param string $owner The name of the owner of the GitHub repository. 120 | * @param string $repo The name of the GitHub repository. 121 | * @param integer $number The issue number to add assignees to. 122 | * @param string[] $assignees The logins for GitHub users to assign to this issue. 123 | * 124 | * @return object 125 | * 126 | * @since 1.4.0 127 | * @throws \DomainException 128 | */ 129 | public function remove($owner, $repo, $number, array $assignees) 130 | { 131 | // Build the request path. 132 | $path = "/repos/$owner/$repo/issues/$number/assignees"; 133 | 134 | $data = json_encode( 135 | [ 136 | 'assignees' => $assignees, 137 | ] 138 | ); 139 | 140 | return $this->processResponse($this->client->delete($this->fetchUrl($path), [], null, $data)); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/Package/Issues/Comments.php: -------------------------------------------------------------------------------- 1 | fetchUrl($path, $page, $limit); 47 | 48 | if ($since) { 49 | $uri->setVar('since', $since->format(\DateTime::RFC3339)); 50 | } 51 | 52 | // Send the request. 53 | return $this->processResponse($this->client->get($uri)); 54 | } 55 | 56 | /** 57 | * List comments in a repository. 58 | * 59 | * @param string $owner The name of the owner of the GitHub repository. 60 | * @param string $repo The name of the GitHub repository. 61 | * @param string $sort The sort field - created or updated. 62 | * @param string $direction The sort order- asc or desc. Ignored without sort parameter. 63 | * @param ?\DateTimeInterface $since Only comments updated at or after this time are returned. 64 | * 65 | * @return object 66 | * 67 | * @since 1.0 68 | * @throws \UnexpectedValueException 69 | * @throws \DomainException 70 | */ 71 | public function getRepositoryList($owner, $repo, $sort = 'created', $direction = 'asc', \DateTimeInterface $since = null) 72 | { 73 | // Build the request path. 74 | $path = '/repos/' . $owner . '/' . $repo . '/issues/comments'; 75 | 76 | if (\in_array($sort, ['created', 'updated']) == false) { 77 | throw new \UnexpectedValueException( 78 | sprintf( 79 | '%1$s - sort field must be "created" or "updated"', 80 | __METHOD__ 81 | ) 82 | ); 83 | } 84 | 85 | if (\in_array($direction, ['asc', 'desc']) == false) { 86 | throw new \UnexpectedValueException( 87 | sprintf( 88 | '%1$s - direction field must be "asc" or "desc"', 89 | __METHOD__ 90 | ) 91 | ); 92 | } 93 | 94 | $uri = $this->fetchUrl($path); 95 | $uri->setVar('sort', $sort); 96 | $uri->setVar('direction', $direction); 97 | 98 | if ($since) { 99 | $uri->setVar('since', $since->format(\DateTime::RFC3339)); 100 | } 101 | 102 | // Send the request. 103 | return $this->processResponse($this->client->get($uri)); 104 | } 105 | 106 | /** 107 | * Get a single comment. 108 | * 109 | * @param string $owner The name of the owner of the GitHub repository. 110 | * @param string $repo The name of the GitHub repository. 111 | * @param integer $id The comment id. 112 | * 113 | * @return object 114 | * 115 | * @since 1.0 116 | * @throws \DomainException 117 | */ 118 | public function get($owner, $repo, $id) 119 | { 120 | // Build the request path. 121 | $path = '/repos/' . $owner . '/' . $repo . '/issues/comments/' . (int) $id; 122 | 123 | // Send the request. 124 | return $this->processResponse( 125 | $this->client->get($this->fetchUrl($path)) 126 | ); 127 | } 128 | 129 | /** 130 | * Edit a comment. 131 | * 132 | * @param string $user The name of the owner of the GitHub repository. 133 | * @param string $repo The name of the GitHub repository. 134 | * @param integer $commentId The id of the comment to update. 135 | * @param string $body The new body text for the comment. 136 | * 137 | * @return object 138 | * 139 | * @since 1.0 140 | * @throws \DomainException 141 | */ 142 | public function edit($user, $repo, $commentId, $body) 143 | { 144 | // Build the request path. 145 | $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; 146 | 147 | // Build the request data. 148 | $data = json_encode( 149 | [ 150 | 'body' => $body, 151 | ] 152 | ); 153 | 154 | // Send the request. 155 | return $this->processResponse( 156 | $this->client->patch($this->fetchUrl($path), $data) 157 | ); 158 | } 159 | 160 | /** 161 | * Create a comment. 162 | * 163 | * @param string $user The name of the owner of the GitHub repository. 164 | * @param string $repo The name of the GitHub repository. 165 | * @param integer $issueId The issue number. 166 | * @param string $body The comment body text. 167 | * 168 | * @return object 169 | * 170 | * @since 1.0 171 | * @throws \DomainException 172 | */ 173 | public function create($user, $repo, $issueId, $body) 174 | { 175 | // Build the request path. 176 | $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; 177 | 178 | // Build the request data. 179 | $data = json_encode( 180 | [ 181 | 'body' => $body, 182 | ] 183 | ); 184 | 185 | // Send the request. 186 | return $this->processResponse( 187 | $this->client->post($this->fetchUrl($path), $data), 188 | 201 189 | ); 190 | } 191 | 192 | /** 193 | * Delete a comment. 194 | * 195 | * @param string $user The name of the owner of the GitHub repository. 196 | * @param string $repo The name of the GitHub repository. 197 | * @param integer $commentId The id of the comment to delete. 198 | * 199 | * @return boolean 200 | * 201 | * @since 1.0 202 | * @throws \DomainException 203 | */ 204 | public function delete($user, $repo, $commentId) 205 | { 206 | // Build the request path. 207 | $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; 208 | 209 | // Send the request. 210 | $this->processResponse( 211 | $this->client->delete($this->fetchUrl($path)), 212 | 204 213 | ); 214 | 215 | return true; 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /src/Package/Issues/Events.php: -------------------------------------------------------------------------------- 1 | processResponse( 45 | $this->client->get($this->fetchUrl($path, $page, $limit)) 46 | ); 47 | } 48 | 49 | /** 50 | * List events for a repository. 51 | * 52 | * @param string $owner The name of the owner of the GitHub repository. 53 | * @param string $repo The name of the GitHub repository. 54 | * @param integer $issueId The issue number. 55 | * @param integer $page The page number from which to get items. 56 | * @param integer $limit The number of items on a page. 57 | * 58 | * @return object 59 | */ 60 | public function getListRepository($owner, $repo, $issueId, $page = 0, $limit = 0) 61 | { 62 | // Build the request path. 63 | $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; 64 | 65 | // Send the request. 66 | return $this->processResponse( 67 | $this->client->get($this->fetchUrl($path, $page, $limit)) 68 | ); 69 | } 70 | 71 | /** 72 | * Get a single event. 73 | * 74 | * @param string $owner The name of the owner of the GitHub repository. 75 | * @param string $repo The name of the GitHub repository. 76 | * @param integer $id The event number. 77 | * 78 | * @return object 79 | */ 80 | public function get($owner, $repo, $id) 81 | { 82 | // Build the request path. 83 | $path = '/repos/' . $owner . '/' . $repo . '/issues/events/' . (int) $id; 84 | 85 | // Send the request. 86 | return $this->processResponse( 87 | $this->client->get($this->fetchUrl($path)) 88 | ); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Package/Issues/Labels.php: -------------------------------------------------------------------------------- 1 | processResponse( 40 | $response = $this->client->get($this->fetchUrl($path)) 41 | ); 42 | } 43 | 44 | /** 45 | * Get a single label. 46 | * 47 | * @param string $user The name of the owner of the GitHub repository. 48 | * @param string $repo The name of the GitHub repository. 49 | * @param string $name The label name to get. 50 | * 51 | * @return object 52 | * 53 | * @since 1.0 54 | */ 55 | public function get($user, $repo, $name) 56 | { 57 | // Build the request path. 58 | $path = '/repos/' . $user . '/' . $repo . '/labels/' . rawurlencode($name); 59 | 60 | // Send the request. 61 | return $this->processResponse( 62 | $response = $this->client->get($this->fetchUrl($path)) 63 | ); 64 | } 65 | 66 | /** 67 | * Create a label. 68 | * 69 | * @param string $owner The name of the owner of the GitHub repository. 70 | * @param string $repo The name of the GitHub repository. 71 | * @param string $name The label name. 72 | * @param string $color The label color. 73 | * 74 | * @return object 75 | * 76 | * @since 1.0 77 | * @throws \DomainException 78 | */ 79 | public function create($owner, $repo, $name, $color) 80 | { 81 | // Build the request path. 82 | $path = '/repos/' . $owner . '/' . $repo . '/labels'; 83 | 84 | // Build the request data. 85 | $data = json_encode( 86 | [ 87 | 'name' => $name, 88 | 'color' => $color, 89 | ] 90 | ); 91 | 92 | // Send the request. 93 | return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); 94 | } 95 | 96 | /** 97 | * Delete a label. 98 | * 99 | * @param string $owner The name of the owner of the GitHub repository. 100 | * @param string $repo The name of the GitHub repository. 101 | * @param string $name The label name. 102 | * 103 | * @return object 104 | * 105 | * @since 1.0 106 | */ 107 | public function delete($owner, $repo, $name) 108 | { 109 | // Build the request path. 110 | $path = '/repos/' . $owner . '/' . $repo . '/labels/' . rawurlencode($name); 111 | 112 | // Send the request. 113 | return $this->processResponse( 114 | $this->client->delete($this->fetchUrl($path)), 115 | 204 116 | ); 117 | } 118 | 119 | /** 120 | * Update a label. 121 | * 122 | * @param string $user The name of the owner of the GitHub repository. 123 | * @param string $repo The name of the GitHub repository. 124 | * @param string $label The label name. 125 | * @param string $name The new label name. 126 | * @param string $color The new label color. 127 | * 128 | * @return object 129 | * 130 | * @since 1.0 131 | */ 132 | public function update($user, $repo, $label, $name, $color) 133 | { 134 | // Build the request path. 135 | $path = '/repos/' . $user . '/' . $repo . '/labels/' . $label; 136 | 137 | // Build the request data. 138 | $data = json_encode( 139 | [ 140 | 'name' => $name, 141 | 'color' => $color, 142 | ] 143 | ); 144 | 145 | // Send the request. 146 | return $this->processResponse( 147 | $this->client->patch($this->fetchUrl($path), $data) 148 | ); 149 | } 150 | 151 | /** 152 | * List labels on an issue. 153 | * 154 | * @param string $owner The name of the owner of the GitHub repository. 155 | * @param string $repo The name of the GitHub repository. 156 | * @param integer $number The issue number. 157 | * 158 | * @return object 159 | * 160 | * @since 1.0 161 | */ 162 | public function getListByIssue($owner, $repo, $number) 163 | { 164 | // Build the request path. 165 | $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; 166 | 167 | // Send the request. 168 | return $this->processResponse( 169 | $this->client->get($this->fetchUrl($path)) 170 | ); 171 | } 172 | 173 | /** 174 | * Add labels to an issue. 175 | * 176 | * @param string $owner The name of the owner of the GitHub repository. 177 | * @param string $repo The name of the GitHub repository. 178 | * @param string $number The issue number. 179 | * @param array $labels An array of labels to add. 180 | * 181 | * @return object 182 | * 183 | * @since 1.0 184 | */ 185 | public function add($owner, $repo, $number, array $labels) 186 | { 187 | // Build the request path. 188 | $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; 189 | 190 | // Send the request. 191 | return $this->processResponse( 192 | $this->client->post($this->fetchUrl($path), json_encode($labels)) 193 | ); 194 | } 195 | 196 | /** 197 | * Remove a label from an issue. 198 | * 199 | * @param string $owner The name of the owner of the GitHub repository. 200 | * @param string $repo The name of the GitHub repository. 201 | * @param string $number The issue number. 202 | * @param string $name The name of the label to remove. 203 | * 204 | * @return object 205 | * 206 | * @since 1.0 207 | */ 208 | public function removeFromIssue($owner, $repo, $number, $name) 209 | { 210 | // Build the request path. 211 | $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels/' . rawurlencode($name); 212 | 213 | // Send the request. 214 | return $this->processResponse( 215 | $this->client->delete($this->fetchUrl($path)) 216 | ); 217 | } 218 | 219 | /** 220 | * Replace all labels for an issue. 221 | * 222 | * Sending an empty array ([]) will remove all Labels from the Issue. 223 | * 224 | * @param string $owner The name of the owner of the GitHub repository. 225 | * @param string $repo The name of the GitHub repository. 226 | * @param string $number The issue number. 227 | * @param array $labels New labels 228 | * 229 | * @return object 230 | * 231 | * @since 1.0 232 | */ 233 | public function replace($owner, $repo, $number, array $labels) 234 | { 235 | // Build the request path. 236 | $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; 237 | 238 | // Send the request. 239 | return $this->processResponse( 240 | $this->client->put($this->fetchUrl($path), json_encode($labels)) 241 | ); 242 | } 243 | 244 | /** 245 | * Remove all labels from an issue. 246 | * 247 | * @param string $owner The name of the owner of the GitHub repository. 248 | * @param string $repo The name of the GitHub repository. 249 | * @param string $number The issue number. 250 | * 251 | * @return object 252 | * 253 | * @since 1.0 254 | */ 255 | public function removeAllFromIssue($owner, $repo, $number) 256 | { 257 | // Build the request path. 258 | $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; 259 | 260 | // Send the request. 261 | return $this->processResponse( 262 | $this->client->delete($this->fetchUrl($path)), 263 | 204 264 | ); 265 | } 266 | 267 | /** 268 | * Get labels for every issue in a milestone. 269 | * 270 | * @param string $owner The name of the owner of the GitHub repository. 271 | * @param string $repo The name of the GitHub repository. 272 | * @param string $number The issue number. 273 | * 274 | * @return object 275 | * 276 | * @since 1.0 277 | */ 278 | public function getListByMilestone($owner, $repo, $number) 279 | { 280 | // Build the request path. 281 | $path = '/repos/' . $owner . '/' . $repo . '/milestones/' . $number . '/labels'; 282 | 283 | // Send the request. 284 | return $this->processResponse( 285 | $this->client->get($this->fetchUrl($path)) 286 | ); 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/Package/Issues/Milestones.php: -------------------------------------------------------------------------------- 1 | fetchUrl($path, $page, $limit); 45 | $uri->setVar('state', $state); 46 | $uri->setVar('sort', $sort); 47 | $uri->setVar('direction', $direction); 48 | 49 | // Send the request. 50 | return $this->processResponse($this->client->get($uri)); 51 | } 52 | 53 | /** 54 | * Get a single milestone. 55 | * 56 | * @param string $user The name of the owner of the GitHub repository. 57 | * @param string $repo The name of the GitHub repository. 58 | * @param integer $milestoneId The milestone id to get. 59 | * 60 | * @return object 61 | * 62 | * @since 1.0 63 | * @throws \DomainException 64 | */ 65 | public function get($user, $repo, $milestoneId) 66 | { 67 | // Build the request path. 68 | $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; 69 | 70 | // Send the request. 71 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 72 | } 73 | 74 | /** 75 | * Create a milestone. 76 | * 77 | * @param string $user The name of the owner of the GitHub repository. 78 | * @param string $repo The name of the GitHub repository. 79 | * @param integer $title The title of the milestone. 80 | * @param string $state Can be open (default) or closed. 81 | * @param string $description Optional description for milestone. 82 | * @param string $dueOn The milestone due date. This is a timestamp in ISO 8601 format. 83 | * 84 | * @return object 85 | * 86 | * @note As of 2.0 the $dueOn parameter will be typehinted to a \DateTime object 87 | * @since 1.0 88 | * @throws \DomainException 89 | */ 90 | public function create($user, $repo, $title, $state = null, $description = null, $dueOn = null) 91 | { 92 | // Build the request path. 93 | $path = '/repos/' . $user . '/' . $repo . '/milestones'; 94 | 95 | // Build the request data. 96 | $data = [ 97 | 'title' => $title, 98 | ]; 99 | 100 | if ($state !== null) { 101 | $data['state'] = $state; 102 | } 103 | 104 | if ($description !== null) { 105 | $data['description'] = $description; 106 | } 107 | 108 | if ($dueOn !== null) { 109 | $data['due_on'] = $dueOn; 110 | } 111 | 112 | $data = json_encode($data); 113 | 114 | // Send the request. 115 | return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); 116 | } 117 | 118 | /** 119 | * Update a milestone. 120 | * 121 | * @param string $user The name of the owner of the GitHub repository. 122 | * @param string $repo The name of the GitHub repository. 123 | * @param integer $milestoneId The id of the comment to update. 124 | * @param integer $title Optional title of the milestone. 125 | * @param string $state Can be open (default) or closed. 126 | * @param string $description Optional description for milestone. 127 | * @param string $dueOn The milestone due date. This is a timestamp in ISO 8601 format. 128 | * 129 | * @return object 130 | * 131 | * @note As of 2.0 the $dueOn parameter will be typehinted to a \DateTime object 132 | * @since 1.0 133 | * @throws \DomainException 134 | */ 135 | public function edit($user, $repo, $milestoneId, $title = null, $state = null, $description = null, $dueOn = null) 136 | { 137 | // Build the request path. 138 | $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; 139 | 140 | // Build the request data. 141 | $data = []; 142 | 143 | if ($title !== null) { 144 | $data['title'] = $title; 145 | } 146 | 147 | if ($state !== null) { 148 | $data['state'] = $state; 149 | } 150 | 151 | if ($description !== null) { 152 | $data['description'] = $description; 153 | } 154 | 155 | if ($dueOn !== null) { 156 | $data['due_on'] = $dueOn; 157 | } 158 | 159 | $data = json_encode($data); 160 | 161 | // Send the request. 162 | return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); 163 | } 164 | 165 | /** 166 | * Delete a milestone. 167 | * 168 | * @param string $user The name of the owner of the GitHub repository. 169 | * @param string $repo The name of the GitHub repository. 170 | * @param integer $milestoneId The id of the milestone to delete. 171 | * 172 | * @return void 173 | * 174 | * @since 1.0 175 | * @throws \DomainException 176 | */ 177 | public function delete($user, $repo, $milestoneId) 178 | { 179 | // Build the request path. 180 | $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; 181 | 182 | // Send the request. 183 | $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /src/Package/Markdown.php: -------------------------------------------------------------------------------- 1 | $text, 57 | 'mode' => $mode, 58 | 'context' => $context, 59 | ] 60 | ) 61 | ); 62 | 63 | // Send the request. 64 | $response = $this->client->post($this->fetchUrl($path), $data); 65 | 66 | // Validate the response code. 67 | if ($response->code != 200) { 68 | // Decode the error response and throw an exception. 69 | $error = json_decode($response->body); 70 | $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; 71 | 72 | throw new UnexpectedResponseException($response, $message, $response->code); 73 | } 74 | 75 | return $response->body; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Package/Meta.php: -------------------------------------------------------------------------------- 1 | processResponse($this->client->get($this->fetchUrl($path)), 200); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Package/Orgs.php: -------------------------------------------------------------------------------- 1 | processResponse( 47 | $this->client->get($this->fetchUrl($path)) 48 | ); 49 | } 50 | 51 | /** 52 | * Get an organization. 53 | * 54 | * @param string $org The organization name. 55 | * 56 | * @return object 57 | * 58 | * @since 1.0 59 | */ 60 | public function get($org) 61 | { 62 | // Build the request path. 63 | $path = '/orgs/' . $org; 64 | 65 | // Send the request. 66 | return $this->processResponse( 67 | $this->client->get($this->fetchUrl($path)) 68 | ); 69 | } 70 | 71 | /** 72 | * Edit an organization. 73 | * 74 | * @param string $org The organization name. 75 | * @param string $billingEmail Billing email address. This address is not publicized. 76 | * @param string $company The company name. 77 | * @param string $email The email address. 78 | * @param string $location The location name. 79 | * @param string $name The name. 80 | * 81 | * @return object 82 | * 83 | * @since 1.0 84 | */ 85 | public function edit($org, $billingEmail = '', $company = '', $email = '', $location = '', $name = '') 86 | { 87 | // Build the request path. 88 | $path = '/orgs/' . $org; 89 | 90 | $args = ['billing_email', 'company', 'email', 'location', 'name']; 91 | 92 | $data = []; 93 | 94 | $fArgs = \func_get_args(); 95 | 96 | foreach ($args as $i => $arg) { 97 | if (array_key_exists($i + 1, $fArgs) && $fArgs[$i + 1]) { 98 | $data[$arg] = $fArgs[$i + 1]; 99 | } 100 | } 101 | 102 | // Send the request. 103 | return $this->processResponse( 104 | $this->client->patch($this->fetchUrl($path), $data) 105 | ); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Package/Orgs/Hooks.php: -------------------------------------------------------------------------------- 1 | processResponse( 41 | $this->client->get($this->fetchUrl($path)) 42 | ); 43 | } 44 | 45 | /** 46 | * Get single hook. 47 | * 48 | * @param string $org The name of the organization. 49 | * @param integer $id The hook id. 50 | * 51 | * @return object 52 | * 53 | * @since 1.4.0 54 | */ 55 | public function get($org, $id) 56 | { 57 | // Build the request path. 58 | $path = "/orgs/$org/hooks/" . (int) $id; 59 | 60 | return $this->processResponse( 61 | $this->client->get($this->fetchUrl($path)) 62 | ); 63 | } 64 | 65 | /** 66 | * Create a hook. 67 | * 68 | * @param string $org The name of the organization. 69 | * @param string $url The URL to which the payloads will be delivered. 70 | * @param string $contentType The media type used to serialize the payloads. Supported values include "json" and "form". 71 | * @param string $secret If provided, payloads will be delivered with an X-Hub-Signature header. 72 | * The value of this header is computed as the 73 | * [HMAC hex digest of the body, using the secret as the key][hub-signature]. 74 | * @param boolean $insecureSsl Determines whether the SSL certificate of the host for url will be verified when delivering payloads. 75 | * If false, verification is performed. If true, verification is not performed. 76 | * @param array $events Determines what events the hook is triggered for. 77 | * @param boolean $active Determines whether the hook is actually triggered on pushes. 78 | * 79 | * @return object 80 | * 81 | * @since 1.4.0 82 | * @throws \UnexpectedValueException 83 | */ 84 | public function create($org, $url, $contentType = 'form', $secret = null, $insecureSsl = false, array $events = ['push'], $active = true) 85 | { 86 | // Build the request path. 87 | $path = "/orgs/$org/hooks"; 88 | 89 | if (\in_array($contentType, ['form', 'json']) == false) { 90 | throw new \UnexpectedValueException('Content type must be either "form" or "json".'); 91 | } 92 | 93 | $config = [ 94 | 'url' => $url, 95 | 'content_type' => $contentType, 96 | 'insecure_ssl' => (int) $insecureSsl, 97 | ]; 98 | 99 | if ($secret) { 100 | $config['secret'] = $secret; 101 | } 102 | 103 | $data = [ 104 | 'name' => 'web', 105 | 'active' => $active, 106 | 'config' => (object) $config, 107 | ]; 108 | 109 | if (!empty($events)) { 110 | // Check to ensure all events are in the allowed list 111 | foreach ($events as $event) { 112 | if (!\in_array($event, $this->hookEvents)) { 113 | throw new \RuntimeException('Your events array contains an unauthorized event.'); 114 | } 115 | } 116 | 117 | $data['events'] = $events; 118 | } 119 | 120 | return $this->processResponse( 121 | $this->client->post($this->fetchUrl($path), $data), 122 | 201 123 | ); 124 | } 125 | 126 | /** 127 | * Edit a hook. 128 | * 129 | * @param string $org The name of the organization. 130 | * @param string $url The URL to which the payloads will be delivered. 131 | * @param string $contentType The media type used to serialize the payloads. Supported values include "json" and "form". 132 | * @param string $secret If provided, payloads will be delivered with an X-Hub-Signature header. 133 | * The value of this header is computed as the 134 | * [HMAC hex digest of the body, using the secret as the key][hub-signature]. 135 | * @param boolean $insecureSsl Determines whether the SSL certificate of the host for url will be verified when delivering payloads. 136 | * If false, verification is performed. If true, verification is not performed. 137 | * @param array $events Determines what events the hook is triggered for. 138 | * @param boolean $active Determines whether the hook is actually triggered on pushes. 139 | * 140 | * @return object 141 | * 142 | * @since 1.4.0 143 | * @throws \UnexpectedValueException 144 | */ 145 | public function edit($org, $url, $contentType = null, $secret = null, $insecureSsl = null, array $events = [], $active = null) 146 | { 147 | // Build the request path. 148 | $path = "/orgs/$org/hooks"; 149 | 150 | $config = [ 151 | 'url' => $url, 152 | ]; 153 | 154 | if ($contentType) { 155 | if (\in_array($contentType, ['form', 'json']) == false) { 156 | throw new \UnexpectedValueException('Content type must be either "form" or "json".'); 157 | } 158 | 159 | $config['content_type'] = $contentType; 160 | } 161 | 162 | if ($insecureSsl !== null) { 163 | $config['insecure_ssl'] = (int) $insecureSsl; 164 | } 165 | 166 | if ($secret) { 167 | $config['secret'] = $secret; 168 | } 169 | 170 | $data = [ 171 | 'config' => (object) $config, 172 | ]; 173 | 174 | if ($active !== null) { 175 | $data['active'] = (bool) $active; 176 | } 177 | 178 | if (!empty($events)) { 179 | // Check to ensure all events are in the allowed list 180 | foreach ($events as $event) { 181 | if (!\in_array($event, $this->hookEvents)) { 182 | throw new \RuntimeException('Your events array contains an unauthorized event.'); 183 | } 184 | } 185 | 186 | $data['events'] = $events; 187 | } 188 | 189 | return $this->processResponse( 190 | $this->client->post($this->fetchUrl($path), $data), 191 | 201 192 | ); 193 | } 194 | 195 | /** 196 | * Ping a hook. 197 | * 198 | * @param string $org The name of the organization 199 | * @param integer $id ID of the hook to ping 200 | * 201 | * @return object 202 | * 203 | * @since 1.4.0 204 | * @throws \DomainException 205 | */ 206 | public function ping($org, $id) 207 | { 208 | // Build the request path. 209 | $path = "/orgs/$org/hooks/$id/pings"; 210 | 211 | return $this->processResponse( 212 | $this->client->post($this->fetchUrl($path), json_encode('')), 213 | 204 214 | ); 215 | } 216 | 217 | /** 218 | * Delete a hook. 219 | * 220 | * @param string $org The name of the organization 221 | * @param integer $id ID of the hook to delete 222 | * 223 | * @return object 224 | * 225 | * @since 1.4.0 226 | */ 227 | public function delete($org, $id) 228 | { 229 | // Build the request path. 230 | $path = "/orgs/$org/hooks/$id"; 231 | 232 | return $this->processResponse( 233 | $this->client->delete($this->fetchUrl($path)), 234 | 204 235 | ); 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /src/Package/Orgs/Members.php: -------------------------------------------------------------------------------- 1 | client->get($this->fetchUrl($path)); 46 | 47 | switch ($response->code) { 48 | case 302: 49 | // Requester is not an organization member. 50 | return false; 51 | 52 | case 200: 53 | return json_decode($response->body); 54 | 55 | default: 56 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); 57 | } 58 | } 59 | 60 | /** 61 | * Check membership. 62 | * 63 | * Check if a user is, publicly or privately, a member of the organization. 64 | * 65 | * @param string $org The name of the organization. 66 | * @param string $user The name of the user. 67 | * 68 | * @throws \UnexpectedValueException 69 | * @since 1.0 70 | * 71 | * @return boolean 72 | */ 73 | public function check($org, $user) 74 | { 75 | // Build the request path. 76 | $path = '/orgs/' . $org . '/members/' . $user; 77 | 78 | $response = $this->client->get($this->fetchUrl($path)); 79 | 80 | switch ($response->code) { 81 | case 204: 82 | // Requester is an organization member and user is a member. 83 | return true; 84 | 85 | case 404: 86 | // Requester is an organization member and user is not a member. 87 | // Requester is not an organization member and is inquiring about themselves. 88 | return false; 89 | 90 | case 302: 91 | // Requester is not an organization member. 92 | return false; 93 | 94 | default: 95 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); 96 | } 97 | } 98 | 99 | /** 100 | * Add a member. 101 | * 102 | * To add someone as a member to an org, you must add them to a team. 103 | */ 104 | 105 | /** 106 | * Remove a member. 107 | * 108 | * Removing a user from this list will remove them from all teams and they will no longer have 109 | * any access to the organization’s repositories. 110 | * 111 | * @param string $org The name of the organization. 112 | * @param string $user The name of the user. 113 | * 114 | * @since 1.0 115 | * 116 | * @return object 117 | */ 118 | public function remove($org, $user) 119 | { 120 | // Build the request path. 121 | $path = '/orgs/' . $org . '/members/' . $user; 122 | 123 | return $this->processResponse( 124 | $this->client->delete($this->fetchUrl($path)), 125 | 204 126 | ); 127 | } 128 | 129 | /** 130 | * Public members list. 131 | * 132 | * Members of an organization can choose to have their membership publicized or not. 133 | * 134 | * @param string $org The name of the organization. 135 | * 136 | * @since 1.0 137 | * 138 | * @return object 139 | */ 140 | public function getListPublic($org) 141 | { 142 | // Build the request path. 143 | $path = '/orgs/' . $org . '/public_members'; 144 | 145 | return $this->processResponse( 146 | $this->client->get($this->fetchUrl($path)) 147 | ); 148 | } 149 | 150 | /** 151 | * Check public membership. 152 | * 153 | * @param string $org The name of the organization. 154 | * @param string $user The name of the user. 155 | * 156 | * @throws \UnexpectedValueException 157 | * @since 1.0 158 | * 159 | * @return boolean 160 | */ 161 | public function checkPublic($org, $user) 162 | { 163 | // Build the request path. 164 | $path = '/orgs/' . $org . '/public_members/' . $user; 165 | 166 | $response = $this->client->get($this->fetchUrl($path)); 167 | 168 | switch ($response->code) { 169 | case 204: 170 | // Response if user is a public member. 171 | return true; 172 | 173 | case 404: 174 | // Response if user is not a public member. 175 | return false; 176 | 177 | default: 178 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); 179 | } 180 | } 181 | 182 | /** 183 | * Publicize a user’s membership. 184 | * 185 | * @param string $org The name of the organization. 186 | * @param string $user The name of the user. 187 | * 188 | * @since 1.0 189 | * 190 | * @return object 191 | */ 192 | public function publicize($org, $user) 193 | { 194 | // Build the request path. 195 | $path = '/orgs/' . $org . '/public_members/' . $user; 196 | 197 | return $this->processResponse( 198 | $this->client->put($this->fetchUrl($path), ''), 199 | 204 200 | ); 201 | } 202 | 203 | /** 204 | * Conceal a user’s membership. 205 | * 206 | * @param string $org The name of the organization. 207 | * @param string $user The name of the user. 208 | * 209 | * @since 1.0 210 | * 211 | * @return object 212 | */ 213 | public function conceal($org, $user) 214 | { 215 | // Build the request path. 216 | $path = '/orgs/' . $org . '/public_members/' . $user; 217 | 218 | return $this->processResponse( 219 | $this->client->delete($this->fetchUrl($path)), 220 | 204 221 | ); 222 | } 223 | 224 | /** 225 | * Get organization membership 226 | * 227 | * In order to get a user's membership with an organization, the authenticated user must be an organization owner. 228 | * 229 | * @param string $org The name of the organization. 230 | * @param string $user The name of the user. 231 | * 232 | * @return object 233 | * 234 | * @since 1.4.0 235 | */ 236 | public function getMembership($org, $user) 237 | { 238 | // Build the request path. 239 | $path = '/orgs/' . $org . '/memberships/' . $user; 240 | 241 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 242 | } 243 | 244 | /** 245 | * Add or update organization membership 246 | * 247 | * In order to create or update a user's membership with an organization, the authenticated user must be an organization owner. 248 | * 249 | * @param string $org The name of the organization. 250 | * @param string $user The name of the user. 251 | * @param string $role The role to give the user in the organization. Can be either 'member' or 'admin'. 252 | * 253 | * @return object 254 | * 255 | * @since 1.4.0 256 | */ 257 | public function updateMembership($org, $user, $role = 'member') 258 | { 259 | $allowedRoles = ['member', 'admin']; 260 | 261 | if (!\in_array($role, $allowedRoles)) { 262 | throw new \InvalidArgumentException(sprintf("The user's role must be: %s", implode(', ', $allowedRoles))); 263 | } 264 | 265 | // Build the request path. 266 | $path = "/orgs/$org/memberships/$user"; 267 | 268 | $data = [ 269 | 'role' => $role, 270 | ]; 271 | 272 | return $this->processResponse($this->client->put($this->fetchUrl($path), json_encode($data))); 273 | } 274 | 275 | /** 276 | * Remove organization membership 277 | * 278 | * In order to remove a user's membership with an organization, the authenticated user must be an organization owner. 279 | * 280 | * @param string $org The name of the organization. 281 | * @param string $user The name of the user. 282 | * 283 | * @return object 284 | * 285 | * @since 1.4.0 286 | */ 287 | public function removeMembership($org, $user) 288 | { 289 | // Build the request path. 290 | $path = '/orgs/' . $org . '/memberships/' . $user; 291 | 292 | return $this->processResponse( 293 | $this->client->delete($this->fetchUrl($path)), 294 | 204 295 | ); 296 | } 297 | 298 | /** 299 | * List your organization memberships 300 | * 301 | * @return object 302 | * 303 | * @since 1.4.0 304 | */ 305 | public function listMemberships() 306 | { 307 | // Build the request path. 308 | $path = '/user/memberships/orgs'; 309 | 310 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 311 | } 312 | 313 | /** 314 | * Get your organization membership 315 | * 316 | * @param string $org The name of the organization. 317 | * 318 | * @return object 319 | * 320 | * @since 1.4.0 321 | */ 322 | public function listOrganizationMembership($org) 323 | { 324 | // Build the request path. 325 | $path = '/user/memberships/orgs/' . $org; 326 | 327 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 328 | } 329 | 330 | /** 331 | * Edit your organization membership 332 | * 333 | * @param string $org The name of the organization. 334 | * @param string $state The state that the membership should be in. 335 | * 336 | * @return object 337 | * 338 | * @since 1.4.0 339 | */ 340 | public function editOrganizationMembership($org, $state) 341 | { 342 | // The API only accepts $state == 'active' at present 343 | if ($state != 'active') { 344 | throw new \InvalidArgumentException('The state must be "active".'); 345 | } 346 | 347 | // Build the request path. 348 | $path = '/user/memberships/orgs/' . $org; 349 | 350 | return $this->processResponse($this->client->patch($this->fetchUrl($path), ['state' => $state])); 351 | } 352 | } 353 | -------------------------------------------------------------------------------- /src/Package/Pulls/Comments.php: -------------------------------------------------------------------------------- 1 | $body, 47 | 'commit_id' => $commitId, 48 | 'path' => $filePath, 49 | 'position' => $position, 50 | ] 51 | ); 52 | 53 | // Send the request. 54 | return $this->processResponse( 55 | $this->client->post($this->fetchUrl($path), $data), 56 | 201 57 | ); 58 | } 59 | 60 | /** 61 | * Method to create a comment in reply to another comment. 62 | * 63 | * @param string $user The name of the owner of the GitHub repository. 64 | * @param string $repo The name of the GitHub repository. 65 | * @param integer $pullId The pull request number. 66 | * @param string $body The comment body text. 67 | * @param integer $inReplyTo The id of the comment to reply to. 68 | * 69 | * @since 1.0 70 | * 71 | * @return object 72 | */ 73 | public function createReply($user, $repo, $pullId, $body, $inReplyTo) 74 | { 75 | // Build the request path. 76 | $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; 77 | 78 | // Build the request data. 79 | $data = json_encode( 80 | [ 81 | 'body' => $body, 82 | 'in_reply_to' => (int) $inReplyTo, 83 | ] 84 | ); 85 | 86 | // Send the request. 87 | return $this->processResponse( 88 | $this->client->post($this->fetchUrl($path), $data), 89 | 201 90 | ); 91 | } 92 | 93 | /** 94 | * Delete a comment. 95 | * 96 | * @param string $user The name of the owner of the GitHub repository. 97 | * @param string $repo The name of the GitHub repository. 98 | * @param integer $commentId The id of the comment to delete. 99 | * 100 | * @since 1.0 101 | * 102 | * @return void 103 | */ 104 | public function delete($user, $repo, $commentId) 105 | { 106 | // Build the request path. 107 | $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; 108 | 109 | // Send the request. 110 | $this->processResponse( 111 | $this->client->delete($this->fetchUrl($path)), 112 | 204 113 | ); 114 | } 115 | 116 | /** 117 | * Edit a comment. 118 | * 119 | * @param string $user The name of the owner of the GitHub repository. 120 | * @param string $repo The name of the GitHub repository. 121 | * @param integer $commentId The id of the comment to update. 122 | * @param string $body The new body text for the comment. 123 | * 124 | * @since 1.0 125 | * 126 | * @return object 127 | */ 128 | public function edit($user, $repo, $commentId, $body) 129 | { 130 | // Build the request path. 131 | $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; 132 | 133 | // Build the request data. 134 | $data = json_encode( 135 | [ 136 | 'body' => $body, 137 | ] 138 | ); 139 | 140 | // Send the request. 141 | return $this->processResponse( 142 | $this->client->patch($this->fetchUrl($path), $data) 143 | ); 144 | } 145 | 146 | /** 147 | * Get a single comment. 148 | * 149 | * @param string $user The name of the owner of the GitHub repository. 150 | * @param string $repo The name of the GitHub repository. 151 | * @param integer $commentId The comment id to get. 152 | * 153 | * @since 1.0 154 | * 155 | * @return object 156 | */ 157 | public function get($user, $repo, $commentId) 158 | { 159 | // Build the request path. 160 | $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; 161 | 162 | // Send the request. 163 | return $this->processResponse( 164 | $this->client->get($this->fetchUrl($path)) 165 | ); 166 | } 167 | 168 | /** 169 | * List comments on a pull request. 170 | * 171 | * @param string $user The name of the owner of the GitHub repository. 172 | * @param string $repo The name of the GitHub repository. 173 | * @param integer $pullId The pull request number. 174 | * @param integer $page The page number from which to get items. 175 | * @param integer $limit The number of items on a page. 176 | * 177 | * @since 1.0 178 | * 179 | * @return array 180 | */ 181 | public function getList($user, $repo, $pullId, $page = 0, $limit = 0) 182 | { 183 | // Build the request path. 184 | $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; 185 | 186 | // Send the request. 187 | return $this->processResponse( 188 | $this->client->get($this->fetchUrl($path, $page, $limit)) 189 | ); 190 | } 191 | 192 | /** 193 | * List comments in a repository. 194 | * 195 | * @param string $user The name of the owner of the GitHub repository. 196 | * @param string $repo The name of the GitHub repository. 197 | * @param integer $page The page number from which to get items. 198 | * @param integer $limit The number of items on a page. 199 | * 200 | * @return array 201 | * 202 | * @since 1.4.0 203 | */ 204 | public function getListForRepo($user, $repo, $page = 0, $limit = 0) 205 | { 206 | // Build the request path. 207 | $path = "/repos/$user/$repo/pulls/comments"; 208 | 209 | // Send the request. 210 | return $this->processResponse( 211 | $this->client->get($this->fetchUrl($path, $page, $limit)) 212 | ); 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /src/Package/Repositories/Branches.php: -------------------------------------------------------------------------------- 1 | processResponse( 40 | $this->client->get($this->fetchUrl($path)) 41 | ); 42 | } 43 | 44 | /** 45 | * Get Branch. 46 | * 47 | * @param string $owner Repository owner. 48 | * @param string $repo Repository name. 49 | * @param string $branch Branch name. 50 | * 51 | * @return object 52 | * 53 | * @since 1.4.0 54 | */ 55 | public function get($owner, $repo, $branch) 56 | { 57 | // Build the request path. 58 | $path = "/repos/$owner/$repo/branches/$branch"; 59 | 60 | // Send the request. 61 | return $this->processResponse( 62 | $this->client->get($this->fetchUrl($path)) 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Package/Repositories/Collaborators.php: -------------------------------------------------------------------------------- 1 | processResponse( 43 | $this->client->get($this->fetchUrl($path)) 44 | ); 45 | } 46 | 47 | /** 48 | * Check if a user is a collaborator. 49 | * 50 | * @param string $owner The name of the owner of the GitHub repository. 51 | * @param string $repo The name of the GitHub repository. 52 | * @param string $user The name of the GitHub user. 53 | * 54 | * @throws \UnexpectedValueException 55 | * @since 1.0 56 | * 57 | * @return boolean 58 | */ 59 | public function get($owner, $repo, $user) 60 | { 61 | // Build the request path. 62 | $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user; 63 | 64 | $response = $this->client->get($this->fetchUrl($path)); 65 | 66 | switch ($response->code) { 67 | case '204': 68 | return true; 69 | 70 | case '404': 71 | return false; 72 | 73 | default: 74 | throw new \UnexpectedValueException('Unexpected code: ' . $response->code); 75 | } 76 | } 77 | 78 | /** 79 | * Add user as a collaborator. 80 | * 81 | * @param string $owner The name of the owner of the GitHub repository. 82 | * @param string $repo The name of the GitHub repository. 83 | * @param string $user The name of the GitHub user. 84 | * 85 | * @since 1.0 86 | * 87 | * @return object 88 | */ 89 | public function add($owner, $repo, $user) 90 | { 91 | // Build the request path. 92 | $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user; 93 | 94 | return $this->processResponse( 95 | $this->client->put($this->fetchUrl($path), ''), 96 | 204 97 | ); 98 | } 99 | 100 | /** 101 | * Remove user as a collaborator. 102 | * 103 | * @param string $owner The name of the owner of the GitHub repository. 104 | * @param string $repo The name of the GitHub repository. 105 | * @param string $user The name of the GitHub user. 106 | * 107 | * @since 1.0 108 | * 109 | * @return object 110 | */ 111 | public function remove($owner, $repo, $user) 112 | { 113 | // Build the request path. 114 | $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user; 115 | 116 | return $this->processResponse( 117 | $this->client->delete($this->fetchUrl($path)), 118 | 204 119 | ); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/Package/Repositories/Comments.php: -------------------------------------------------------------------------------- 1 | processResponse( 42 | $this->client->get($this->fetchUrl($path, $page, $limit)) 43 | ); 44 | } 45 | 46 | /** 47 | * List comments for a single commit. 48 | * 49 | * @param string $user The name of the owner of the GitHub repository. 50 | * @param string $repo The name of the GitHub repository. 51 | * @param string $sha The SHA of the commit to retrieve. 52 | * @param integer $page Page to request 53 | * @param integer $limit Number of results to return per page 54 | * 55 | * @return array 56 | * 57 | * @since 1.0 58 | */ 59 | public function getList($user, $repo, $sha, $page = 0, $limit = 0) 60 | { 61 | // Build the request path. 62 | $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments'; 63 | 64 | // Send the request. 65 | return $this->processResponse( 66 | $this->client->get($this->fetchUrl($path, $page, $limit)) 67 | ); 68 | } 69 | 70 | /** 71 | * Get a single commit comment. 72 | * 73 | * @param string $user The name of the owner of the GitHub repository. 74 | * @param string $repo The name of the GitHub repository. 75 | * @param integer $id ID of the comment to retrieve 76 | * 77 | * @return array 78 | * 79 | * @since 1.0 80 | */ 81 | public function get($user, $repo, $id) 82 | { 83 | // Build the request path. 84 | $path = '/repos/' . $user . '/' . $repo . '/comments/' . (int) $id; 85 | 86 | // Send the request. 87 | return $this->processResponse( 88 | $this->client->get($this->fetchUrl($path)) 89 | ); 90 | } 91 | 92 | /** 93 | * Update a commit comment. 94 | * 95 | * @param string $user The name of the owner of the GitHub repository. 96 | * @param string $repo The name of the GitHub repository. 97 | * @param string $id The ID of the comment to edit. 98 | * @param string $comment The text of the comment. 99 | * 100 | * @return object 101 | * 102 | * @since 1.0 103 | */ 104 | public function edit($user, $repo, $id, $comment) 105 | { 106 | // Build the request path. 107 | $path = '/repos/' . $user . '/' . $repo . '/comments/' . $id; 108 | 109 | $data = json_encode( 110 | [ 111 | 'body' => $comment, 112 | ] 113 | ); 114 | 115 | // Send the request. 116 | return $this->processResponse( 117 | $this->client->patch($this->fetchUrl($path), $data) 118 | ); 119 | } 120 | 121 | /** 122 | * Delete a commit comment. 123 | * 124 | * @param string $user The name of the owner of the GitHub repository. 125 | * @param string $repo The name of the GitHub repository. 126 | * @param string $id The ID of the comment to edit. 127 | * 128 | * @return object 129 | * 130 | * @since 1.0 131 | */ 132 | public function delete($user, $repo, $id) 133 | { 134 | // Build the request path. 135 | $path = '/repos/' . $user . '/' . $repo . '/comments/' . $id; 136 | 137 | // Send the request. 138 | return $this->processResponse( 139 | $this->client->delete($this->fetchUrl($path)), 140 | 204 141 | ); 142 | } 143 | 144 | /** 145 | * Create a commit comment. 146 | * 147 | * @param string $user The name of the owner of the GitHub repository. 148 | * @param string $repo The name of the GitHub repository. 149 | * @param string $sha The SHA of the commit to comment on. 150 | * @param string $comment The text of the comment. 151 | * @param integer $line The line number of the commit to comment on. 152 | * @param string $filepath A relative path to the file to comment on within the commit. 153 | * @param integer $position Line index in the diff to comment on. 154 | * 155 | * @return object 156 | * 157 | * @since 1.0 158 | */ 159 | public function create($user, $repo, $sha, $comment, $line, $filepath, $position) 160 | { 161 | // Build the request path. 162 | $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments'; 163 | 164 | $data = json_encode( 165 | [ 166 | 'body' => $comment, 167 | 'path' => $filepath, 168 | 'position' => (int) $position, 169 | 'line' => (int) $line, 170 | ] 171 | ); 172 | 173 | // Send the request. 174 | return $this->processResponse( 175 | $this->client->post($this->fetchUrl($path), $data), 176 | 201 177 | ); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/Package/Repositories/Commits.php: -------------------------------------------------------------------------------- 1 | fetchUrl($rPath); 51 | 52 | if ($sha) { 53 | $uri->setVar('sha', $sha); 54 | } 55 | 56 | if ($path) { 57 | $uri->setVar('path', $path); 58 | } 59 | 60 | if ($author) { 61 | $uri->setVar('author', $author); 62 | } 63 | 64 | if ($since) { 65 | $uri->setVar('since', $since->format(\DateTime::RFC3339)); 66 | } 67 | 68 | if ($until) { 69 | $uri->setVar('until', $until->format(\DateTime::RFC3339)); 70 | } 71 | 72 | // Send the request. 73 | return $this->processResponse($this->client->get($uri)); 74 | } 75 | 76 | /** 77 | * Get a single commit. 78 | * 79 | * @param string $user The name of the owner of the GitHub repository. 80 | * @param string $repo The name of the GitHub repository. 81 | * @param string $sha The SHA of the commit to retrieve. 82 | * 83 | * @return object 84 | * 85 | * @since 1.0 86 | * @throws \DomainException 87 | */ 88 | public function get($user, $repo, $sha) 89 | { 90 | // Build the request path. 91 | $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha; 92 | 93 | // Send the request. 94 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 95 | } 96 | 97 | /** 98 | * Get the SHA-1 of a commit reference. 99 | * 100 | * @param string $user The name of the owner of the GitHub repository. 101 | * @param string $repo The name of the GitHub repository. 102 | * @param string $ref The commit reference 103 | * 104 | * @return string 105 | * 106 | * @since 1.4.0 107 | * @throws UnexpectedResponseException 108 | */ 109 | public function getSha($user, $repo, $ref) 110 | { 111 | // Build the request path. 112 | $path = '/repos/' . $user . '/' . $repo . '/commits/' . $ref; 113 | 114 | // Send the request. 115 | $response = $this->client->get($this->fetchUrl($path)); 116 | 117 | // Validate the response code. 118 | if ($response->code != 200) { 119 | // Decode the error response and throw an exception. 120 | $error = json_decode($response->body); 121 | $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; 122 | 123 | throw new UnexpectedResponseException($response, $message, $response->code); 124 | } 125 | 126 | return $response->body; 127 | } 128 | 129 | /** 130 | * Compare two commits. 131 | * 132 | * @param string $user The name of the owner of the GitHub repository. 133 | * @param string $repo The name of the GitHub repository. 134 | * @param string $base The base of the diff, either a commit SHA or branch. 135 | * @param string $head The head of the diff, either a commit SHA or branch. 136 | * 137 | * @return object 138 | * 139 | * @since 1.0 140 | */ 141 | public function compare($user, $repo, $base, $head) 142 | { 143 | // Build the request path. 144 | $path = '/repos/' . $user . '/' . $repo . '/compare/' . $base . '...' . $head; 145 | 146 | // Send the request. 147 | return $this->processResponse( 148 | $this->client->get($this->fetchUrl($path)) 149 | ); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/Package/Repositories/Deployments.php: -------------------------------------------------------------------------------- 1 | fetchUrl($path, $page, $limit); 45 | 46 | if ($sha) { 47 | $uri->setVar('sha', $sha); 48 | } 49 | 50 | if ($ref) { 51 | $uri->setVar('ref', $ref); 52 | } 53 | 54 | if ($task) { 55 | $uri->setVar('task', $task); 56 | } 57 | 58 | if ($environment) { 59 | $uri->setVar('environment', $environment); 60 | } 61 | 62 | return $this->processResponse($this->client->get($uri)); 63 | } 64 | 65 | /** 66 | * Create a Deployment. 67 | * 68 | * @param string $owner The name of the owner of the GitHub repository. 69 | * @param string $repo The name of the GitHub repository. 70 | * @param string $ref The ref to deploy. This can be a branch, tag, or SHA. 71 | * @param string $task Optional parameter to specify a task to execute. 72 | * @param boolean $autoMerge Optional parameter to merge the default branch into the requested ref if 73 | * it is behind the default branch. 74 | * @param array|null $requiredContexts Optional array of status contexts verified against commit status checks. 75 | * If this parameter is omitted 76 | * from the parameters then all unique contexts will be verified before a 77 | * deployment is created. To bypass checking entirely pass an empty array. 78 | * Defaults to all unique contexts. 79 | * @param string $payload Optional JSON payload with extra information about the deployment. 80 | * @param string $environment Optional name for the target deployment environment. 81 | * @param string $description Optional short description. 82 | * 83 | * @return object 84 | * 85 | * @since 1.4.0 86 | * @throws \RuntimeException 87 | */ 88 | public function create( 89 | $owner, 90 | $repo, 91 | $ref, 92 | $task = '', 93 | $autoMerge = true, 94 | $requiredContexts = null, 95 | $payload = '', 96 | $environment = '', 97 | $description = '' 98 | ) { 99 | // Build the request path. 100 | $path = "/repos/$owner/$repo/deployments"; 101 | 102 | $data = [ 103 | 'ref' => $ref, 104 | 'auto_merge' => $autoMerge, 105 | ]; 106 | 107 | if ($task) { 108 | $data['task'] = $task; 109 | } 110 | 111 | if (\is_array($requiredContexts)) { 112 | $data['required_contexts'] = $requiredContexts; 113 | } 114 | 115 | if ($payload) { 116 | $data['payload'] = $payload; 117 | } 118 | 119 | if ($environment) { 120 | $data['environment'] = $environment; 121 | } 122 | 123 | if ($description) { 124 | $data['description'] = $description; 125 | } 126 | 127 | $response = $this->client->post($this->fetchUrl($path), json_encode($data)); 128 | 129 | switch ($response->code) { 130 | case 201: 131 | // The deployment was successful 132 | return json_decode($response->body); 133 | 134 | case 409: 135 | // There was a merge conflict or a status check failed. 136 | $body = json_decode($response->body); 137 | $message = isset($body->message) ? $body->message : 'Invalid response received from GitHub.'; 138 | 139 | throw new \RuntimeException($message, $response->code); 140 | 141 | default: 142 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); 143 | } 144 | } 145 | 146 | /** 147 | * List Deployment Statuses. 148 | * 149 | * @param string $owner The name of the owner of the GitHub repository. 150 | * @param string $repo The name of the GitHub repository. 151 | * @param integer $id The Deployment ID to list the statuses from. 152 | * @param integer $page The page number from which to get items. 153 | * @param integer $limit The number of items on a page. 154 | * 155 | * @return object 156 | * 157 | * @since 1.4.0 158 | */ 159 | public function getDeploymentStatuses($owner, $repo, $id, $page = 0, $limit = 0) 160 | { 161 | // Build the request path. 162 | $path = "/repos/$owner/$repo/deployments/" . (int) $id . '/statuses'; 163 | 164 | return $this->processResponse( 165 | $this->client->get($this->fetchUrl($path, $page, $limit)) 166 | ); 167 | } 168 | 169 | /** 170 | * Create a Deployment Status. 171 | * 172 | * @param string $owner The name of the owner of the GitHub repository. 173 | * @param string $repo The name of the GitHub repository. 174 | * @param integer $id The Deployment ID to list the statuses from. 175 | * @param string $state The state of the status. 176 | * @param string $targetUrl The target URL to associate with this status. This URL should contain output to keep the user updated while 177 | * the task is running or serve as historical information for what happened in the deployment. 178 | * @param string $description A short description of the status. Maximum length of 140 characters. 179 | * 180 | * @return object 181 | * 182 | * @since 1.4.0 183 | * @throws \InvalidArgumentException 184 | */ 185 | public function createStatus($owner, $repo, $id, $state, $targetUrl = '', $description = '') 186 | { 187 | $allowedStates = ['pending', 'success', 'error', 'failure']; 188 | 189 | // Build the request path. 190 | $path = "/repos/$owner/$repo/deployments/" . (int) $id . '/statuses'; 191 | 192 | if (!\in_array($state, $allowedStates)) { 193 | throw new \InvalidArgumentException(sprintf('The deployment state must be: %s', implode(', ', $allowedStates))); 194 | } 195 | 196 | $data = [ 197 | 'state' => $state, 198 | ]; 199 | 200 | if ($targetUrl) { 201 | $data['target_url'] = $targetUrl; 202 | } 203 | 204 | if ($description) { 205 | $data['description'] = $description; 206 | } 207 | 208 | return $this->processResponse( 209 | $this->client->post($this->fetchUrl($path), json_encode($data)), 210 | 201 211 | ); 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /src/Package/Repositories/Downloads.php: -------------------------------------------------------------------------------- 1 | processResponse( 46 | $this->client->get($this->fetchUrl($path)) 47 | ); 48 | } 49 | 50 | /** 51 | * Get a single download. 52 | * 53 | * @param string $owner The name of the owner of the GitHub repository. 54 | * @param string $repo The name of the GitHub repository. 55 | * @param integer $id The id of the download. 56 | * 57 | * @return object 58 | * 59 | * @since 1.0 60 | * @deprecated The Releases API should be used instead 61 | */ 62 | public function get($owner, $repo, $id) 63 | { 64 | // Build the request path. 65 | $path = '/repos/' . $owner . '/' . $repo . '/downloads/' . $id; 66 | 67 | // Send the request. 68 | return $this->processResponse( 69 | $this->client->get($this->fetchUrl($path)) 70 | ); 71 | } 72 | 73 | /** 74 | * Create a new download (Part 1: Create the resource). 75 | * 76 | * Creating a new download is a two step process. You must first create a new download resource. 77 | * 78 | * @param string $owner The name of the owner of the GitHub repository. 79 | * @param string $repo The name of the GitHub repository. 80 | * @param string $name The name. 81 | * @param string $size Size of file in bytes. 82 | * @param string $description The description. 83 | * @param string $contentType The content type. 84 | * 85 | * @return void 86 | * 87 | * @note This API endpoint no longer exists at GitHub 88 | * @since 1.0 89 | * @throws \RuntimeException 90 | * @deprecated The Releases API should be used instead 91 | */ 92 | public function create($owner, $repo, $name, $size, $description = '', $contentType = '') 93 | { 94 | throw new \RuntimeException('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); 95 | } 96 | 97 | /** 98 | * Create a new download (Part 2: Upload file to s3). 99 | * 100 | * Now that you have created the download resource, you can use the information 101 | * in the response to upload your file to s3. This can be done with a POST to 102 | * the s3_url you got in the create response. Here is a brief example using curl: 103 | * 104 | * curl \ 105 | * -F "key=downloads/octocat/Hello-World/new_file.jpg" \ 106 | * -F "acl=public-read" \ 107 | * -F "success_action_status=201" \ 108 | * -F "Filename=new_file.jpg" \ 109 | * -F "AWSAccessKeyId=1ABCDEF..." \ 110 | * -F "Policy=ewogIC..." \ 111 | * -F "Signature=mwnF..." \ 112 | * -F "Content-Type=image/jpeg" \ 113 | * -F "file=@new_file.jpg" \ 114 | * https://github.s3.amazonaws.com/ 115 | * 116 | * NOTES 117 | * The order in which you pass these fields matters! Follow the order shown above exactly. 118 | * All parameters shown are required and if you excluded or modify them your upload will 119 | * fail because the values are hashed and signed by the policy. 120 | * 121 | * More information about using the REST API to interact with s3 can be found here: 122 | * http://docs.amazonwebservices.com/AmazonS3/latest/API/ 123 | * 124 | * @param string $key Value of path field in the response. 125 | * @param string $acl Value of acl field in the response. 126 | * @param string $successActionStatus 201, or whatever you want to get back. 127 | * @param string $filename Value of name field in the response. 128 | * @param string $awsAccessKeyId Value of accesskeyid field in the response. 129 | * @param string $policy Value of policy field in the response. 130 | * @param string $signature Value of signature field in the response. 131 | * @param string $contentType Value of mime_type field in the response. 132 | * @param string $file Local file. Example assumes the file existing in the directory 133 | * where you are running the curl command. Yes, the @ matters. 134 | * 135 | * @return void 136 | * 137 | * @note This API endpoint no longer exists at GitHub 138 | * @since 1.0 139 | * @throws \RuntimeException 140 | * @deprecated The Releases API should be used instead 141 | */ 142 | public function upload($key, $acl, $successActionStatus, $filename, $awsAccessKeyId, $policy, $signature, $contentType, $file) 143 | { 144 | throw new \RuntimeException('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); 145 | } 146 | 147 | /** 148 | * Delete a download. 149 | * 150 | * @param string $owner The name of the owner of the GitHub repository. 151 | * @param string $repo The name of the GitHub repository. 152 | * @param integer $id The id of the download. 153 | * 154 | * @return object 155 | * 156 | * @since 1.0 157 | * @deprecated The Releases API should be used instead 158 | */ 159 | public function delete($owner, $repo, $id) 160 | { 161 | // Build the request path. 162 | $path = '/repos/' . $owner . '/' . $repo . '/downloads/' . (int) $id; 163 | 164 | // Send the request. 165 | return $this->processResponse( 166 | $this->client->delete($this->fetchUrl($path)), 167 | 204 168 | ); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/Package/Repositories/Forks.php: -------------------------------------------------------------------------------- 1 | 0) { 41 | $data = json_encode( 42 | ['org' => $org] 43 | ); 44 | } else { 45 | $data = json_encode([]); 46 | } 47 | 48 | // Send the request. 49 | return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 202); 50 | } 51 | 52 | /** 53 | * List forks. 54 | * 55 | * @param string $owner The name of the owner of the GitHub repository. 56 | * @param string $repo The name of the GitHub repository. 57 | * @param integer $page Page to request 58 | * @param integer $limit Number of results to return per page 59 | * 60 | * @return array 61 | * 62 | * @since 1.0 63 | * @throws \DomainException 64 | */ 65 | public function getList($owner, $repo, $page = 0, $limit = 0) 66 | { 67 | // Build the request path. 68 | $path = '/repos/' . $owner . '/' . $repo . '/forks'; 69 | 70 | // Send the request. 71 | return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit)), 200); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Package/Repositories/Hooks.php: -------------------------------------------------------------------------------- 1 | hookEvents)) { 47 | throw new \RuntimeException('Your events array contains an unauthorized event.'); 48 | } 49 | } 50 | 51 | $data = json_encode( 52 | ['name' => $name, 'config' => $config, 'events' => $events, 'active' => $active] 53 | ); 54 | 55 | return $this->processResponse( 56 | $this->client->post($this->fetchUrl($path), $data), 57 | 201 58 | ); 59 | } 60 | 61 | /** 62 | * Delete a hook 63 | * 64 | * @param string $user The name of the owner of the GitHub repository. 65 | * @param string $repo The name of the GitHub repository. 66 | * @param integer $id ID of the hook to delete. 67 | * 68 | * @return object 69 | * 70 | * @since 1.0 71 | * @throws \DomainException 72 | */ 73 | public function delete($user, $repo, $id) 74 | { 75 | // Build the request path. 76 | $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; 77 | 78 | return $this->processResponse( 79 | $this->client->delete($this->fetchUrl($path)), 80 | 204 81 | ); 82 | } 83 | 84 | /** 85 | * Edit a hook. 86 | * 87 | * @param string $user The name of the owner of the GitHub repository. 88 | * @param string $repo The name of the GitHub repository. 89 | * @param integer $id ID of the hook to edit. 90 | * @param string $name The name of the service being called. 91 | * @param array $config Array containing the config for the service. 92 | * @param array $events The events the hook will be triggered for. This resets the currently set list 93 | * @param array $addEvents Events to add to the hook. 94 | * @param array $removeEvents Events to remove from the hook. 95 | * @param boolean $active Flag to determine if the hook is active 96 | * 97 | * @return object 98 | * 99 | * @since 1.0 100 | * @throws \DomainException 101 | * @throws \RuntimeException 102 | */ 103 | public function edit($user, $repo, $id, $name, $config, array $events = ['push'], array $addEvents = [], array $removeEvents = [], $active = true) 104 | { 105 | // Check to ensure all events are in the allowed list 106 | foreach ($events as $event) { 107 | if (!\in_array($event, $this->hookEvents)) { 108 | throw new \RuntimeException('Your events array contains an unauthorized event.'); 109 | } 110 | } 111 | 112 | foreach ($addEvents as $event) { 113 | if (!\in_array($event, $this->hookEvents)) { 114 | throw new \RuntimeException('Your active_events array contains an unauthorized event.'); 115 | } 116 | } 117 | 118 | foreach ($removeEvents as $event) { 119 | if (!\in_array($event, $this->hookEvents)) { 120 | throw new \RuntimeException('Your remove_events array contains an unauthorized event.'); 121 | } 122 | } 123 | 124 | // Build the request path. 125 | $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; 126 | 127 | $data = json_encode( 128 | [ 129 | 'name' => $name, 130 | 'config' => $config, 131 | 'events' => $events, 132 | 'add_events' => $addEvents, 133 | 'remove_events' => $removeEvents, 134 | 'active' => $active, 135 | ] 136 | ); 137 | 138 | return $this->processResponse( 139 | $this->client->patch($this->fetchUrl($path), $data) 140 | ); 141 | } 142 | 143 | /** 144 | * Get single hook. 145 | * 146 | * @param string $user The name of the owner of the GitHub repository. 147 | * @param string $repo The name of the GitHub repository. 148 | * @param integer $id ID of the hook to retrieve 149 | * 150 | * @return object 151 | * 152 | * @since 1.0 153 | * @throws \DomainException 154 | */ 155 | public function get($user, $repo, $id) 156 | { 157 | // Build the request path. 158 | $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; 159 | 160 | return $this->processResponse( 161 | $this->client->get($this->fetchUrl($path)) 162 | ); 163 | } 164 | 165 | /** 166 | * List hooks. 167 | * 168 | * @param string $user The name of the owner of the GitHub repository. 169 | * @param string $repo The name of the GitHub repository. 170 | * 171 | * @return object 172 | * 173 | * @since 1.0 174 | * @throws \DomainException 175 | */ 176 | public function getList($user, $repo) 177 | { 178 | // Build the request path. 179 | $path = '/repos/' . $user . '/' . $repo . '/hooks'; 180 | 181 | return $this->processResponse( 182 | $this->client->get($this->fetchUrl($path)) 183 | ); 184 | } 185 | 186 | /** 187 | * Ping a hook. 188 | * 189 | * @param string $user The name of the owner of the GitHub repository. 190 | * @param string $repo The name of the GitHub repository. 191 | * @param integer $id ID of the hook to ping 192 | * 193 | * @return object 194 | * 195 | * @since 1.4.0 196 | * @throws \DomainException 197 | */ 198 | public function ping($user, $repo, $id) 199 | { 200 | // Build the request path. 201 | $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id . '/pings'; 202 | 203 | return $this->processResponse( 204 | $this->client->post($this->fetchUrl($path), json_encode('')), 205 | 204 206 | ); 207 | } 208 | 209 | /** 210 | * Test a `push` hook. 211 | * 212 | * @param string $user The name of the owner of the GitHub repository. 213 | * @param string $repo The name of the GitHub repository. 214 | * @param integer $id ID of the hook to test 215 | * 216 | * @return object 217 | * 218 | * @since 1.0 219 | * @throws \DomainException 220 | */ 221 | public function test($user, $repo, $id) 222 | { 223 | // Build the request path. 224 | $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id . '/test'; 225 | 226 | return $this->processResponse( 227 | $this->client->post($this->fetchUrl($path), json_encode('')), 228 | 204 229 | ); 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/Package/Repositories/Keys.php: -------------------------------------------------------------------------------- 1 | processResponse( 39 | $this->client->get($this->fetchUrl($path)) 40 | ); 41 | } 42 | 43 | /** 44 | * Get a deploy key. 45 | * 46 | * @param string $owner The name of the owner of the GitHub repository. 47 | * @param string $repo The name of the GitHub repository. 48 | * @param integer $id The id of the key. 49 | * 50 | * @since 1.0 51 | * 52 | * @return object 53 | */ 54 | public function get($owner, $repo, $id) 55 | { 56 | // Build the request path. 57 | $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; 58 | 59 | return $this->processResponse( 60 | $this->client->get($this->fetchUrl($path)) 61 | ); 62 | } 63 | 64 | /** 65 | * Add a new deploy key. 66 | * 67 | * @param string $owner The name of the owner of the GitHub repository. 68 | * @param string $repo The name of the GitHub repository. 69 | * @param string $title The key title. 70 | * @param string $key The key. 71 | * 72 | * @since 1.0 73 | * 74 | * @return object 75 | */ 76 | public function create($owner, $repo, $title, $key) 77 | { 78 | // Build the request path. 79 | $path = '/repos/' . $owner . '/' . $repo . '/keys'; 80 | 81 | $data = [ 82 | 'title' => $title, 83 | 'key' => $key, 84 | ]; 85 | 86 | return $this->processResponse( 87 | $this->client->post($this->fetchUrl($path), json_encode($data)), 88 | 201 89 | ); 90 | } 91 | 92 | /** 93 | * Edit a deploy key. 94 | * 95 | * @param string $owner The name of the owner of the GitHub repository. 96 | * @param string $repo The name of the GitHub repository. 97 | * @param integer $id The id of the key. 98 | * @param string $title The key title. 99 | * @param string $key The key. 100 | * 101 | * @since 1.0 102 | * 103 | * @return object 104 | */ 105 | public function edit($owner, $repo, $id, $title, $key) 106 | { 107 | // Build the request path. 108 | $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; 109 | 110 | $data = [ 111 | 'title' => $title, 112 | 'key' => $key, 113 | ]; 114 | 115 | return $this->processResponse( 116 | $this->client->patch($this->fetchUrl($path), json_encode($data)) 117 | ); 118 | } 119 | 120 | /** 121 | * Remove a deploy key. 122 | * 123 | * @param string $owner The name of the owner of the GitHub repository. 124 | * @param string $repo The name of the GitHub repository. 125 | * @param integer $id The id of the key. 126 | * 127 | * @since 1.0 128 | * 129 | * @return boolean 130 | */ 131 | public function delete($owner, $repo, $id) 132 | { 133 | // Build the request path. 134 | $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; 135 | 136 | $this->processResponse( 137 | $this->client->delete($this->fetchUrl($path)), 138 | 204 139 | ); 140 | 141 | return true; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/Package/Repositories/Merging.php: -------------------------------------------------------------------------------- 1 | base = $base; 46 | $data->head = $head; 47 | 48 | if ($commitMessage) { 49 | $data->commit_message = $commitMessage; 50 | } 51 | 52 | // Send the request. 53 | $response = $this->client->post($this->fetchUrl($path), json_encode($data)); 54 | 55 | switch ($response->code) { 56 | case '201': 57 | // Success 58 | return json_decode($response->body); 59 | 60 | case '204': 61 | // No-op response (base already contains the head, nothing to merge) 62 | throw new \UnexpectedValueException('Nothing to merge'); 63 | 64 | case '404': 65 | // Missing base or Missing head response 66 | $error = json_decode($response->body); 67 | 68 | $message = (isset($error->message)) ? $error->message : 'Missing base or head: ' . $response->code; 69 | 70 | throw new \UnexpectedValueException($message); 71 | 72 | case '409': 73 | // Merge conflict response 74 | $error = json_decode($response->body); 75 | 76 | $message = (isset($error->message)) ? $error->message : 'Merge conflict ' . $response->code; 77 | 78 | throw new \UnexpectedValueException($message); 79 | 80 | default: 81 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Package/Repositories/Pages.php: -------------------------------------------------------------------------------- 1 | processResponse( 39 | $this->client->get($this->fetchUrl($path)) 40 | ); 41 | } 42 | 43 | /** 44 | * List Pages builds. 45 | * 46 | * @param string $owner The name of the owner of the GitHub repository. 47 | * @param string $repo The name of the GitHub repository. 48 | * @param integer $page The page number from which to get items. 49 | * @param integer $limit The number of items on a page. 50 | * 51 | * @return object 52 | * 53 | * @since 1.4.0 54 | */ 55 | public function getList($owner, $repo, $page = 0, $limit = 0) 56 | { 57 | // Build the request path. 58 | $path = "/repos/$owner/$repo/pages/builds"; 59 | 60 | return $this->processResponse( 61 | $this->client->get($this->fetchUrl($path, $page, $limit)) 62 | ); 63 | } 64 | 65 | /** 66 | * List latest Pages build. 67 | * 68 | * @param string $owner The name of the owner of the GitHub repository. 69 | * @param string $repo The name of the GitHub repository. 70 | * 71 | * @return object 72 | * 73 | * @since 1.4.0 74 | */ 75 | public function getLatest($owner, $repo) 76 | { 77 | // Build the request path. 78 | $path = "/repos/$owner/$repo/pages/builds/latest"; 79 | 80 | return $this->processResponse( 81 | $this->client->get($this->fetchUrl($path)) 82 | ); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Package/Repositories/Statistics.php: -------------------------------------------------------------------------------- 1 | processResponse($this->client->get($this->fetchUrl($path))); 54 | } 55 | 56 | /** 57 | * Get the last year of commit activity data. 58 | * 59 | * Returns the last year of commit activity grouped by week. 60 | * The days array is a group of commits per day, starting on Sunday. 61 | * 62 | * @param string $owner The owner of the repository. 63 | * @param string $repo The repository name. 64 | * 65 | * @return object 66 | * 67 | * @since 1.0 68 | */ 69 | public function getActivityData($owner, $repo) 70 | { 71 | // Build the request path. 72 | $path = '/repos/' . $owner . '/' . $repo . '/stats/commit_activity'; 73 | 74 | // Send the request. 75 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 76 | } 77 | 78 | /** 79 | * Get the number of additions and deletions per week. 80 | * 81 | * Response returns a weekly aggregate of the number of additions and deletions pushed to a repository. 82 | * 83 | * @param string $owner The owner of the repository. 84 | * @param string $repo The repository name. 85 | * 86 | * @return object 87 | * 88 | * @since 1.0 89 | */ 90 | public function getCodeFrequency($owner, $repo) 91 | { 92 | // Build the request path. 93 | $path = '/repos/' . $owner . '/' . $repo . '/stats/code_frequency'; 94 | 95 | // Send the request. 96 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 97 | } 98 | 99 | /** 100 | * Get the weekly commit count for the repository owner and everyone else. 101 | * 102 | * Returns the total commit counts for the "owner" and total commit counts in "all". "all" is everyone combined, 103 | * including the owner in the last 52 weeks. 104 | * If you’d like to get the commit counts for non-owners, you can subtract all from owner. 105 | * 106 | * The array order is oldest week (index 0) to most recent week. 107 | * 108 | * @param string $owner The owner of the repository. 109 | * @param string $repo The repository name. 110 | * 111 | * @return object 112 | * 113 | * @since 1.0 114 | */ 115 | public function getParticipation($owner, $repo) 116 | { 117 | // Build the request path. 118 | $path = '/repos/' . $owner . '/' . $repo . '/stats/participation'; 119 | 120 | // Send the request. 121 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 122 | } 123 | 124 | /** 125 | * Get the number of commits per hour in each day. 126 | * 127 | * Response 128 | * Each array contains the day number, hour number, and number of commits: 129 | * 130 | * 0-6: Sunday - Saturday 131 | * 0-23: Hour of day 132 | * Number of commits 133 | * 134 | * For example, [2, 14, 25] indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays. 135 | * All times are based on the time zone of individual commits. 136 | * 137 | * @param string $owner The owner of the repository. 138 | * @param string $repo The repository name. 139 | * 140 | * @return object 141 | * 142 | * @since 1.0 143 | */ 144 | public function getPunchCard($owner, $repo) 145 | { 146 | // Build the request path. 147 | $path = '/repos/' . $owner . '/' . $repo . '/stats/punch_card'; 148 | 149 | // Send the request. 150 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 151 | } 152 | 153 | /** 154 | * Process the response and decode it. 155 | * 156 | * @param Response $response The response. 157 | * @param integer $expectedCode The expected "good" code. 158 | * 159 | * @return mixed 160 | * 161 | * @since 1.0 162 | * @throws \DomainException 163 | */ 164 | protected function processResponse(Response $response, $expectedCode = 200) 165 | { 166 | if ($response->code == 202) { 167 | throw new \DomainException( 168 | 'GitHub is building the statistics data. Please try again in a few moments.', 169 | $response->code 170 | ); 171 | } 172 | 173 | return parent::processResponse($response, $expectedCode); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /src/Package/Repositories/Statuses.php: -------------------------------------------------------------------------------- 1 | $state, 54 | ]; 55 | 56 | if ($targetUrl !== null) { 57 | $data['target_url'] = $targetUrl; 58 | } 59 | 60 | if ($description !== null) { 61 | $data['description'] = $description; 62 | } 63 | 64 | if ($context !== null) { 65 | $data['context'] = $context; 66 | } 67 | 68 | // Send the request. 69 | return $this->processResponse( 70 | $this->client->post($this->fetchUrl($path), json_encode($data)), 71 | 201 72 | ); 73 | } 74 | 75 | /** 76 | * List Statuses for a specific Ref. 77 | * 78 | * @param string $user The name of the owner of the GitHub repository. 79 | * @param string $repo The name of the GitHub repository. 80 | * @param string $sha SHA1 for which to get the statuses. 81 | * 82 | * @return array 83 | * 84 | * @since 1.0 85 | */ 86 | public function getList($user, $repo, $sha) 87 | { 88 | // Build the request path. 89 | $path = "/repos/$user/$repo/statuses/$sha"; 90 | 91 | // Send the request. 92 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 93 | } 94 | 95 | /** 96 | * Get the combined Status for a specific Ref. 97 | * 98 | * @param string $user The name of the owner of the GitHub repository. 99 | * @param string $repo The name of the GitHub repository. 100 | * @param string $sha SHA1 for which to get the combined status. 101 | * 102 | * @return array 103 | * 104 | * @since 1.4.0 105 | */ 106 | public function getCombinedStatus($user, $repo, $sha) 107 | { 108 | // Build the request path. 109 | $path = "/repos/$user/$repo/commits/$sha/status"; 110 | 111 | // Send the request. 112 | return $this->processResponse($this->client->get($this->fetchUrl($path))); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/Package/Search.php: -------------------------------------------------------------------------------- 1 | processResponse( 48 | $this->client->get($this->fetchUrl($path)) 49 | ); 50 | } 51 | 52 | /** 53 | * Search repositories. 54 | * 55 | * Find repositories by keyword. Note, this legacy method does not follow 56 | * the v3 pagination pattern. 57 | * This method returns up to 100 results per page and pages can be fetched 58 | * using the start_page parameter. 59 | * 60 | * @param string $keyword The search term. 61 | * @param string $language Filter results by language https://github.com/languages 62 | * @param integer $startPage Page number to fetch 63 | * 64 | * @return object 65 | * 66 | * @since 1.0 67 | * @deprecated The legacy API is deprecated 68 | */ 69 | public function repositories($keyword, $language = '', $startPage = 0) 70 | { 71 | // Build the request path. 72 | $uri = $this->fetchUrl('/legacy/repos/search/' . $keyword); 73 | 74 | if ($language) { 75 | $uri->setVar('language', $language); 76 | } 77 | 78 | if ($startPage) { 79 | $uri->setVar('start_page', $startPage); 80 | } 81 | 82 | // Send the request. 83 | return $this->processResponse($this->client->get($uri)); 84 | } 85 | 86 | /** 87 | * Search users. 88 | * 89 | * Find users by keyword. 90 | * 91 | * @param string $keyword The search term. 92 | * @param integer $startPage Page number to fetch 93 | * 94 | * @return object 95 | * 96 | * @since 1.0 97 | * @deprecated The legacy API is deprecated 98 | */ 99 | public function users($keyword, $startPage = 0) 100 | { 101 | // Build the request path. 102 | $uri = $this->fetchUrl('/legacy/user/search/' . $keyword); 103 | 104 | if ($startPage) { 105 | $uri->setVar('start_page', $startPage); 106 | } 107 | 108 | // Send the request. 109 | return $this->processResponse($this->client->get($uri)); 110 | } 111 | 112 | /** 113 | * Email search. 114 | * 115 | * This API call is added for compatibility reasons only. There’s no guarantee 116 | * that full email searches will always be available. The @ character in the 117 | * address must be left unencoded. Searches only against public email addresses 118 | * (as configured on the user’s GitHub profile). 119 | * 120 | * @param string $email The email address(es). 121 | * 122 | * @return object 123 | * 124 | * @since 1.0 125 | * @deprecated The legacy API is deprecated 126 | */ 127 | public function email($email) 128 | { 129 | // Build the request path. 130 | $path = '/legacy/user/email/' . $email; 131 | 132 | // Send the request. 133 | return $this->processResponse( 134 | $this->client->get($this->fetchUrl($path)) 135 | ); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/Package/Users.php: -------------------------------------------------------------------------------- 1 | processResponse( 44 | $this->client->get($this->fetchUrl($path)) 45 | ); 46 | } 47 | 48 | /** 49 | * Get the authenticated user. 50 | * 51 | * @return mixed 52 | * 53 | * @since 1.0 54 | * @throws \DomainException 55 | */ 56 | public function getAuthenticatedUser() 57 | { 58 | // Build the request path. 59 | $path = '/user'; 60 | 61 | // Send the request. 62 | return $this->processResponse( 63 | $this->client->get($this->fetchUrl($path)) 64 | ); 65 | } 66 | 67 | /** 68 | * Update the authenticated user. 69 | * 70 | * @param string $name The full name 71 | * @param string $email The email 72 | * @param string $blog The blog 73 | * @param string $company The company 74 | * @param string $location The location 75 | * @param string $hireable If he is unemployed :P 76 | * @param string $bio The biometrical DNA fingerprint (or smthng...) 77 | * 78 | * @return mixed 79 | * 80 | * @since 1.0 81 | * @throws \DomainException 82 | */ 83 | public function edit($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '') 84 | { 85 | $data = [ 86 | 'name' => $name, 87 | 'email' => $email, 88 | 'blog' => $blog, 89 | 'company' => $company, 90 | 'location' => $location, 91 | 'hireable' => $hireable, 92 | 'bio' => $bio, 93 | ]; 94 | 95 | // Build the request path. 96 | $path = '/user'; 97 | 98 | // Send the request. 99 | return $this->processResponse( 100 | $this->client->patch($this->fetchUrl($path), json_encode($data)) 101 | ); 102 | } 103 | 104 | /** 105 | * Get all users. 106 | * 107 | * This provides a dump of every user, in the order that they signed up for GitHub. 108 | * 109 | * @param integer $since The integer ID of the last User that you’ve seen. 110 | * 111 | * @return object 112 | * 113 | * @since 1.0 114 | * @throws \DomainException 115 | */ 116 | public function getList($since = 0) 117 | { 118 | // Build the request path. 119 | $uri = $this->fetchUrl('/users'); 120 | 121 | if ($since) { 122 | $uri->setVar('since', $since); 123 | } 124 | 125 | // Send the request. 126 | return $this->processResponse($this->client->get($uri)); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/Package/Users/Emails.php: -------------------------------------------------------------------------------- 1 | processResponse( 39 | $this->client->get($this->fetchUrl($path)) 40 | ); 41 | } 42 | 43 | /** 44 | * Add email address(es). 45 | * 46 | * @param string|array $email The email address(es). 47 | * 48 | * @return object 49 | * 50 | * @since 1.0 51 | */ 52 | public function add($email) 53 | { 54 | // Build the request path. 55 | $path = '/user/emails'; 56 | 57 | return $this->processResponse( 58 | $this->client->post($this->fetchUrl($path), json_encode($email)), 59 | 201 60 | ); 61 | } 62 | 63 | /** 64 | * Delete email address(es). 65 | * 66 | * @param string|array $email The email address(es). 67 | * 68 | * @return object 69 | * 70 | * @since 1.0 71 | */ 72 | public function delete($email) 73 | { 74 | // Build the request path. 75 | $path = '/user/emails'; 76 | 77 | $this->client->setOption('body', json_encode($email)); 78 | 79 | return $this->processResponse( 80 | $this->client->delete($this->fetchUrl($path)), 81 | 204 82 | ); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Package/Users/Followers.php: -------------------------------------------------------------------------------- 1 | processResponse( 40 | $this->client->get($this->fetchUrl($path)) 41 | ); 42 | } 43 | 44 | /** 45 | * List users followed by another user. 46 | * 47 | * @param string $user The name of the user. If not set the current authenticated user will be used. 48 | * 49 | * @return object 50 | * 51 | * @since 1.0 52 | */ 53 | public function getListFollowedBy($user = '') 54 | { 55 | // Build the request path. 56 | $path = ($user) 57 | ? '/users/' . $user . '/following' 58 | : '/user/following'; 59 | 60 | return $this->processResponse( 61 | $this->client->get($this->fetchUrl($path)) 62 | ); 63 | } 64 | 65 | /** 66 | * Check if you are following a user. 67 | * 68 | * @param string $user The name of the user. 69 | * 70 | * @return boolean 71 | * 72 | * @since 1.0 73 | * @throws \UnexpectedValueException 74 | */ 75 | public function check($user) 76 | { 77 | // Build the request path. 78 | $path = '/user/following/' . $user; 79 | 80 | $response = $this->client->get($this->fetchUrl($path)); 81 | 82 | switch ($response->code) { 83 | case '204': 84 | // You are following this user 85 | return true; 86 | 87 | case '404': 88 | // You are not following this user 89 | return false; 90 | 91 | default: 92 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); 93 | } 94 | } 95 | 96 | /** 97 | * Check if one user follows another. 98 | * 99 | * @param string $user The name of the user. 100 | * @param string $target The name of the user to check is being followed. 101 | * 102 | * @return boolean 103 | * 104 | * @since 1.4.0 105 | * @throws \UnexpectedValueException 106 | */ 107 | public function checkUserFollowing($user, $target) 108 | { 109 | // Build the request path. 110 | $path = "/user/$user/following/$target"; 111 | 112 | $response = $this->client->get($this->fetchUrl($path)); 113 | 114 | switch ($response->code) { 115 | case '204': 116 | // User is following the target 117 | return true; 118 | 119 | case '404': 120 | // User is not following the target 121 | return false; 122 | 123 | default: 124 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); 125 | } 126 | } 127 | 128 | /** 129 | * Follow a user. 130 | * 131 | * Following a user requires the user to be logged in and authenticated with 132 | * basic auth or OAuth with the user:follow scope. 133 | * 134 | * @param string $user The name of the user. 135 | * 136 | * @return object 137 | * 138 | * @since 1.0 139 | */ 140 | public function follow($user) 141 | { 142 | // Build the request path. 143 | $path = '/user/following/' . $user; 144 | 145 | return $this->processResponse( 146 | $this->client->put($this->fetchUrl($path), ''), 147 | 204 148 | ); 149 | } 150 | 151 | /** 152 | * Unfollow a user. 153 | * 154 | * Unfollowing a user requires the user to be logged in and authenticated with 155 | * basic auth or OAuth with the user:follow scope. 156 | * 157 | * @param string $user The name of the user. 158 | * 159 | * @return object 160 | * 161 | * @since 1.0 162 | */ 163 | public function unfollow($user) 164 | { 165 | // Build the request path. 166 | $path = '/user/following/' . $user; 167 | 168 | return $this->processResponse( 169 | $this->client->delete($this->fetchUrl($path)), 170 | 204 171 | ); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/Package/Users/Keys.php: -------------------------------------------------------------------------------- 1 | processResponse( 40 | $this->client->get($this->fetchUrl($path)) 41 | ); 42 | } 43 | 44 | /** 45 | * List your public keys. 46 | * 47 | * Lists the current user’s keys. 48 | * Management of public keys via the API requires that you are authenticated 49 | * through basic auth, or OAuth with the ‘user’ scope. 50 | * 51 | * @return object 52 | * 53 | * @since 1.0 54 | */ 55 | public function getList() 56 | { 57 | // Build the request path. 58 | $path = '/users/keys'; 59 | 60 | return $this->processResponse( 61 | $this->client->get($this->fetchUrl($path)) 62 | ); 63 | } 64 | 65 | /** 66 | * Get a single public key. 67 | * 68 | * @param integer $id The id of the key. 69 | * 70 | * @return object 71 | * 72 | * @since 1.0 73 | */ 74 | public function get($id) 75 | { 76 | // Build the request path. 77 | $path = '/users/keys/' . $id; 78 | 79 | return $this->processResponse( 80 | $this->client->get($this->fetchUrl($path)) 81 | ); 82 | } 83 | 84 | /** 85 | * Create a public key 86 | * 87 | * @param string $title The title of the key. 88 | * @param string $key The key. 89 | * 90 | * @return object 91 | * 92 | * @since 1.0 93 | */ 94 | public function create($title, $key) 95 | { 96 | // Build the request path. 97 | $path = '/users/keys'; 98 | 99 | $data = [ 100 | 'title' => $title, 101 | 'key' => $key, 102 | ]; 103 | 104 | return $this->processResponse( 105 | $this->client->post($this->fetchUrl($path), json_encode($data)), 106 | 201 107 | ); 108 | } 109 | 110 | /** 111 | * Update a public key. 112 | * 113 | * @param integer $id The id of the key. 114 | * @param string $title The title of the key. 115 | * @param string $key The key. 116 | * 117 | * @return object 118 | * 119 | * @since 1.0 120 | */ 121 | public function edit($id, $title, $key) 122 | { 123 | // Build the request path. 124 | $path = '/users/keys/' . $id; 125 | 126 | $data = [ 127 | 'title' => $title, 128 | 'key' => $key, 129 | ]; 130 | 131 | return $this->processResponse( 132 | $this->client->patch($this->fetchUrl($path), json_encode($data)) 133 | ); 134 | } 135 | 136 | /** 137 | * Delete a public key. 138 | * 139 | * @param integer $id The id of the key. 140 | * 141 | * @return object 142 | * 143 | * @since 1.0 144 | */ 145 | public function delete($id) 146 | { 147 | // Build the request path. 148 | $path = '/users/keys/' . (int) $id; 149 | 150 | return $this->processResponse( 151 | $this->client->delete($this->fetchUrl($path)), 152 | 204 153 | ); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/Package/Zen.php: -------------------------------------------------------------------------------- 1 | client->get($this->fetchUrl('/zen')); 33 | 34 | if ($response->code != 200) { 35 | throw new \RuntimeException('Can\'t get a Zen'); 36 | } 37 | 38 | return $response->body; 39 | } 40 | } 41 | --------------------------------------------------------------------------------