AAAA.htaccess000066600000000177151372560460006364 0ustar00 Order allow,deny Deny from all pulls.php000066600000041316151372560460006436 0ustar00 $title, 'base' => $base, 'head' => $head, 'body' => $body ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to create a comment on a pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $pullId The pull request number. * @param string $body The comment body text. * @param string $commitId The SHA1 hash of the commit to comment on. * @param string $filePath The Relative path of the file to comment on. * @param string $position The line index in the diff to comment on. * * @return object * * @since 11.3 */ public function createComment($user, $repo, $pullId, $body, $commitId, $filePath, $position) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; // Build the request data. $data = json_encode( array( 'body' => $body, 'commit_id' => $commitId, 'path' => $filePath, 'position' => $position ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to create a comment in reply to another comment. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $pullId The pull request number. * @param string $body The comment body text. * @param integer $inReplyTo The id of the comment to reply to. * * @return object * * @since 11.3 */ public function createCommentReply($user, $repo, $pullId, $body, $inReplyTo) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; // Build the request data. $data = json_encode( array( 'body' => $body, 'in_reply_to' => (int) $inReplyTo ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to create a pull request from an existing issue. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $issueId The issue number for which to attach the new pull request. * @param string $base The branch (or git ref) you want your changes pulled into. This * should be an existing branch on the current repository. You cannot * submit a pull request to one repo that requests a merge to a base * of another repo. * @param string $head The branch (or git ref) where your changes are implemented. * * @return object * * @since 11.3 */ public function createFromIssue($user, $repo, $issueId, $base, $head) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls'; // Build the request data. $data = json_encode( array( 'issue' => (int) $issueId, 'base' => $base, 'head' => $head ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to delete a comment on a pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $commentId The id of the comment to delete. * * @return void * * @since 11.3 */ public function deleteComment($user, $repo, $commentId) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; // Send the request. $response = $this->client->delete($this->fetchUrl($path)); // Validate the response code. if ($response->code != 204) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } } /** * Method to update a pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $pullId The pull request number. * @param string $title The optional new title for the pull request. * @param string $body The optional new body text for the pull request. * @param string $state The optional new state for the pull request. [open, closed] * * @return object * * @since 11.3 */ public function edit($user, $repo, $pullId, $title = null, $body = null, $state = null) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId; // Craete the data object. $data = new stdClass; // If a title is set add it to the data object. if (isset($title)) { $data->title = $title; } // If a body is set add it to the data object. if (isset($body)) { $data->body = $body; } // If a state is set add it to the data object. if (isset($state)) { $data->state = $state; } // Encode the request data. $data = json_encode($data); // Send the request. $response = $this->client->patch($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to update a comment on a pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $commentId The id of the comment to update. * @param string $body The new body text for the comment. * * @return object * * @since 11.3 */ public function editComment($user, $repo, $commentId, $body) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; // Build the request data. $data = json_encode( array( 'body' => $body ) ); // Send the request. $response = $this->client->patch($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a single pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $pullId The pull request number. * * @return object * * @since 11.3 */ public function get($user, $repo, $pullId) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId; // Send the request. $response = $this->client->get($this->fetchUrl($path)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a specific comment on a pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $commentId The comment id to get. * * @return object * * @since 11.3 */ public function getComment($user, $repo, $commentId) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; // Send the request. $response = $this->client->get($this->fetchUrl($path)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get the list of comments on a pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $pullId The pull request number. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getComments($user, $repo, $pullId, $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a list of commits for a pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $pullId The pull request number. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getCommits($user, $repo, $pullId, $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/commits'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a list of files for a pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $pullId The pull request number. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getFiles($user, $repo, $pullId, $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/files'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to list pull requests. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param string $state The optional state to filter requests by. [open, closed] * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getList($user, $repo, $state = 'open', $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls'; // If a state exists append it as an option. if ($state != 'open') { $path .= '?state=' . $state; } // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to check if a pull request has been merged. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $pullId The pull request number. The pull request number. * * @return boolean True if the pull request has been merged. * * @since 11.3 */ public function isMerged($user, $repo, $pullId) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/merge'; // Send the request. $response = $this->client->get($this->fetchUrl($path)); // Validate the response code. if ($response->code == 204) { return true; } elseif ($response->code == 404) { return false; } else { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } } /** * Method to merge a pull request. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $pullId The pull request number. * @param string $message The message that will be used for the merge commit. * * @return object * * @since 11.3 */ public function merge($user, $repo, $pullId, $message = '') { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/merge'; // Build the request data. $data = json_encode( array( 'commit_message' => $message ) ); // Send the request. $response = $this->client->put($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } } issues.php000066600000031213151372560460006605 0ustar00 $title, 'assignee' => $assignee, 'milestone' => $milestone, 'labels' => $labels, 'body' => $body ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to create a comment on an issue. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $issueId The issue number. * @param string $body The comment body text. * * @return object * * @since 11.3 */ public function createComment($user, $repo, $issueId, $body) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; // Build the request data. $data = json_encode( array( 'body' => $body, ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to delete a comment on an issue. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $commentId The id of the comment to delete. * * @return void * * @since 11.3 */ public function deleteComment($user, $repo, $commentId) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; // Send the request. $response = $this->client->delete($this->fetchUrl($path)); // Validate the response code. if ($response->code != 204) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } } /** * Method to update an issue. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $issueId The issue number. * @param string $state The optional new state for the issue. [open, closed] * @param string $title The title of the new issue. * @param string $body The body text for the new issue. * @param string $assignee The login for the GitHub user that this issue should be assigned to. * @param integer $milestone The milestone to associate this issue with. * @param array $labels The labels to associate with this issue. * * @return object * * @since 11.3 */ public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, $milestone = null, array $labels = null) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; // Craete the data object. $data = new stdClass; // If a title is set add it to the data object. if (isset($title)) { $data->title = $title; } // If a body is set add it to the data object. if (isset($body)) { $data->body = $body; } // If a state is set add it to the data object. if (isset($state)) { $data->state = $state; } // If an assignee is set add it to the data object. if (isset($assignee)) { $data->assignee = $assignee; } // If a milestone is set add it to the data object. if (isset($milestone)) { $data->milestone = $milestone; } // If labels are set add them to the data object. if (isset($labels)) { // Ensure that we have a non-associative array. if (isset($labels)) { $labels = array_values($labels); } $data->labels = $labels; } // Encode the request data. $data = json_encode($data); // Send the request. $response = $this->client->patch($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to update a comment on an issue. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $commentId The id of the comment to update. * @param string $body The new body text for the comment. * * @return object * * @since 11.3 */ public function editComment($user, $repo, $commentId, $body) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; // Build the request data. $data = json_encode( array( 'body' => $body ) ); // Send the request. $response = $this->client->patch($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a single issue. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $issueId The issue number. * * @return object * * @since 11.3 */ public function get($user, $repo, $issueId) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; // Send the request. $response = $this->client->get($this->fetchUrl($path)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a specific comment on an issue. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $commentId The comment id to get. * * @return object * * @since 11.3 */ public function getComment($user, $repo, $commentId) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; // Send the request. $response = $this->client->get($this->fetchUrl($path)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get the list of comments on an issue. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $issueId The issue number. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getComments($user, $repo, $issueId, $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to list an authenticated user's issues. * * @param string $filter The filter type: assigned, created, mentioned, subscribed. * @param string $state The optional state to filter requests by. [open, closed] * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. * @param string $sort The sort order: created, updated, comments, default: created. * @param string $direction The list direction: asc or desc, default: desc. * @param JDate $since The date/time since when issues should be returned. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getList($filter = null, $state = null, $labels = null, $sort = null, $direction = null, JDate $since = null, $page = 0, $limit = 0) { // Build the request path. $path = '/issues'; //TODO Implement the filtering options. // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to list issues. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param string $milestone The milestone number, 'none', or *. * @param string $state The optional state to filter requests by. [open, closed] * @param string $assignee The assignee name, 'none', or *. * @param string $mentioned The GitHub user name. * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. * @param string $sort The sort order: created, updated, comments, default: created. * @param string $direction The list direction: asc or desc, default: desc. * @param JDate $since The date/time since when issues should be returned. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, $sort = null, $direction = null, JDate $since = null, $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues'; //TODO Implement the filtering options. // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } } gists.php000066600000033727151372560460006437 0ustar00 $this->buildFileData((array) $files), 'public' => (bool) $public, 'description' => $description ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to create a comment on a gist. * * @param integer $gistId The gist number. * @param string $body The comment body text. * * @return object * * @since 11.3 */ public function createComment($gistId, $body) { // Build the request path. $path = '/gists/' . (int) $gistId . '/comments'; // Build the request data. $data = json_encode( array( 'body' => $body, ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to delete a gist. * * @param integer $gistId The gist number. * * @return void * * @since 11.3 */ public function delete($gistId) { // Build the request path. $path = '/gists/' . (int) $gistId; // Send the request. $response = $this->client->delete($this->fetchUrl($path)); // Validate the response code. if ($response->code != 204) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } } /** * Method to delete a comment on a gist. * * @param integer $commentId The id of the comment to delete. * * @return void * * @since 11.3 */ public function deleteComment($commentId) { // Build the request path. $path = '/gists/comments/' . (int) $commentId; // Send the request. $response = $this->client->delete($this->fetchUrl($path)); // Validate the response code. if ($response->code != 204) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } } /** * Method to update a gist. * * @param integer $gistId The gist number. * @param mixed $files Either an array of file paths or a single file path as a string. * @param boolean $public True if the gist should be public. * @param string $description The description of the gist. * * @return object * * @since 11.3 */ public function edit($gistId, $files = null, $public = null, $description = null) { // Build the request path. $path = '/gists/' . (int) $gistId; // Craete the data object. $data = new stdClass; // If a description is set add it to the data object. if (isset($description)) { $data->description = $description; } // If the public flag is set add it to the data object. if (isset($public)) { $data->public = $public; } // If a state is set add it to the data object. if (isset($files)) { $data->files = $this->buildFileData((array) $files); } // Encode the request data. $data = json_encode($data); // Send the request. $response = $this->client->patch($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to update a comment on a gist. * * @param integer $commentId The id of the comment to update. * @param string $body The new body text for the comment. * * @return object * * @since 11.3 */ public function editComment($commentId, $body) { // Build the request path. $path = '/gists/comments/' . (int) $commentId; // Build the request data. $data = json_encode( array( 'body' => $body ) ); // Send the request. $response = $this->client->patch($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to fork a gist. * * @param integer $gistId The gist number. * * @return object * * @since 11.3 */ public function fork($gistId) { // Build the request path. $path = '/gists/' . (int) $gistId . '/fork'; // Send the request. // TODO: Verify change $response = $this->client->post($this->fetchUrl($path), ''); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a single gist. * * @param integer $gistId The gist number. * * @return object * * @since 11.3 */ public function get($gistId) { // Build the request path. $path = '/gists/' . (int) $gistId; // Send the request. $response = $this->client->get($this->fetchUrl($path)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a specific comment on a gist. * * @param integer $commentId The comment id to get. * * @return object * * @since 11.3 */ public function getComment($commentId) { // Build the request path. $path = '/gists/comments/' . (int) $commentId; // Send the request. $response = $this->client->get($this->fetchUrl($path)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get the list of comments on a gist. * * @param integer $gistId The gist number. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getComments($gistId, $page = 0, $limit = 0) { // Build the request path. $path = '/gists/' . (int) $gistId . '/comments'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to list gists. If a user is authenticated it will return the user's gists, otherwise * it will return all public gists. * * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getList($page = 0, $limit = 0) { // Build the request path. $path = '/gists'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a list of gists belonging to a given user. * * @param string $user The name of the GitHub user from which to list gists. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getListByUser($user, $page = 0, $limit = 0) { // Build the request path. $path = '/users/' . $user . '/gists'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a list of all public gists. * * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getListPublic($page = 0, $limit = 0) { // Build the request path. $path = '/gists/public'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a list of the authenticated users' starred gists. * * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return array * * @since 11.3 */ public function getListStarred($page = 0, $limit = 0) { // Build the request path. $path = '/gists/starred'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to check if a gist has been starred. * * @param integer $gistId The gist number. * * @return boolean True if the gist is starred. * * @since 11.3 */ public function isStarred($gistId) { // Build the request path. $path = '/gists/' . (int) $gistId . '/star'; // Send the request. $response = $this->client->get($this->fetchUrl($path)); // Validate the response code. if ($response->code == 204) { return true; } elseif ($response->code == 404) { return false; } else { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } } /** * Method to star a gist. * * @param integer $gistId The gist number. * * @return void * * @since 11.3 */ public function star($gistId) { // Build the request path. $path = '/gists/' . (int) $gistId . '/star'; // Send the request. $response = $this->client->put($this->fetchUrl($path), ''); // Validate the response code. if ($response->code != 204) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } } /** * Method to star a gist. * * @param integer $gistId The gist number. * * @return void * * @since 11.3 */ public function unstar($gistId) { // Build the request path. $path = '/gists/' . (int) $gistId . '/star'; // Send the request. $response = $this->client->delete($this->fetchUrl($path)); // Validate the response code. if ($response->code != 204) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } } /** * Method to fetch a data array for transmitting to the GitHub API for a list of files based on * an input array of file paths or filename and content pairs. * * @param array $files The list of file paths or filenames and content. * * @return array * * @since 11.3 */ protected function buildFileData(array $files) { // Initialize variables. $data = array(); foreach ($files as $key => $file) { // if the key isn't numeric, then we are dealing with a file whose content has been supplied if (!is_numeric($key)) { $data[$key] = array('content' => $file); } // otherwise, we have been given a path and we have to load the content // Verify that the each file exists. elseif (!file_exists($file)) { throw new InvalidArgumentException('The file ' . $file . ' does not exist.'); } else { $data[basename($file)] = array('content' => file_get_contents($file)); } } return $data; } } http.php000066600000003601151372560460006251 0ustar00options->def('userAgent', 'JGitHub/2.0'); // Set the default timeout to 120 seconds. $this->options->def('timeout', 120); } /** * Method to send the PATCH command to the server. * * @param string $url Path to the resource. * @param mixed $data Either an associative array or a string to be sent with the request. * @param array $headers An array of name-value pairs to include in the header of the request. * * @return JHttpResponse * * @since 11.3 */ public function patch($url, $data, array $headers = null) { return $this->transport->request('PATCH', new JUri($url), $data, $headers); } } github.php000066600000006512151372560460006560 0ustar00options = isset($options) ? $options : new JRegistry; $this->client = isset($client) ? $client : new JGithubHttp($this->options); // Setup the default API url if not already set. $this->options->def('api.url', 'https://api.github.com'); } /** * Magic method to lazily create API objects * * @param string $name Name of property to retrieve * * @return JGithubObject GitHub API object (gists, issues, pulls, etc). * * @since 11.3 */ public function __get($name) { if ($name == 'gists') { if ($this->gists == null) { $this->gists = new JGithubGists($this->options, $this->client); } return $this->gists; } if ($name == 'issues') { if ($this->issues == null) { $this->issues = new JGithubIssues($this->options, $this->client); } return $this->issues; } if ($name == 'pulls') { if ($this->pulls == null) { $this->pulls = new JGithubPulls($this->options, $this->client); } return $this->pulls; } if ($name == 'refs') { if ($this->refs == null) { $this->refs = new JGithubRefs($this->options, $this->client); } return $this->refs; } if ($name == 'forks') { if ($this->forks == null) { $this->forks = new JGithubForks($this->options, $this->client); } return $this->forks; } } /** * Get an option from the JGitHub instance. * * @param string $key The name of the option to get. * * @return mixed The option value. * * @since 11.3 */ public function getOption($key) { return $this->options->get($key); } /** * Set an option for the JGitHub instance. * * @param string $key The name of the option to set. * @param mixed $value The option value to set. * * @return JGitHub This object for method chaining. * * @since 11.3 */ public function setOption($key, $value) { $this->options->set($key, $value); return $this; } } forks.php000066600000004422151372560460006420 0ustar00 0) { $data = json_encode( array('org' => $org) ); } else { $data = json_encode(array()); } // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to list forks for a repository. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param integer $page Page to request * @param integer $limit Number of results to return per page * * @return array * * @since 11.4 */ public function getList($user, $repo, $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/forks'; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } } index.html000066600000000037151372560460006556 0ustar00 refs.php000066600000010547151372560460006240 0ustar00 $ref, 'sha' => $sha ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 201) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to update a reference. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param string $ref The reference to update. * @param string $sha The SHA1 value to set the reference to. * @param string $force Whether the update should be forced. Default to false. * * @return object * * @since 11.3 */ public function edit($user, $repo, $ref, $sha, $force = false) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref; // Craete the data object. $data = new stdClass; // If a title is set add it to the data object. if ($force) { $data->force = true; } $data->sha = $sha; // Encode the request data. $data = json_encode($data); // Send the request. $response = $this->client->patch($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to get a reference. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param string $ref The reference to get. * * @return object * * @since 11.3 */ public function get($user, $repo, $ref) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref; // Send the request. $response = $this->client->get($this->fetchUrl($path)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } /** * Method to list references for a repository. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param string $namespace Optional sub-namespace to limit the returned references. * @param integer $page Page to request * @param integer $limit Number of results to return per page * * @return array * * @since 11.3 */ public function getList($user, $repo, $namespace = '', $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/git/refs' . $namespace; // Send the request. $response = $this->client->get($this->fetchUrl($path, $page, $limit)); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } return json_decode($response->body); } } object.php000066600000004277151372560460006552 0ustar00options = isset($options) ? $options : new JRegistry; $this->client = isset($client) ? $client : new JGithubHttp($this->options); } /** * Method to build and return a full request URL for the request. This method will * add appropriate pagination details if necessary and also prepend the API url * to have a complete URL for the request. * * @param string $path URL to inflect * @param integer $page Page to request * @param integer $limit Number of results to return per page * * @return string The request URL. * * @since 11.3 */ protected function fetchUrl($path, $page = 0, $limit = 0) { // Get a new JUri object fousing the api url and given path. $uri = new JUri($this->options->get('api.url') . $path); if ($this->options->get('api.username', false)) { $uri->setUser($this->options->get('api.username')); } if ($this->options->get('api.password', false)) { $uri->setPass($this->options->get('api.password')); } // If we have a defined page number add it to the JUri object. if ($page > 0) { $uri->setVar('page', (int) $page); } // If we have a defined items per page add it to the JUri object. if ($limit > 0) { $uri->setVar('per_page', (int) $limit); } return (string) $uri; } }