first commit

This commit is contained in:
alazhar
2020-01-02 22:20:31 +07:00
commit 10eb3340ad
5753 changed files with 631345 additions and 0 deletions

View File

@ -0,0 +1,240 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Account class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 12.3
*/
class JGithubAccount extends JGithubObject
{
/**
* Method to create an authorisation.
*
* @param array $scopes A list of scopes that this authorisation is in.
* @param string $note A note to remind you what the OAuth token is for.
* @param string $url A URL to remind you what app the OAuth token is for.
*
* @return object
*
* @since 12.3
* @throws DomainException
*/
public function createAuthorisation(array $scopes = array(), $note = '', $url = '')
{
// Build the request path.
$path = '/authorizations';
$data = json_encode(
array('scopes' => $scopes, 'note' => $note, 'note_url' => $url)
);
// 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 an authorisation
*
* @param integer $id ID of the authorisation to delete
*
* @return object
*
* @since 12.3
* @throws DomainException
*/
public function deleteAuthorisation($id)
{
// Build the request path.
$path = '/authorizations/' . $id;
// 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);
}
return json_decode($response->body);
}
/**
* Method to edit an authorisation.
*
* @param integer $id ID of the authorisation to edit
* @param array $scopes Replaces the authorisation scopes with these.
* @param array $addScopes A list of scopes to add to this authorisation.
* @param array $removeScopes A list of scopes to remove from this authorisation.
* @param string $note A note to remind you what the OAuth token is for.
* @param string $url A URL to remind you what app the OAuth token is for.
*
* @return object
*
* @since 12.3
* @throws DomainException
* @throws RuntimeException
*/
public function editAuthorisation($id, array $scopes = array(), array $addScopes = array(), array $removeScopes = array(), $note = '', $url = '')
{
// Check if more than one scopes array contains data
$scopesCount = 0;
if (!empty($scopes))
{
$scope = 'scopes';
$scopeData = $scopes;
$scopesCount++;
}
if (!empty($addScopes))
{
$scope = 'add_scopes';
$scopeData = $addScopes;
$scopesCount++;
}
if (!empty($removeScopes))
{
$scope = 'remove_scopes';
$scopeData = $removeScopes;
$scopesCount++;
}
// Only allowed to send data for one scope parameter
if ($scopesCount >= 2)
{
throw new RuntimeException('You can only send one scope key in this request.');
}
// Build the request path.
$path = '/authorizations/' . $id;
$data = json_encode(
array(
$scope => $scopeData,
'note' => $note,
'note_url' => $url
)
);
// 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 details about an authorised application for the authenticated user.
*
* @param integer $id ID of the authorisation to retrieve
*
* @return object
*
* @since 12.3
* @note This method will only accept Basic Authentication
* @throws DomainException
*/
public function getAuthorisation($id)
{
// Build the request path.
$path = '/authorizations/' . $id;
// 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 authorised applications for the authenticated user.
*
* @return object
*
* @since 12.3
* @throws DomainException
* @note This method will only accept Basic Authentication
*/
public function getAuthorisations()
{
// Build the request path.
$path = '/authorizations';
// 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 rate limit for the authenticated user.
*
* @return object
*
* @since 12.3
* @throws DomainException
*/
public function getRateLimit()
{
// Build the request path.
$path = '/rate_limit';
// 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);
}
}

View File

@ -0,0 +1,357 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Commits class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 12.1
*/
class JGithubCommits extends JGithubObject
{
/**
* Method to create a commit.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $message The commit message.
* @param string $tree SHA of the tree object this commit points to.
* @param array $parents Array of the SHAs of the commits that were the parents of this commit.
* If omitted or empty, the commit will be written as a root commit.
* For a single parent, an array of one SHA should be provided.
* For a merge commit, an array of more than one should be provided.
*
* @return object
*
* @since 12.1
*/
public function create($user, $repo, $message, $tree, array $parents = array())
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/git/commits';
$data = json_encode(
array('message' => $message, 'tree' => $tree, 'parents' => $parents)
);
// 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 commit.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $sha The SHA of the commit to comment on.
* @param string $comment The text of the comment.
* @param integer $line The line number of the commit to comment on.
* @param string $filepath A relative path to the file to comment on within the commit.
* @param integer $position Line index in the diff to comment on.
*
* @return object
*
* @since 12.1
*/
public function createCommitComment($user, $repo, $sha, $comment, $line, $filepath, $position)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments';
$data = json_encode(
array(
'body' => $comment,
'commit_id' => $sha,
'line' => (int) $line,
'path' => $filepath,
'position' => (int) $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 delete a comment on a commit.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $id The ID of the comment to edit.
*
* @return object
*
* @since 12.1
*/
public function deleteCommitComment($user, $repo, $id)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/comments/' . $id;
// 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);
}
return json_decode($response->body);
}
/**
* Method to edit a comment on a commit.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $id The ID of the comment to edit.
* @param string $comment The text of the comment.
*
* @return object
*
* @since 12.1
*/
public function editCommitComment($user, $repo, $id, $comment)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/comments/' . $id;
$data = json_encode(
array(
'body' => $comment
)
);
// 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 commit 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 $sha The SHA of the commit to retrieve.
* @param integer $page Page to request
* @param integer $limit Number of results to return per page
*
* @return array
*
* @since 12.1
*/
public function getCommit($user, $repo, $sha, $page = 0, $limit = 0)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha;
// 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 single comment on a commit.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $id ID of the comment to retrieve
*
* @return array
*
* @since 12.1
*/
public function getCommitComment($user, $repo, $id)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/comments/' . $id;
// 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 list of comments for a single commit 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 $sha The SHA of the commit to retrieve.
* @param integer $page Page to request
* @param integer $limit Number of results to return per page
*
* @return array
*
* @since 12.1
*/
public function getCommitComments($user, $repo, $sha, $page = 0, $limit = 0)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/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 diff for two commits.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $base The base of the diff, either a commit SHA or branch.
* @param string $head The head of the diff, either a commit SHA or branch.
*
* @return array
*
* @since 12.1
*/
public function getDiff($user, $repo, $base, $head)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/compare/' . $base . '...' . $head;
// 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 commits 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 12.1
*/
public function getList($user, $repo, $page = 0, $limit = 0)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/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 commit comments 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 12.1
*/
public function getListComments($user, $repo, $page = 0, $limit = 0)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/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);
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Forks class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 11.3
*/
class JGithubForks extends JGithubObject
{
/**
* Method to fork 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 $org The organization to fork the repo into. By default it is forked to the current user.
*
* @return object
*
* @since 11.4
* @throws DomainException
*/
public function create($user, $repo, $org = '')
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/forks';
if (strlen($org) > 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 != 202)
{
// 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
* @throws DomainException
*/
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);
}
}

View File

@ -0,0 +1,593 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Gists class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 11.3
*/
class JGithubGists extends JGithubObject
{
/**
* Method to create a gist.
*
* @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 optional description of the gist.
*
* @return object
*
* @since 11.3
*/
public function create($files, $public = false, $description = null)
{
// Build the request path.
$path = '/gists';
// Build the request data.
$data = json_encode(
array(
'files' => $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)
{
$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;
}
}

View File

@ -0,0 +1,192 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla Platform class for interacting with a GitHub server instance.
*
* @property-read JGithubGists $gists GitHub API object for gists.
* @property-read JGithubIssues $issues GitHub API object for issues.
* @property-read JGithubPulls $pulls GitHub API object for pulls.
* @property-read JGithubRefs $refs GitHub API object for referencess.
* @property-read JGithubForks $forks GitHub API object for forks.
* @property-read JGithubCommits $commits GitHub API object for commits.
* @property-read JGithubMilestones $milestones GitHub API object for commits.
* @property-read JGithubStatuses $statuses GitHub API object for commits.
* @property-read JGithubAccount $account GitHub API object for account references.
* @property-read JGithubHooks $hooks GitHub API object for hooks.
* @property-read JGithubUsers $users GitHub API object for users.
* @property-read JGithubMeta $meta GitHub API object for meta.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 11.3
*/
class JGithub
{
/**
* @var JRegistry Options for the GitHub object.
* @since 11.3
*/
protected $options;
/**
* @var JGithubHttp The HTTP client object to use in sending HTTP requests.
* @since 11.3
*/
protected $client;
/**
* @var JGithubGists GitHub API object for gists.
* @since 11.3
*/
protected $gists;
/**
* @var JGithubIssues GitHub API object for issues.
* @since 11.3
*/
protected $issues;
/**
* @var JGithubPulls GitHub API object for pulls.
* @since 11.3
*/
protected $pulls;
/**
* @var JGithubRefs GitHub API object for referencess.
* @since 11.3
*/
protected $refs;
/**
* @var JGithubForks GitHub API object for forks.
* @since 11.3
*/
protected $forks;
/**
* @var JGithubCommits GitHub API object for commits.
* @since 12.1
*/
protected $commits;
/**
* @var JGithubMilestones GitHub API object for milestones.
* @since 12.3
*/
protected $milestones;
/**
* @var JGithubStatuses GitHub API object for statuses.
* @since 12.3
*/
protected $statuses;
/**
* @var JGithubAccount GitHub API object for account references.
* @since 12.3
*/
protected $account;
/**
* @var JGithubHooks GitHub API object for hooks.
* @since 12.3
*/
protected $hooks;
/**
* @var JGithubUsers GitHub API object for users.
* @since 12.4
*/
protected $users;
/**
* @var JGithubMeta GitHub API object for meta.
* @since 13.1
*/
protected $meta;
/**
* Constructor.
*
* @param JRegistry $options GitHub options object.
* @param JGithubHttp $client The HTTP client object.
*
* @since 11.3
*/
public function __construct(JRegistry $options = null, JGithubHttp $client = null)
{
$this->options = 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
* @throws InvalidArgumentException
*/
public function __get($name)
{
$class = 'JGithub' . ucfirst($name);
if (class_exists($class))
{
if (false == isset($this->$name))
{
$this->$name = new $class($this->options, $this->client);
}
return $this->$name;
}
throw new InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class));
}
/**
* 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;
}
}

View File

@ -0,0 +1,226 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Hooks class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 12.3
*/
class JGithubHooks extends JGithubObject
{
/**
* Array containing the allowed hook events
*
* @var array
* @since 12.3
*/
protected $events = array(
'push', 'issues', 'issue_comment', 'commit_comment', 'pull_request', 'gollum', 'watch', 'download', 'fork', 'fork_apply',
'member', 'public', 'status'
);
/**
* Method to create a hook on 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 $name The name of the service being called.
* @param array $config Array containing the config for the service.
* @param array $events The events the hook will be triggered for.
* @param boolean $active Flag to determine if the hook is active
*
* @return object
*
* @since 12.3
* @throws DomainException
* @throws RuntimeException
*/
public function create($user, $repo, $name, array $config, array $events = array('push'), $active = true)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks';
// Check to ensure all events are in the allowed list
foreach ($events as $event)
{
if (!in_array($event, $this->events))
{
throw new RuntimeException('Your events array contains an unauthorized event.');
}
}
$data = json_encode(
array('name' => $name, 'config' => $config, 'events' => $events, 'active' => $active)
);
return $this->processResponse(
$this->client->post($this->fetchUrl($path), $data),
201
);
}
/**
* Method to delete a hook
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $id ID of the hook to delete.
*
* @return object
*
* @since 12.3
* @throws DomainException
*/
public function delete($user, $repo, $id)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id;
return $this->processResponse(
$this->client->delete($this->fetchUrl($path)),
204
);
}
/**
* Method to edit a hook.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $id ID of the hook to edit.
* @param string $name The name of the service being called.
* @param array $config Array containing the config for the service.
* @param array $events The events the hook will be triggered for. This resets the currently set list
* @param array $addEvents Events to add to the hook.
* @param array $removeEvents Events to remove from the hook.
* @param boolean $active Flag to determine if the hook is active
*
* @return object
*
* @since 12.3
* @throws DomainException
* @throws RuntimeException
*/
public function edit($user, $repo, $id, $name, array $config, array $events = array('push'), array $addEvents = array(),
array $removeEvents = array(), $active = true)
{
// Check to ensure all events are in the allowed list
foreach ($events as $event)
{
if (!in_array($event, $this->events))
{
throw new RuntimeException('Your events array contains an unauthorized event.');
}
}
foreach ($addEvents as $event)
{
if (!in_array($event, $this->events))
{
throw new RuntimeException('Your active_events array contains an unauthorized event.');
}
}
foreach ($removeEvents as $event)
{
if (!in_array($event, $this->events))
{
throw new RuntimeException('Your remove_events array contains an unauthorized event.');
}
}
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id;
$data = json_encode(
array(
'name' => $name,
'config' => $config,
'events' => $events,
'add_events' => $addEvents,
'remove_events' => $removeEvents,
'active' => $active)
);
return $this->processResponse(
$this->client->patch($this->fetchUrl($path), $data)
);
}
/**
* Method to get details about a single hook for the repository.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $id ID of the hook to retrieve
*
* @return object
*
* @since 12.3
* @throws DomainException
*/
public function get($user, $repo, $id)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id;
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* Method to list hooks 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 object
*
* @since 12.3
* @throws DomainException
*/
public function getList($user, $repo, $page = 0, $limit = 0)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks';
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* Method to test a hook against the latest repository commit
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $id ID of the hook to delete
*
* @return object
*
* @since 12.3
* @throws DomainException
*/
public function test($user, $repo, $id)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id . '/test';
return $this->processResponse(
$this->client->post($this->fetchUrl($path), json_encode('')),
204
);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* HTTP client class for connecting to a GitHub instance.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 11.3
*/
class JGithubHttp extends JHttp
{
/**
* @const integer Use no authentication for HTTP connections.
* @since 11.3
*/
const AUTHENTICATION_NONE = 0;
/**
* @const integer Use basic authentication for HTTP connections.
* @since 11.3
*/
const AUTHENTICATION_BASIC = 1;
/**
* @const integer Use OAuth authentication for HTTP connections.
* @since 11.3
*/
const AUTHENTICATION_OAUTH = 2;
/**
* Constructor.
*
* @param JRegistry $options Client options object.
* @param JHttpTransport $transport The HTTP transport object.
*
* @since 11.3
*/
public function __construct(JRegistry $options = null, JHttpTransport $transport = null)
{
// Call the JHttp constructor to setup the object.
parent::__construct($options, $transport);
// Make sure the user agent string is defined.
$this->options->def('userAgent', 'JGitHub/2.0');
// Set the default timeout to 120 seconds.
$this->options->def('timeout', 120);
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,636 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Issues class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 11.3
*/
class JGithubIssues extends JGithubObject
{
/**
* Method to create an issue.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @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 create($user, $repo, $title, $body = null, $assignee = null, $milestone = null, array $labels = null)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/issues';
// Ensure that we have a non-associative array.
if (isset($labels))
{
$labels = array_values($labels);
}
// Build the request data.
$data = json_encode(
array(
'title' => $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 create a label on a repo.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $name The label name.
* @param string $color The label color.
*
* @return object
*
* @since 12.3
*/
public function createLabel($user, $repo, $name, $color)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/labels';
// Build the request data.
$data = json_encode(
array(
'name' => $name,
'color' => $color
)
);
// 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 delete a label on a repo.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $label The label name.
*
* @return object
*
* @since 12.3
*/
public function deleteLabel($user, $repo, $label)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/labels/' . $label;
// 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 update a label on a repo.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $label The label name.
* @param string $name The label name.
* @param string $color The label color.
*
* @return object
*
* @since 12.3
*/
public function editLabel($user, $repo, $label, $name, $color)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/labels/' . $label;
// Build the request data.
$data = json_encode(
array(
'name' => $name,
'color' => $color
)
);
// 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 get a specific label on a repo.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $name The label name to get.
*
* @return object
*
* @since 12.3
*/
public function getLabel($user, $repo, $name)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/labels/' . $name;
// 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 labels on a repo.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
*
* @return array
*
* @since 12.3
*/
public function getLabels($user, $repo)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/labels';
// 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 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';
$uri = new JUri($this->fetchUrl($path, $page, $limit));
if ($milestone)
{
$uri->setVar('milestone', $milestone);
}
if ($state)
{
$uri->setVar('state', $state);
}
if ($assignee)
{
$uri->setVar('assignee', $assignee);
}
if ($mentioned)
{
$uri->setVar('mentioned', $mentioned);
}
if ($labels)
{
$uri->setVar('labels', $labels);
}
if ($sort)
{
$uri->setVar('sort', $sort);
}
if ($direction)
{
$uri->setVar('direction', $direction);
}
if ($since)
{
$uri->setVar('since', $since->toISO8601());
}
// Send the request.
$response = $this->client->get((string) $uri);
// 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);
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Meta class.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 13.1
*/
class JGithubMeta extends JGithubObject
{
/**
* Method to get the authorized IP addresses for services
*
* @return array Authorized IP addresses
*
* @since 13.1
* @throws DomainException
*/
public function getMeta()
{
// Build the request path.
$path = '/meta';
$githubIps = $this->processResponse($this->client->get($this->fetchUrl($path)), 200);
/*
* The response body returns the IP addresses in CIDR format
* Decode the response body and strip the subnet mask information prior to
* returning the data to the user. We're assuming quite a bit here that all
* masks will be /32 as they are as of the time of development.
*/
$authorizedIps = array();
foreach ($githubIps as $key => $serviceIps)
{
// The first level contains an array of IPs based on the service
$authorizedIps[$key] = array();
foreach ($serviceIps as $serviceIp)
{
// The second level is each individual IP address, strip the mask here
$authorizedIps[$key][] = substr($serviceIp, 0, -3);
}
}
return $authorizedIps;
}
}

View File

@ -0,0 +1,230 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Milestones class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 12.3
*/
class JGithubMilestones extends JGithubObject
{
/**
* Method to get the list of milestones for a repo.
*
* @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 milestone state to retrieved. Open (default) or closed.
* @param string $sort Sort can be due_date (default) or completeness.
* @param string $direction Direction is asc or desc (default).
* @param integer $page The page number from which to get items.
* @param integer $limit The number of items on a page.
*
* @return array
*
* @since 12.3
*/
public function getList($user, $repo, $state = 'open', $sort = 'due_date', $direction = 'desc', $page = 0, $limit = 0)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/milestones?';
$path .= 'state=' . $state;
$path .= '&sort=' . $sort;
$path .= '&direction=' . $direction;
// 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 specific milestone.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $milestoneId The milestone id to get.
*
* @return object
*
* @since 12.3
*/
public function get($user, $repo, $milestoneId)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId;
// 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 create a milestone 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 $title The title of the milestone.
* @param string $state Can be open (default) or closed.
* @param string $description Optional description for milestone.
* @param string $due_on Optional ISO 8601 time.
*
* @return object
*
* @since 12.3
*/
public function create($user, $repo, $title, $state = null, $description = null, $due_on = null)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/milestones';
// Build the request data.
$data = array(
'title' => $title
);
if (!is_null($state))
{
$data['state'] = $state;
}
if (!is_null($description))
{
$data['description'] = $description;
}
if (!is_null($due_on))
{
$data['due_on'] = $due_on;
}
$data = json_encode($data);
// 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 milestone.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $milestoneId The id of the comment to update.
* @param integer $title Optional title of the milestone.
* @param string $state Can be open (default) or closed.
* @param string $description Optional description for milestone.
* @param string $due_on Optional ISO 8601 time.
*
* @return object
*
* @since 12.3
*/
public function edit($user, $repo, $milestoneId, $title = null, $state = null, $description = null, $due_on = null)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId;
// Build the request data.
$data = array();
if (!is_null($title))
{
$data['title'] = $title;
}
if (!is_null($state))
{
$data['state'] = $state;
}
if (!is_null($description))
{
$data['description'] = $description;
}
if (!is_null($due_on))
{
$data['due_on'] = $due_on;
}
$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 delete a milestone.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $milestoneId The id of the milestone to delete.
*
* @return void
*
* @since 12.3
*/
public function delete($user, $repo, $milestoneId)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId;
// 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);
}
}
}

View File

@ -0,0 +1,121 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API object class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 11.3
*/
abstract class JGithubObject
{
/**
* @var JRegistry Options for the GitHub object.
* @since 11.3
*/
protected $options;
/**
* @var JGithubHttp The HTTP client object to use in sending HTTP requests.
* @since 11.3
*/
protected $client;
/**
* Constructor.
*
* @param JRegistry $options GitHub options object.
* @param JGithubHttp $client The HTTP client object.
*
* @since 11.3
*/
public function __construct(JRegistry $options = null, JGithubHttp $client = null)
{
$this->options = 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('gh.token', false))
{
// Use oAuth authentication - @todo set in request header ?
$uri->setVar('access_token', $this->options->get('gh.token'));
}
else
{
// Use basic authentication
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;
}
/**
* Process the response and decode it.
*
* @param JHttpResponse $response The response.
* @param integer $expectedCode The expected "good" code.
*
* @throws DomainException
*
* @return mixed
*/
protected function processResponse(JHttpResponse $response, $expectedCode = 200)
{
// Validate the response code.
if ($response->code != $expectedCode)
{
// 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);
}
}

View File

@ -0,0 +1,585 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Pull Requests class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 11.3
*/
class JGithubPulls extends JGithubObject
{
/**
* Method to create 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 string $title The title of 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.
* @param string $body The body text for the new pull request.
*
* @return object
*
* @since 11.3
*/
public function create($user, $repo, $title, $base, $head, $body = '')
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/pulls';
// Build the request data.
$data = json_encode(
array(
'title' => $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);
}
}

View File

@ -0,0 +1,167 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API References class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 11.3
*/
class JGithubRefs extends JGithubObject
{
/**
* Method to create an issue.
*
* @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 name of the fully qualified reference.
* @param string $sha The SHA1 value to set this reference to.
*
* @return object
*
* @since 11.3
*/
public function create($user, $repo, $ref, $sha)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/git/refs';
// Build the request data.
$data = json_encode(
array(
'ref' => $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);
}
}

View File

@ -0,0 +1,103 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API References class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 12.3
*/
class JGithubStatuses extends JGithubObject
{
/**
* Method to create a status.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $sha The SHA1 value for which to set the status.
* @param string $state The state (pending, success, error or failure).
* @param string $targetUrl Optional target URL.
* @param string $description Optional description for the status.
*
* @return object
*
* @since 12.3
*/
public function create($user, $repo, $sha, $state, $targetUrl = null, $description = null)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/statuses/' . $sha;
if (!in_array($state, array('pending', 'success', 'error', 'failure')))
{
throw new InvalidArgumentException('State must be one of pending, success, error or failure.');
}
// Build the request data.
$data = array(
'state' => $state
);
if (!is_null($targetUrl))
{
$data['target_url'] = $targetUrl;
}
if (!is_null($description))
{
$data['description'] = $description;
}
// Send the request.
$response = $this->client->post($this->fetchUrl($path), json_encode($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 statuses for an SHA.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $sha SHA1 for which to get the statuses.
*
* @return array
*
* @since 12.3
*/
public function getList($user, $repo, $sha)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/statuses/' . $sha;
// 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);
}
}

View File

@ -0,0 +1,150 @@
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API References class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage GitHub
* @since 12.3
*/
class JGithubUsers extends JGithubObject
{
/**
* Get a single user.
*
* @param string $user The users login name.
*
* @throws DomainException
*
* @return mixed
*/
public function getUser($user)
{
// Build the request path.
$path = '/users/' . $user;
// 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);
}
/**
* Get the current authenticated user.
*
* @throws DomainException
*
* @return mixed
*/
public function getAuthenticatedUser()
{
// Build the request path.
$path = '/user';
// 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);
}
/**
* Update a user.
*
* @param string $name The full name
* @param string $email The email
* @param string $blog The blog
* @param string $company The company
* @param string $location The location
* @param string $hireable If he is unemplayed :P
* @param string $bio The biometrical DNA fingerprint (or smthng...)
*
* @throws DomainException
*
* @return mixed
*/
public function updateUser($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '')
{
$data = array(
'name' => $name,
'email' => $email,
'blog' => $blog,
'company' => $company,
'location' => $location,
'hireable' => $hireable,
'bio' => $bio
);
// Build the request path.
$path = '/user';
// Send the request.
$response = $this->client->patch($this->fetchUrl($path), json_encode($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);
}
/**
* Get all users.
*
* This provides a dump of every user, in the order that they signed up for GitHub.
*
* @param integer $since The integer ID of the last User that youve seen.
*
* @throws DomainException
* @return mixed
*/
public function getUsers($since = 0)
{
// Build the request path.
$path = '/users';
$path .= ($since) ? '?since=' . $since : '';
// 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);
}
}