This commit is contained in:
Chris
2018-10-18 15:59:38 +01:00
parent 4f6a0cb7c6
commit 380a0e8623
352 changed files with 32929 additions and 3604 deletions

View File

@@ -0,0 +1,243 @@
<?php
namespace Github\Api;
use Github\Client;
use Github\HttpClient\Message\ResponseMediator;
/**
* Abstract class for Api classes.
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
abstract class AbstractApi implements ApiInterface
{
/**
* The client.
*
* @var Client
*/
protected $client;
/**
* The requested page (GitHub pagination).
*
* @var null|int
*/
private $page;
/**
* Number of items per page (GitHub pagination).
*
* @var null|int
*/
protected $perPage;
/**
* @param Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
}
public function configure()
{
}
/**
* @return null|int
*/
public function getPage()
{
return $this->page;
}
/**
* @param null|int $page
*/
public function setPage($page)
{
$this->page = (null === $page ? $page : (int) $page);
return $this;
}
/**
* @return null|int
*/
public function getPerPage()
{
return $this->perPage;
}
/**
* @param null|int $perPage
*/
public function setPerPage($perPage)
{
$this->perPage = (null === $perPage ? $perPage : (int) $perPage);
return $this;
}
/**
* Send a GET request with query parameters.
*
* @param string $path Request path.
* @param array $parameters GET parameters.
* @param array $requestHeaders Request Headers.
*
* @return array|string
*/
protected function get($path, array $parameters = [], array $requestHeaders = [])
{
if (null !== $this->page && !isset($parameters['page'])) {
$parameters['page'] = $this->page;
}
if (null !== $this->perPage && !isset($parameters['per_page'])) {
$parameters['per_page'] = $this->perPage;
}
if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) {
unset($parameters['ref']);
}
if (count($parameters) > 0) {
$path .= '?'.http_build_query($parameters);
}
$response = $this->client->getHttpClient()->get($path, $requestHeaders);
return ResponseMediator::getContent($response);
}
/**
* Send a HEAD request with query parameters.
*
* @param string $path Request path.
* @param array $parameters HEAD parameters.
* @param array $requestHeaders Request headers.
*
* @return \Psr\Http\Message\ResponseInterface
*/
protected function head($path, array $parameters = [], array $requestHeaders = [])
{
if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) {
unset($parameters['ref']);
}
$response = $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters), $requestHeaders);
return $response;
}
/**
* Send a POST request with JSON-encoded parameters.
*
* @param string $path Request path.
* @param array $parameters POST parameters to be JSON encoded.
* @param array $requestHeaders Request headers.
*
* @return array|string
*/
protected function post($path, array $parameters = [], array $requestHeaders = [])
{
return $this->postRaw(
$path,
$this->createJsonBody($parameters),
$requestHeaders
);
}
/**
* Send a POST request with raw data.
*
* @param string $path Request path.
* @param string $body Request body.
* @param array $requestHeaders Request headers.
*
* @return array|string
*/
protected function postRaw($path, $body, array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->post(
$path,
$requestHeaders,
$body
);
return ResponseMediator::getContent($response);
}
/**
* Send a PATCH request with JSON-encoded parameters.
*
* @param string $path Request path.
* @param array $parameters POST parameters to be JSON encoded.
* @param array $requestHeaders Request headers.
*
* @return array|string
*/
protected function patch($path, array $parameters = [], array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->patch(
$path,
$requestHeaders,
$this->createJsonBody($parameters)
);
return ResponseMediator::getContent($response);
}
/**
* Send a PUT request with JSON-encoded parameters.
*
* @param string $path Request path.
* @param array $parameters POST parameters to be JSON encoded.
* @param array $requestHeaders Request headers.
*
* @return array|string
*/
protected function put($path, array $parameters = [], array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->put(
$path,
$requestHeaders,
$this->createJsonBody($parameters)
);
return ResponseMediator::getContent($response);
}
/**
* Send a DELETE request with JSON-encoded parameters.
*
* @param string $path Request path.
* @param array $parameters POST parameters to be JSON encoded.
* @param array $requestHeaders Request headers.
*
* @return array|string
*/
protected function delete($path, array $parameters = [], array $requestHeaders = [])
{
$response = $this->client->getHttpClient()->delete(
$path,
$requestHeaders,
$this->createJsonBody($parameters)
);
return ResponseMediator::getContent($response);
}
/**
* Create a JSON encoded version of an array of parameters.
*
* @param array $parameters Request parameters
*
* @return null|string
*/
protected function createJsonBody(array $parameters)
{
return (count($parameters) === 0) ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0);
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Github\Api;
/**
* A trait to make sure we add accept headers on all requests.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
trait AcceptHeaderTrait
{
protected $acceptHeaderValue = null;
protected function get($path, array $parameters = [], array $requestHeaders = [])
{
return parent::get($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function head($path, array $parameters = [], array $requestHeaders = [])
{
return parent::head($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function post($path, array $parameters = [], array $requestHeaders = [])
{
return parent::post($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function postRaw($path, $body, array $requestHeaders = [])
{
return parent::postRaw($path, $body, $this->mergeHeaders($requestHeaders));
}
protected function patch($path, array $parameters = [], array $requestHeaders = [])
{
return parent::patch($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function put($path, array $parameters = [], array $requestHeaders = [])
{
return parent::put($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function delete($path, array $parameters = [], array $requestHeaders = [])
{
return parent::delete($path, $parameters, $this->mergeHeaders($requestHeaders));
}
/**
* Append a new accept header on all requests.
*
* @return array
*/
private function mergeHeaders(array $headers = [])
{
$default = [];
if ($this->acceptHeaderValue) {
$default = ['Accept' => $this->acceptHeaderValue];
}
return array_merge($default, $headers);
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Github\Api;
/**
* Api interface.
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
interface ApiInterface
{
public function getPerPage();
public function setPerPage($perPage);
}

View File

@@ -0,0 +1,93 @@
<?php
namespace Github\Api;
/**
* @link https://developer.github.com/v3/apps/
*
* @author Nils Adermann <naderman@naderman.de>
*/
class Apps extends AbstractApi
{
/**
* Create an access token for an installation.
*
* @param int $installationId An integration installation id
* @param int $userId An optional user id on behalf of whom the
* token will be requested
*
* @link https://developer.github.com/v3/apps/#create-a-new-installation-token
*
* @return array token and token metadata
*/
public function createInstallationToken($installationId, $userId = null)
{
$parameters = [];
if ($userId) {
$parameters['user_id'] = $userId;
}
return $this->post('/app/installations/'.rawurlencode($installationId).'/access_tokens', $parameters);
}
/**
* Find all installations for the authenticated application.
*
* @link https://developer.github.com/v3/apps/#find-installations
*
* @return array
*/
public function findInstallations()
{
return $this->get('/app/installations');
}
/**
* List repositories that are accessible to the authenticated installation.
*
* @link https://developer.github.com/v3/apps/installations/#list-repositories
*
* @param int $userId
*
* @return array
*/
public function listRepositories($userId = null)
{
$parameters = [];
if ($userId) {
$parameters['user_id'] = $userId;
}
return $this->get('/installation/repositories', $parameters);
}
/**
* Add a single repository to an installation.
*
* @link https://developer.github.com/v3/apps/installations/#add-repository-to-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function addRepository($installationId, $repositoryId)
{
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
}
/**
* Remove a single repository from an installation.
*
* @link https://developer.github.com/v3/apps/installations/#remove-repository-from-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function removeRepository($installationId, $repositoryId)
{
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
}
}

View File

@@ -0,0 +1,122 @@
<?php
namespace Github\Api;
/**
* Creating, deleting and listing authorizations.
*
* @link http://developer.github.com/v3/oauth_authorizations/
*
* @author Evgeniy Guseletov <d46k16@gmail.com>
*/
class Authorizations extends AbstractApi
{
/**
* List all authorizations.
*
* @return array
*/
public function all()
{
return $this->get('/authorizations');
}
/**
* Show a single authorization.
*
* @param $clientId
*
* @return array
*/
public function show($clientId)
{
return $this->get('/authorizations/'.rawurlencode($clientId));
}
/**
* Create an authorization.
*
* @param array $params
* @param null $OTPCode
*
* @return array
*/
public function create(array $params, $OTPCode = null)
{
$headers = null === $OTPCode ? [] : ['X-GitHub-OTP' => $OTPCode];
return $this->post('/authorizations', $params, $headers);
}
/**
* Update an authorization.
*
* @param $clientId
* @param array $params
*
* @return array
*/
public function update($clientId, array $params)
{
return $this->patch('/authorizations/'.rawurlencode($clientId), $params);
}
/**
* Remove an authorization.
*
* @param $clientId
*
* @return array
*/
public function remove($clientId)
{
return $this->delete('/authorizations/'.rawurlencode($clientId));
}
/**
* Check an authorization.
*
* @param $clientId
* @param $token
*
* @return array
*/
public function check($clientId, $token)
{
return $this->get('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
}
/**
* Reset an authorization.
*
* @param $clientId
* @param $token
*
* @return array
*/
public function reset($clientId, $token)
{
return $this->post('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
}
/**
* Remove an authorization.
*
* @param $clientId
* @param $token
*/
public function revoke($clientId, $token)
{
$this->delete('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
}
/**
* Revoke all authorizations.
*
* @param $clientId
*/
public function revokeAll($clientId)
{
$this->delete('/applications/'.rawurlencode($clientId).'/tokens');
}
}

View File

@@ -0,0 +1,207 @@
<?php
namespace Github\Api;
use Github\Api\CurrentUser\Emails;
use Github\Api\CurrentUser\Followers;
use Github\Api\CurrentUser\Memberships;
use Github\Api\CurrentUser\Notifications;
use Github\Api\CurrentUser\PublicKeys;
use Github\Api\CurrentUser\Starring;
use Github\Api\CurrentUser\Watchers;
/**
* @link http://developer.github.com/v3/users/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Felipe Valtl de Mello <eu@felipe.im>
*/
class CurrentUser extends AbstractApi
{
public function show()
{
return $this->get('/user');
}
public function update(array $params)
{
return $this->patch('/user', $params);
}
/**
* @return Emails
*/
public function emails()
{
return new Emails($this->client);
}
/**
* @return Followers
*/
public function follow()
{
return new Followers($this->client);
}
public function followers($page = 1)
{
return $this->get('/user/followers', [
'page' => $page,
]);
}
/**
* @link http://developer.github.com/v3/issues/#list-issues
*
* @param array $params
* @param bool $includeOrgIssues
*
* @return array
*/
public function issues(array $params = [], $includeOrgIssues = true)
{
return $this->get($includeOrgIssues ? '/issues' : '/user/issues', array_merge(['page' => 1], $params));
}
/**
* @return PublicKeys
*/
public function keys()
{
return new PublicKeys($this->client);
}
/**
* @return Notifications
*/
public function notifications()
{
return new Notifications($this->client);
}
/**
* @return Memberships
*/
public function memberships()
{
return new Memberships($this->client);
}
/**
* @link http://developer.github.com/v3/orgs/#list-user-organizations
*
* @return array
*/
public function organizations()
{
return $this->get('/user/orgs');
}
/**
* @link https://developer.github.com/v3/orgs/teams/#list-user-teams
*
* @return array
*/
public function teams()
{
return $this->get('/user/teams');
}
/**
* @link http://developer.github.com/v3/repos/#list-your-repositories
*
* @param string $type role in the repository
* @param string $sort sort by
* @param string $direction direction of sort, asc or desc
* @param string $visibility visibility of repository
* @param string $affiliation relationship to repository
*
* @return array
*/
public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = null, $affiliation = null)
{
$params = [
'type' => $type,
'sort' => $sort,
'direction' => $direction,
];
if (null !== $visibility) {
unset($params['type']);
$params['visibility'] = $visibility;
}
if (null !== $affiliation) {
unset($params['type']);
$params['affiliation'] = $affiliation;
}
return $this->get('/user/repos', $params);
}
/**
* @return Watchers
*/
public function watchers()
{
return new Watchers($this->client);
}
/**
* @deprecated Use watchers() instead
*/
public function watched($page = 1)
{
return $this->get('/user/watched', [
'page' => $page,
]);
}
/**
* @return Starring
*/
public function starring()
{
return new Starring($this->client);
}
/**
* @deprecated Use starring() instead
*/
public function starred($page = 1)
{
return $this->get('/user/starred', [
'page' => $page,
]);
}
/**
* @link https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
*/
public function subscriptions()
{
return $this->get('/user/subscriptions');
}
/**
* @link https://developer.github.com/v3/integrations/#list-installations-for-user
*
* @param array $params
*/
public function installations(array $params = [])
{
return $this->get('/user/installations', array_merge(['page' => 1], $params));
}
/**
* @link https://developer.github.com/v3/integrations/installations/#list-repositories-accessible-to-the-user-for-an-installation
*
* @param string $installationId the ID of the Installation
* @param array $params
*/
public function repositoriesByInstallation($installationId, array $params = [])
{
return $this->get(sprintf('/user/installations/%s/repositories', $installationId), array_merge(['page' => 1], $params));
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace Github\Api\CurrentUser;
use Github\Api\AbstractApi;
use Github\Exception\InvalidArgumentException;
/**
* @link http://developer.github.com/v3/users/emails/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Emails extends AbstractApi
{
/**
* List emails for the authenticated user.
*
* @link http://developer.github.com/v3/users/emails/
*
* @return array
*/
public function all()
{
return $this->get('/user/emails');
}
/**
* List public email addresses for a user.
*
* @link https://developer.github.com/v3/users/emails/#list-public-email-addresses-for-a-user
*
* @return array
*/
public function allPublic()
{
return $this->get('/user/public_emails');
}
/**
* Adds one or more email for the authenticated user.
*
* @link http://developer.github.com/v3/users/emails/
*
* @param string|array $emails
*
* @throws \Github\Exception\InvalidArgumentException
*
* @return array
*/
public function add($emails)
{
if (is_string($emails)) {
$emails = [$emails];
} elseif (0 === count($emails)) {
throw new InvalidArgumentException();
}
return $this->post('/user/emails', $emails);
}
/**
* Removes one or more email for the authenticated user.
*
* @link http://developer.github.com/v3/users/emails/
*
* @param string|array $emails
*
* @throws \Github\Exception\InvalidArgumentException
*
* @return array
*/
public function remove($emails)
{
if (is_string($emails)) {
$emails = [$emails];
} elseif (0 === count($emails)) {
throw new InvalidArgumentException();
}
return $this->delete('/user/emails', $emails);
}
/**
* Toggle primary email visibility.
*
* @link https://developer.github.com/v3/users/emails/#toggle-primary-email-visibility
*
* @return array
*/
public function toggleVisibility()
{
return $this->patch('/user/email/visibility');
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Github\Api\CurrentUser;
use Github\Api\AbstractApi;
/**
* @link http://developer.github.com/v3/users/followers/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Followers extends AbstractApi
{
/**
* List followed users by the authenticated user.
*
* @link http://developer.github.com/v3/repos/followers/
*
* @param int $page
*
* @return array
*/
public function all($page = 1)
{
return $this->get('/user/following', [
'page' => $page,
]);
}
/**
* Check that the authenticated user follows a user.
*
* @link http://developer.github.com/v3/repos/followers/
*
* @param string $username the username to follow
*
* @return array
*/
public function check($username)
{
return $this->get('/user/following/'.rawurlencode($username));
}
/**
* Make the authenticated user follow a user.
*
* @link http://developer.github.com/v3/repos/followers/
*
* @param string $username the username to follow
*
* @return array
*/
public function follow($username)
{
return $this->put('/user/following/'.rawurlencode($username));
}
/**
* Make the authenticated user un-follow a user.
*
* @link http://developer.github.com/v3/repos/followers/
*
* @param string $username the username to un-follow
*
* @return array
*/
public function unfollow($username)
{
return $this->delete('/user/following/'.rawurlencode($username));
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Github\Api\CurrentUser;
use Github\Api\AbstractApi;
class Memberships extends AbstractApi
{
/**
* List your organization memberships.
*
* @link https://developer.github.com/v3/orgs/members/#get-your-organization-membership
*
* @return array
*/
public function all()
{
return $this->get('/user/memberships/orgs');
}
/**
* Get your organization membership.
*
* @link https://developer.github.com/v3/orgs/members/#get-your-organization-membership
*
* @param string $organization
*
* @return array
*/
public function organization($organization)
{
return $this->get('/user/memberships/orgs/'.rawurlencode($organization));
}
/**
* Edit your organization membership.
*
* @link https://developer.github.com/v3/orgs/members/#edit-your-organization-membership
*
* @param string $organization
*
* @return array
*/
public function edit($organization)
{
return $this->patch('/user/memberships/orgs/'.rawurlencode($organization), ['state' => 'active']);
}
}

View File

@@ -0,0 +1,145 @@
<?php
namespace Github\Api\CurrentUser;
use Github\Api\AbstractApi;
/**
* @link http://developer.github.com/v3/activity/notifications/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Notifications extends AbstractApi
{
/**
* List all notifications for the authenticated user.
*
* @link http://developer.github.com/v3/activity/notifications/#list-your-notifications
*
* @param array $params
*
* @return array
*/
public function all(array $params = [])
{
return $this->get('/notifications', $params);
}
/**
* List all notifications for the authenticated user in selected repository.
*
* @link http://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param array $params
*
* @return array
*/
public function allInRepository($username, $repository, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params);
}
/**
* Mark all notifications as read.
*
* @link http://developer.github.com/v3/activity/notifications/#mark-as-read
*
* @param array $params
*
* @return array
*/
public function markAsReadAll(array $params = [])
{
return $this->put('/notifications', $params);
}
/**
* Mark all notifications for a repository as read.
*
* @link http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param array $params
*
* @return array
*/
public function markAsReadInRepository($username, $repository, array $params = [])
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params);
}
/**
* Mark a notification as read.
*
* @link http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
*
* @param int $id the notification number
* @param array $params
*
* @return array
*/
public function markAsRead($id, array $params)
{
return $this->patch('/notifications/threads/'.rawurlencode($id), $params);
}
/**
* Show a notification.
*
* @link http://developer.github.com/v3/activity/notifications/#view-a-single-thread
*
* @param int $id the notification number
*
* @return array
*/
public function show($id)
{
return $this->get('/notifications/threads/'.rawurlencode($id));
}
/**
* Show a subscription.
*
* @link http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
*
* @param int $id the notification number
*
* @return array
*/
public function showSubscription($id)
{
return $this->get('/notifications/threads/'.rawurlencode($id).'/subscription');
}
/**
* Create a subscription.
*
* @link http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription
*
* @param int $id the notification number
* @param array $params
*
* @return array
*/
public function createSubscription($id, array $params)
{
return $this->put('/notifications/threads/'.rawurlencode($id).'/subscription', $params);
}
/**
* Delete a subscription.
*
* @link http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription
*
* @param int $id the notification number
*
* @return array
*/
public function removeSubscription($id)
{
return $this->delete('/notifications/threads/'.rawurlencode($id).'/subscription');
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace Github\Api\CurrentUser;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/users/keys/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class PublicKeys extends AbstractApi
{
/**
* List deploy keys for the authenticated user.
*
* @link https://developer.github.com/v3/users/keys/
*
* @return array
*/
public function all()
{
return $this->get('/user/keys');
}
/**
* Shows deploy key for the authenticated user.
*
* @link https://developer.github.com/v3/users/keys/
*
* @param int $id
*
* @return array
*/
public function show($id)
{
return $this->get('/user/keys/'.rawurlencode($id));
}
/**
* Adds deploy key for the authenticated user.
*
* @link https://developer.github.com/v3/users/keys/
*
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create(array $params)
{
if (!isset($params['title'], $params['key'])) {
throw new MissingArgumentException(['title', 'key']);
}
return $this->post('/user/keys', $params);
}
/**
* Removes deploy key for the authenticated user.
*
* @link https://developer.github.com/v3/users/keys/
*
* @param int $id
*
* @return array
*/
public function remove($id)
{
return $this->delete('/user/keys/'.rawurlencode($id));
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Github\Api\CurrentUser;
use Github\Api\AbstractApi;
/**
* @link https://developer.github.com/v3/activity/starring/
*
* @author Felipe Valtl de Mello <eu@felipe.im>
*/
class Starring extends AbstractApi
{
/**
* List repositories starred by the authenticated user.
*
* @link https://developer.github.com/v3/activity/starring/
*
* @param int $page
* @param int $perPage
*
* @return array
*/
public function all($page = 1, $perPage = 30)
{
return $this->get('/user/starred', [
'page' => $page,
'per_page' => $perPage,
]);
}
/**
* Check that the authenticated user starres a repository.
*
* @link https://developer.github.com/v3/activity/starring/
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array
*/
public function check($username, $repository)
{
return $this->get('/user/starred/'.rawurlencode($username).'/'.rawurlencode($repository));
}
/**
* Make the authenticated user star a repository.
*
* @link https://developer.github.com/v3/activity/starring/
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array
*/
public function star($username, $repository)
{
return $this->put('/user/starred/'.rawurlencode($username).'/'.rawurlencode($repository));
}
/**
* Make the authenticated user unstar a repository.
*
* @link https://developer.github.com/v3/activity/starring
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array
*/
public function unstar($username, $repository)
{
return $this->delete('/user/starred/'.rawurlencode($username).'/'.rawurlencode($repository));
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace Github\Api\CurrentUser;
use Github\Api\AbstractApi;
/**
* @link https://developer.github.com/v3/activity/watching/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @revised Felipe Valtl de Mello <eu@felipe.im>
*/
class Watchers extends AbstractApi
{
/**
* List repositories watched by the authenticated user.
*
* @link https://developer.github.com/v3/activity/watching/
*
* @param int $page
*
* @return array
*/
public function all($page = 1)
{
return $this->get('/user/subscriptions', [
'page' => $page,
]);
}
/**
* Check that the authenticated user watches a repository.
*
* @link https://developer.github.com/v3/activity/watching/
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array
*/
public function check($username, $repository)
{
return $this->get('/user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository));
}
/**
* Make the authenticated user watch a repository.
*
* @link https://developer.github.com/v3/activity/watching/
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array
*/
public function watch($username, $repository)
{
return $this->put('/user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository));
}
/**
* Make the authenticated user unwatch a repository.
*
* @link https://developer.github.com/v3/activity/watching/
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array
*/
public function unwatch($username, $repository)
{
return $this->delete('/user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository));
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace Github\Api;
use Github\Exception\MissingArgumentException;
/**
* Listing, creating and updating deployments.
*
* @link https://developer.github.com/v3/repos/deployments/
*/
class Deployment extends AbstractApi
{
/**
* List deployments for a particular repository.
*
* @link https://developer.github.com/v3/repos/deployments/#list-deployments
*
* @param string $username the username of the user who owns the repository
* @param string $repository the name of the repository
* @param array $params query parameters to filter deployments by (see link)
*
* @return array the deployments requested
*/
public function all($username, $repository, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params);
}
/**
* Get a deployment in selected repository.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the deployment
*
* @return array
*/
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id));
}
/**
* Create a new deployment for the given username and repo.
*
* @link https://developer.github.com/v3/repos/deployments/#create-a-deployment
*
* Important: Once a deployment is created, it cannot be updated. Changes are indicated by creating new statuses.
* @see updateStatus
*
* @param string $username the username
* @param string $repository the repository
* @param array $params the new deployment data
*
* @throws MissingArgumentException
*
* @return array information about the deployment
*/
public function create($username, $repository, array $params)
{
if (!isset($params['ref'])) {
throw new MissingArgumentException(['ref']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params);
}
/**
* Updates a deployment by creating a new status update.
*
* @link https://developer.github.com/v3/repos/deployments/#create-a-deployment-status
*
* @param string $username the username
* @param string $repository the repository
* @param int $id the deployment number
* @param array $params The information about the deployment update.
* Must include a "state" field of pending, success, error, or failure.
* May also be given a target_url and description, ßee link for more details.
*
* @throws MissingArgumentException
*
* @return array information about the deployment
*/
public function updateStatus($username, $repository, $id, array $params)
{
if (!isset($params['state'])) {
throw new MissingArgumentException(['state']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params);
}
/**
* Gets all of the status updates tied to a given deployment.
*
* @param string $username the username
* @param string $repository the repository
* @param int $id the deployment identifier
*
* @return array the deployment statuses
*/
public function getStatuses($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses');
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Github\Api;
use Github\Api\Enterprise\License;
use Github\Api\Enterprise\ManagementConsole;
use Github\Api\Enterprise\Stats;
use Github\Api\Enterprise\UserAdmin;
/**
* Getting information about a GitHub Enterprise instance.
*
* @link https://developer.github.com/v3/enterprise/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Guillermo A. Fisher <guillermoandraefisher@gmail.com>
*/
class Enterprise extends AbstractApi
{
/**
* @return Stats
*/
public function stats()
{
return new Stats($this->client);
}
/**
* @return License
*/
public function license()
{
return new License($this->client);
}
/**
* @return ManagementConsole
*/
public function console()
{
return new ManagementConsole($this->client);
}
/**
* @return UserAdmin
*/
public function userAdmin()
{
return new UserAdmin($this->client);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Github\Api\Enterprise;
use Github\Api\AbstractApi;
class License extends AbstractApi
{
/**
* Provides information about your Enterprise license (only available to site admins).
*
* @link https://developer.github.com/v3/enterprise/license/
*
* @return array array of license information
*/
public function show()
{
return $this->get('/enterprise/settings/license');
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace Github\Api\Enterprise;
use Github\Api\AbstractApi;
class ManagementConsole extends AbstractApi
{
/**
* Checks the status of your installations most recent configuration process.
*
* @link https://developer.github.com/v3/enterprise/management_console/#check-configuration-status
*
* @param string $hash md5 hash of your license
*
* @return array array of configuration status information
*/
public function configcheck($hash)
{
return $this->getWithLicenseHash('/setup/api/configcheck', $hash);
}
/**
* Retrieves your installations settings.
*
* @link https://developer.github.com/v3/enterprise/management_console/#retrieve-settings
*
* @param string $hash md5 hash of your license
*
* @return array array of settings
*/
public function settings($hash)
{
return $this->getWithLicenseHash('/setup/api/settings', $hash);
}
/**
* Checks your installations maintenance status.
*
* @link https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
*
* @param string $hash md5 hash of your license
*
* @return array array of maintenance status information
*/
public function maintenance($hash)
{
return $this->getWithLicenseHash('/setup/api/maintenance', $hash);
}
/**
* Retrieves your installations authorized SSH keys.
*
* @link https://developer.github.com/v3/enterprise/management_console/#retrieve-authorized-ssh-keys
*
* @param string $hash md5 hash of your license
*
* @return array array of authorized keys
*/
public function keys($hash)
{
return $this->getWithLicenseHash('/setup/api/settings/authorized-keys', $hash);
}
/**
* Sends an authenticated GET request.
*
* @param string $uri the request URI
* @param string $hash md5 hash of your license
*
* @return array|string
*/
protected function getWithLicenseHash($uri, $hash)
{
return $this->get($uri, ['license_md5' => rawurlencode($hash)]);
}
}

View File

@@ -0,0 +1,128 @@
<?php
namespace Github\Api\Enterprise;
use Github\Api\AbstractApi;
class Stats extends AbstractApi
{
/**
* Returns the number of open and closed issues.
*
* @return array array with totals of open and closed issues
*/
public function issues()
{
return $this->show('issues');
}
/**
* Returns the number of active and inactive hooks.
*
* @return array array with totals of active and inactive hooks
*/
public function hooks()
{
return $this->show('hooks');
}
/**
* Returns the number of open and closed milestones.
*
* @return array array with totals of open and closed milestones
*/
public function milestones()
{
return $this->show('milestones');
}
/**
* Returns the number of organizations, teams, team members, and disabled organizations.
*
* @return array array with totals of organizations, teams, team members, and disabled organizations
*/
public function orgs()
{
return $this->show('orgs');
}
/**
* Returns the number of comments on issues, pull requests, commits, and gists.
*
* @return array array with totals of comments on issues, pull requests, commits, and gists
*/
public function comments()
{
return $this->show('comments');
}
/**
* Returns the number of GitHub Pages sites.
*
* @return array array with totals of GitHub Pages sites
*/
public function pages()
{
return $this->show('pages');
}
/**
* Returns the number of suspended and admin users.
*
* @return array array with totals of suspended and admin users
*/
public function users()
{
return $this->show('users');
}
/**
* Returns the number of private and public gists.
*
* @return array array with totals of private and public gists
*/
public function gists()
{
return $this->show('gists');
}
/**
* Returns the number of merged, mergeable, and unmergeable pull requests.
*
* @return array array with totals of merged, mergeable, and unmergeable pull requests
*/
public function pulls()
{
return $this->show('pulls');
}
/**
* Returns the number of organization-owned repositories, root repositories, forks, pushed commits, and wikis.
*
* @return array array with totals of organization-owned repositories, root repositories, forks, pushed commits, and wikis
*/
public function repos()
{
return $this->show('repos');
}
/**
* Returns all of the statistics.
*
* @return array array with all of the statistics
*/
public function all()
{
return $this->show('all');
}
/**
* @param string $type The type of statistics to show
*
* @return array
*/
public function show($type)
{
return $this->get('/enterprise/stats/'.rawurlencode($type));
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Github\Api\Enterprise;
use Github\Api\AbstractApi;
class UserAdmin extends AbstractApi
{
/**
* Suspend a user.
*
* @link https://developer.github.com/v3/users/administration/#suspend-a-user
*
* @param string $username
*
* @return array
*/
public function suspend($username)
{
return $this->put('/users/'.rawurldecode($username).'/suspended', ['Content-Length' => 0]);
}
/**
* Unsuspend a user.
*
* @link https://developer.github.com/v3/users/administration/#unsuspend-a-user
*
* @param string $username
*
* @return array
*/
public function unsuspend($username)
{
return $this->delete('/users/'.rawurldecode($username).'/suspended');
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace Github\Api\Gist;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
/**
* @link https://developer.github.com/v3/gists/comments/
*
* @author Kayla Daniels <kayladnls@gmail.com>
*/
class Comments extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/gists/comments/#custom-media-types
*
* @param string|null $bodyType
*
* @return self
*/
public function configure($bodyType = null)
{
if (!in_array($bodyType, ['text', 'html', 'full'])) {
$bodyType = 'raw';
}
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType);
return $this;
}
/**
* Get all comments for a gist.
*
* @param string $gist
*
* @return array
*/
public function all($gist)
{
return $this->get('/gists/'.rawurlencode($gist).'/comments');
}
/**
* Get a comment of a gist.
*
* @param string $gist
* @param int $comment
*
* @return array
*/
public function show($gist, $comment)
{
return $this->get('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment));
}
/**
* Create a comment for gist.
*
* @param string $gist
* @param string $body
*
* @return array
*/
public function create($gist, $body)
{
return $this->post('/gists/'.rawurlencode($gist).'/comments', ['body' => $body]);
}
/**
* Create a comment for a gist.
*
* @param string $gist
* @param int $comment_id
* @param string $body
*
* @return array
*/
public function update($gist, $comment_id, $body)
{
return $this->patch('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), ['body' => $body]);
}
/**
* Delete a comment for a gist.
*
* @param string $gist
* @param int $comment
*
* @return array
*/
public function remove($gist, $comment)
{
return $this->delete('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment));
}
}

View File

@@ -0,0 +1,116 @@
<?php
namespace Github\Api;
use Github\Api\Gist\Comments;
use Github\Exception\MissingArgumentException;
/**
* Creating, editing, deleting and listing gists.
*
* @link http://developer.github.com/v3/gists/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Edoardo Rivello <edoardo.rivello at gmail dot com>
*/
class Gists extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/gists/#custom-media-types
*
* @param string|null $bodyType
*
* @return self
*/
public function configure($bodyType = null)
{
if (!in_array($bodyType, ['base64'])) {
$bodyType = 'raw';
}
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType);
return $this;
}
public function all($type = null)
{
if (!in_array($type, ['public', 'starred'])) {
return $this->get('/gists');
}
return $this->get('/gists/'.rawurlencode($type));
}
public function show($number)
{
return $this->get('/gists/'.rawurlencode($number));
}
public function create(array $params)
{
if (!isset($params['files']) || (!is_array($params['files']) || 0 === count($params['files']))) {
throw new MissingArgumentException('files');
}
$params['public'] = (bool) $params['public'];
return $this->post('/gists', $params);
}
public function update($id, array $params)
{
return $this->patch('/gists/'.rawurlencode($id), $params);
}
public function commits($id)
{
return $this->get('/gists/'.rawurlencode($id).'/commits');
}
public function fork($id)
{
return $this->post('/gists/'.rawurlencode($id).'/fork');
}
public function forks($id)
{
return $this->get('/gists/'.rawurlencode($id).'/forks');
}
public function remove($id)
{
return $this->delete('/gists/'.rawurlencode($id));
}
public function check($id)
{
return $this->get('/gists/'.rawurlencode($id).'/star');
}
public function star($id)
{
return $this->put('/gists/'.rawurlencode($id).'/star');
}
public function unstar($id)
{
return $this->delete('/gists/'.rawurlencode($id).'/star');
}
/**
* Get a gist's comments.
*
* @link http://developer.github.com/v3/gists/comments/
*
* @return Comments
*/
public function comments()
{
return new Comments($this->client);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Github\Api;
use Github\Api\GitData\Blobs;
use Github\Api\GitData\Commits;
use Github\Api\GitData\References;
use Github\Api\GitData\Tags;
use Github\Api\GitData\Trees;
/**
* Getting full versions of specific files and trees in your Git repositories.
*
* @link http://developer.github.com/v3/git/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class GitData extends AbstractApi
{
/**
* @return Blobs
*/
public function blobs()
{
return new Blobs($this->client);
}
/**
* @return Commits
*/
public function commits()
{
return new Commits($this->client);
}
/**
* @return References
*/
public function references()
{
return new References($this->client);
}
/**
* @return Tags
*/
public function tags()
{
return new Tags($this->client);
}
/**
* @return Trees
*/
public function trees()
{
return new Trees($this->client);
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace Github\Api\GitData;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/git/blobs/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class Blobs extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the Accept header depending on the blob type.
*
* @param string|null $bodyType
*
* @return self
*/
public function configure($bodyType = null)
{
if ('raw' === $bodyType) {
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.raw', $this->client->getApiVersion());
}
return $this;
}
/**
* Show a blob of a sha for a repository.
*
* @param string $username
* @param string $repository
* @param string $sha
*
* @return array
*/
public function show($username, $repository, $sha)
{
$response = $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs/'.rawurlencode($sha));
return $response;
}
/**
* Create a blob of a sha for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
if (!isset($params['content'], $params['encoding'])) {
throw new MissingArgumentException(['content', 'encoding']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs', $params);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Github\Api\GitData;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/git/commits/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Commits extends AbstractApi
{
/**
* Show a commit for a repository.
*
* @param string $username
* @param string $repository
* @param string $sha
*
* @return array
*/
public function show($username, $repository, $sha)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits/'.rawurlencode($sha));
}
/**
* Create a commit for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
if (!isset($params['message'], $params['tree'], $params['parents'])) {
throw new MissingArgumentException(['message', 'tree', 'parents']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits', $params);
}
}

View File

@@ -0,0 +1,140 @@
<?php
namespace Github\Api\GitData;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/git/references/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class References extends AbstractApi
{
/**
* Get all references of a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function all($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs');
}
/**
* Get all branches of a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function branches($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/heads');
}
/**
* Get all tags of a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function tags($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags');
}
/**
* Show the reference of a repository.
*
* @param string $username
* @param string $repository
* @param string $reference
*
* @return array
*/
public function show($username, $repository, $reference)
{
$reference = $this->encodeReference($reference);
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference);
}
/**
* Create a reference for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
if (!isset($params['ref'], $params['sha'])) {
throw new MissingArgumentException(['ref', 'sha']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs', $params);
}
/**
* Update a reference for a repository.
*
* @param string $username
* @param string $repository
* @param string $reference
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function update($username, $repository, $reference, array $params)
{
if (!isset($params['sha'])) {
throw new MissingArgumentException('sha');
}
$reference = $this->encodeReference($reference);
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference, $params);
}
/**
* Delete a reference of a repository.
*
* @param string $username
* @param string $repository
* @param string $reference
*
* @return array
*/
public function remove($username, $repository, $reference)
{
$reference = $this->encodeReference($reference);
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference);
}
/**
* Encode the raw reference.
*
* @param string $rawReference
*
* @return string
*/
private function encodeReference($rawReference)
{
return implode('/', array_map('rawurlencode', explode('/', $rawReference)));
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace Github\Api\GitData;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/git/tags/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Tags extends AbstractApi
{
/**
* Get all tags for a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function all($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags');
}
/**
* Get a tag for a repository.
*
* @param string $username
* @param string $repository
* @param string $sha
*
* @return array
*/
public function show($username, $repository, $sha)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags/'.rawurlencode($sha));
}
/**
* Create a tag for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
if (!isset($params['tag'], $params['message'], $params['object'], $params['type'])) {
throw new MissingArgumentException(['tag', 'message', 'object', 'type']);
}
if (!isset($params['tagger'])) {
throw new MissingArgumentException('tagger');
}
if (!isset($params['tagger']['name'], $params['tagger']['email'], $params['tagger']['date'])) {
throw new MissingArgumentException(['tagger.name', 'tagger.email', 'tagger.date']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags', $params);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Github\Api\GitData;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/git/trees/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Trees extends AbstractApi
{
/**
* Get the tree for a repository.
*
* @param string $username
* @param string $repository
* @param string $sha
* @param bool $recursive
*
* @return array
*/
public function show($username, $repository, $sha, $recursive = false)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), $recursive ? ['recursive' => 1] : []);
}
/**
* Create tree for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
if (!isset($params['tree']) || !is_array($params['tree'])) {
throw new MissingArgumentException('tree');
}
if (!isset($params['tree'][0])) {
$params['tree'] = [$params['tree']];
}
foreach ($params['tree'] as $key => $tree) {
if (!isset($tree['path'], $tree['mode'], $tree['type'])) {
throw new MissingArgumentException(["tree.$key.path", "tree.$key.mode", "tree.$key.type"]);
}
// If `sha` is not set, `content` is required
if (!isset($tree['sha']) && !isset($tree['content'])) {
throw new MissingArgumentException("tree.$key.content");
}
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees', $params);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Github\Api;
/**
* GraphQL API.
*
* Part of the Github v4 API
*
* @link https://developer.github.com/v4/
*
* @author Miguel Piedrafita <soy@miguelpiedrafita.com>
*/
class GraphQL extends AbstractApi
{
use AcceptHeaderTrait;
/**
* @param string $query
* @param array $variables
*
* @return array
*/
public function execute($query, array $variables = [])
{
$this->acceptHeaderValue = 'application/vnd.github.v4+json';
$params = [
'query' => $query,
];
if (!empty($variables)) {
$params['variables'] = json_encode($variables);
}
return $this->post('/graphql', $params);
}
/**
* @param string $file
* @param array $variables
*
* @return array
*/
public function fromFile($file, array $variables = [])
{
return $this->execute(file_get_contents($file), $variables);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Github\Api;
@trigger_error('The '.__NAMESPACE__.'\Integrations class is deprecated. Use the '.__NAMESPACE__.'\Apps class instead.', E_USER_DEPRECATED);
/**
* @deprecated Use the Apps class
* @link https://developer.github.com/v3/apps/
*
* @author Nils Adermann <naderman@naderman.de>
*/
class Integrations extends Apps
{
/**
* @deprecated
* Configure the accept header for Early Access to the integrations api (DEPRECATED)
* @see https://developer.github.com/v3/apps/
*
* @return self
*/
public function configure()
{
return $this;
}
}

View File

@@ -0,0 +1,263 @@
<?php
namespace Github\Api;
use Github\Api\Issue\Assignees;
use Github\Api\Issue\Comments;
use Github\Api\Issue\Events;
use Github\Api\Issue\Labels;
use Github\Api\Issue\Milestones;
use Github\Api\Issue\Timeline;
use Github\Exception\MissingArgumentException;
/**
* Listing issues, searching, editing and closing your projects issues.
*
* @link http://develop.github.com/p/issues.html
*
* @author Thibault Duplessis <thibault.duplessis at gmail dot com>
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Issue extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/issues/#custom-media-types
*
* @param string|null $bodyType
*
* @return self
*/
public function configure($bodyType = null)
{
if (!in_array($bodyType, ['text', 'html', 'full'])) {
$bodyType = 'raw';
}
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType);
return $this;
}
/**
* List issues by username, repo and state.
*
* @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repository the repository
* @param array $params the additional parameters like milestone, assignees, labels, sort, direction
*
* @return array list of issues found
*/
public function all($username, $repository, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', array_merge(['page' => 1], $params));
}
/**
* Search issues by username, repo, state and keyword.
*
* @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated
* @link http://developer.github.com/v3/search/#search-issues
*
* @param string $username the username
* @param string $repository the repository
* @param string $state the issue state, can be open or closed
* @param string $keyword the keyword to filter issues by
*
* @return array list of issues found
*/
public function find($username, $repository, $state, $keyword)
{
if (!in_array($state, ['open', 'closed'])) {
$state = 'open';
}
return $this->get('/legacy/issues/search/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($state).'/'.rawurlencode($keyword));
}
/**
* List issues by organization.
*
* @link http://developer.github.com/v3/issues/
*
* @param string $organization the organization
* @param string $state the issue state, can be open or closed
* @param array $params the additional parameters like milestone, assignees, labels, sort, direction
*
* @return array list of issues found
*/
public function org($organization, $state, array $params = [])
{
if (!in_array($state, ['open', 'closed'])) {
$state = 'open';
}
return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(['page' => 1, 'state' => $state], $params));
}
/**
* Get extended information about an issue by its username, repo and number.
*
* @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repository the repository
* @param int $id the issue number
*
* @return array information about the issue
*/
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id));
}
/**
* Create a new issue for the given username and repo.
* The issue is assigned to the authenticated user. Requires authentication.
*
* @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repository the repository
* @param array $params the new issue data
*
* @throws MissingArgumentException
*
* @return array information about the issue
*/
public function create($username, $repository, array $params)
{
if (!isset($params['title'])) {
throw new MissingArgumentException(['title']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', $params);
}
/**
* Update issue information's by username, repo and issue number. Requires authentication.
*
* @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repository the repository
* @param int $id the issue number
* @param array $params key=>value user attributes to update.
* key can be title or body
*
* @return array information about the issue
*/
public function update($username, $repository, $id, array $params)
{
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id), $params);
}
/**
* Lock an issue. Users with push access can lock an issue's conversation.
*
* @link https://developer.github.com/v3/issues/#lock-an-issue
*
* @param string $username
* @param string $repository
* @param int $id
*
* @return string
*/
public function lock($username, $repository, $id)
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock');
}
/**
* Unlock an issue. Users with push access can unlock an issue's conversation.
*
* @link https://developer.github.com/v3/issues/#lock-an-issue
*
* @param string $username
* @param string $repository
* @param int $id
*
* @return string
*/
public function unlock($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock');
}
/**
* List an issue comments.
*
* @link http://developer.github.com/v3/issues/comments/
*
* @return Comments
*/
public function comments()
{
return new Comments($this->client);
}
/**
* List all project events.
*
* @link http://developer.github.com/v3/issues/events/
*
* @return Events
*/
public function events()
{
return new Events($this->client);
}
/**
* List all project labels.
*
* @link http://developer.github.com/v3/issues/labels/
*
* @return Labels
*/
public function labels()
{
return new Labels($this->client);
}
/**
* List all project milestones.
*
* @link http://developer.github.com/v3/issues/milestones/
*
* @return Milestones
*/
public function milestones()
{
return new Milestones($this->client);
}
/**
* List all assignees.
*
* @link https://developer.github.com/v3/issues/assignees/
*
* @return Assignees
*/
public function assignees()
{
return new Assignees($this->client);
}
/**
* List all events.
*
* @link https://developer.github.com/v3/issues/timeline/
*
* @return Timeline
*/
public function timeline()
{
return new Timeline($this->client);
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace Github\Api\Issue;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
class Assignees extends AbstractApi
{
/**
* List all the available assignees to which issues may be assigned.
*
* @param string $username
* @param string $repository
* @param array $parameters
*
* @return array
*/
public function listAvailable($username, $repository, array $parameters = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees', $parameters);
}
/**
* Check to see if a particular user is an assignee for a repository.
*
* @link https://developer.github.com/v3/issues/assignees/#check-assignee
*
* @param string $username
* @param string $repository
* @param string $assignee
*
* @return array
*/
public function check($username, $repository, $assignee)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees/'.rawurlencode($assignee));
}
/**
* Add assignees to an Issue.
*
* @link https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue
*
* @param string $username
* @param string $repository
* @param string $issue
* @param array $parameters
*
* @throws MissingArgumentException
*
* @return string
*/
public function add($username, $repository, $issue, array $parameters)
{
if (!isset($parameters['assignees'])) {
throw new MissingArgumentException('assignees');
}
if (!is_array($parameters['assignees'])) {
@trigger_error(sprintf('Passing the "assignees" parameter as a string in "%s" is deprecated and will throw an exception in php-github-api version 3.0. Pass an array of strings instead', __METHOD__), E_USER_DEPRECATED);
$parameters['assignees'] = [$parameters['assignees']];
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters);
}
/**
* Remove assignees from an Issue.
*
* @link https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue
*
* @param string $username
* @param string $repository
* @param string $issue
* @param array $parameters
*
* @throws MissingArgumentException
*
* @return string
*/
public function remove($username, $repository, $issue, array $parameters)
{
if (!isset($parameters['assignees'])) {
throw new MissingArgumentException('assignees');
}
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters);
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace Github\Api\Issue;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/issues/comments/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class Comments extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/issues/comments/#custom-media-types
*
* @param string|null $bodyType
*
* @return self
*/
public function configure($bodyType = null)
{
if (!in_array($bodyType, ['raw', 'text', 'html'])) {
$bodyType = 'full';
}
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType);
return $this;
}
/**
* Get all comments for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
*
* @param string $username
* @param string $repository
* @param int $issue
* @param int $page
*
* @return array
*/
public function all($username, $repository, $issue, $page = 1)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', [
'page' => $page,
]);
}
/**
* Get a comment for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#get-a-single-comment
*
* @param string $username
* @param string $repository
* @param int $comment
*
* @return array
*/
public function show($username, $repository, $comment)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment));
}
/**
* Create a comment for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#create-a-comment
*
* @param string $username
* @param string $repository
* @param int $issue
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($username, $repository, $issue, array $params)
{
if (!isset($params['body'])) {
throw new MissingArgumentException('body');
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $params);
}
/**
* Update a comment for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#edit-a-comment
*
* @param string $username
* @param string $repository
* @param int $comment
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function update($username, $repository, $comment, array $params)
{
if (!isset($params['body'])) {
throw new MissingArgumentException('body');
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment), $params);
}
/**
* Delete a comment for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#delete-a-comment
*
* @param string $username
* @param string $repository
* @param int $comment
*
* @return array
*/
public function remove($username, $repository, $comment)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment));
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Github\Api\Issue;
use Github\Api\AbstractApi;
/**
* @link http://developer.github.com/v3/issues/events/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Events extends AbstractApi
{
/**
* Get all events for an issue.
*
* @link https://developer.github.com/v3/issues/events/#list-events-for-an-issue
*
* @param string $username
* @param string $repository
* @param int|null $issue
* @param int $page
*
* @return array
*/
public function all($username, $repository, $issue = null, $page = 1)
{
if (null !== $issue) {
$path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events';
} else {
$path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events';
}
return $this->get($path, [
'page' => $page,
]);
}
/**
* Display an event for an issue.
*
* @link https://developer.github.com/v3/issues/events/#get-a-single-event
*
* @param $username
* @param $repository
* @param $event
*
* @return array
*/
public function show($username, $repository, $event)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events/'.rawurlencode($event));
}
}

View File

@@ -0,0 +1,192 @@
<?php
namespace Github\Api\Issue;
use Github\Api\AbstractApi;
use Github\Exception\InvalidArgumentException;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/issues/labels/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Labels extends AbstractApi
{
/**
* Get all labels for a repository or the labels for a specific issue.
*
* @link https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
*
* @param string $username
* @param string $repository
* @param int|null $issue
*
* @return array
*/
public function all($username, $repository, $issue = null)
{
if ($issue === null) {
$path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels';
} else {
$path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels';
}
return $this->get($path);
}
/**
* Get a single label.
*
* @link https://developer.github.com/v3/issues/labels/#get-a-single-label
*
* @param string $username
* @param string $repository
* @param string $label
*
* @return array
*/
public function show($username, $repository, $label)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
}
/**
* Create a label for a repository.
*
* @link https://developer.github.com/v3/issues/labels/#create-a-label
*
* @param string $username
* @param string $repository
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException('name');
}
if (!isset($params['color'])) {
$params['color'] = 'FFFFFF';
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params);
}
/**
* Delete a label for a repository.
*
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
*
* @param string $username
* @param string $repository
* @param string $label
*
* @return array
*/
public function deleteLabel($username, $repository, $label)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
}
/**
* Edit a label for a repository.
*
* @link https://developer.github.com/v3/issues/labels/#update-a-label
*
* @param string $username
* @param string $repository
* @param string $label
* @param string $newName
* @param string $color
*
* @return array
*/
public function update($username, $repository, $label, $newName, $color)
{
$params = [
'name' => $newName,
'color' => $color,
];
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params);
}
/**
* Add a label to an issue.
*
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
*
* @param string $username
* @param string $repository
* @param int $issue
* @param string $labels
*
* @return array
*
* @thorws \Github\Exception\InvalidArgumentException
*/
public function add($username, $repository, $issue, $labels)
{
if (is_string($labels)) {
$labels = [$labels];
} elseif (0 === count($labels)) {
throw new InvalidArgumentException();
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels);
}
/**
* Replace labels for an issue.
*
* @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
*
* @param string $username
* @param string $repository
* @param int $issue
* @param array $params
*
* @return array
*/
public function replace($username, $repository, $issue, array $params)
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $params);
}
/**
* Remove a label for an issue.
*
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
*
* @param string $username
* @param string $repository
* @param string $issue
* @param string $label
*
* @return null
*/
public function remove($username, $repository, $issue, $label)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels/'.rawurlencode($label));
}
/**
* Remove all labels from an issue.
*
* @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
*
* @param string $username
* @param string $repository
* @param string $issue
*
* @return null
*/
public function clear($username, $repository, $issue)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels');
}
}

View File

@@ -0,0 +1,139 @@
<?php
namespace Github\Api\Issue;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/issues/milestones/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Milestones extends AbstractApi
{
/**
* Get all milestones for a repository.
*
* @link https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
*
* @param string $username
* @param string $repository
* @param array $params
*
* @return array
*/
public function all($username, $repository, array $params = [])
{
if (isset($params['state']) && !in_array($params['state'], ['open', 'closed', 'all'])) {
$params['state'] = 'open';
}
if (isset($params['sort']) && !in_array($params['sort'], ['due_date', 'completeness'])) {
$params['sort'] = 'due_date';
}
if (isset($params['direction']) && !in_array($params['direction'], ['asc', 'desc'])) {
$params['direction'] = 'asc';
}
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge([
'page' => 1,
'state' => 'open',
'sort' => 'due_date',
'direction' => 'asc',
], $params));
}
/**
* Get a milestone for a repository.
*
* @link https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
*
* @param string $username
* @param string $repository
* @param int $id
*
* @return array
*/
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id));
}
/**
* Create a milestone for a repository.
*
* @link https://developer.github.com/v3/issues/milestones/#create-a-milestone
*
* @param string $username
* @param string $repository
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
if (!isset($params['title'])) {
throw new MissingArgumentException('title');
}
if (isset($params['state']) && !in_array($params['state'], ['open', 'closed'])) {
$params['state'] = 'open';
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', $params);
}
/**
* Update a milestone for a repository.
*
* @link https://developer.github.com/v3/issues/milestones/#update-a-milestone
*
* @param string $username
* @param string $repository
* @param int $id
* @param array $params
*
* @return array
*/
public function update($username, $repository, $id, array $params)
{
if (isset($params['state']) && !in_array($params['state'], ['open', 'closed'])) {
$params['state'] = 'open';
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id), $params);
}
/**
* Delete a milestone for a repository.
*
* @link https://developer.github.com/v3/issues/milestones/#delete-a-milestone
*
* @param string $username
* @param string $repository
* @param int $id
*
* @return null
*/
public function remove($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id));
}
/**
* Get the labels of a milestone.
*
* @link https://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone
*
* @param string $username
* @param string $repository
* @param int $id
*
* @return array
*/
public function labels($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id).'/labels');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Github\Api\Issue;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
class Timeline extends AbstractApi
{
use AcceptHeaderTrait;
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.mockingbird-preview';
return $this;
}
/**
* Get all events for a specific issue.
*
* @link https://developer.github.com/v3/issues/timeline/#list-events-for-an-issue
*
* @param string $username
* @param string $repository
* @param int $issue
*
* @return array
*/
public function all($username, $repository, $issue)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/timeline');
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Github\Api;
/**
* Markdown Rendering API.
*
* @link http://developer.github.com/v3/markdown/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Markdown extends AbstractApi
{
/**
* @param string $text
* @param string $mode
* @param string $context
*
* @return string
*/
public function render($text, $mode = 'markdown', $context = null)
{
if (!in_array($mode, ['gfm', 'markdown'])) {
$mode = 'markdown';
}
$params = [
'text' => $text,
'mode' => $mode,
];
if (null !== $context && 'gfm' === $mode) {
$params['context'] = $context;
}
return $this->post('/markdown', $params);
}
/**
* @param string $file
*
* @return string
*/
public function renderRaw($file)
{
return $this->post('/markdown/raw', [
'file' => $file,
]);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Github\Api;
/**
* Getting GitHub service information.
*
* @link https://developer.github.com/v3/meta/
*
* @author Claude Dioudonnat <claude.dioudonnat@gmail.com>
*/
class Meta extends AbstractApi
{
/**
* Get the ip address of the hook and git servers for the GitHub.com service.
*
* @return array Information about the service of GitHub.com
*/
public function service()
{
return $this->get('/meta');
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Github\Api\Miscellaneous;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
class CodeOfConduct extends AbstractApi
{
use AcceptHeaderTrait;
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.scarlet-witch-preview+json';
return $this;
}
/**
* List all codes of conduct.
*
* @link https://developer.github.com/v3/codes_of_conduct/#list-all-codes-of-conduct
*
* @return array
*/
public function all()
{
return $this->get('/codes_of_conduct');
}
/**
* Get an individual code of conduct.
*
* @link https://developer.github.com/v3/codes_of_conduct/#get-an-individual-code-of-conduct
*
* @param string $key
*
* @return array
*/
public function show($key)
{
return $this->get('/codes_of_conduct/'.rawurlencode($key));
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Github\Api\Miscellaneous;
use Github\Api\AbstractApi;
class Emojis extends AbstractApi
{
/**
* Lists all the emojis available to use on GitHub.
*
* @link https://developer.github.com/v3/emojis/
*
* @return array
*/
public function all()
{
return $this->get('/emojis');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Github\Api\Miscellaneous;
use Github\Api\AbstractApi;
class Gitignore extends AbstractApi
{
/**
* List all templates available to pass as an option when creating a repository.
*
* @link https://developer.github.com/v3/gitignore/#listing-available-templates
*
* @return array
*/
public function all()
{
return $this->get('/gitignore/templates');
}
/**
* Get a single template.
*
* @link https://developer.github.com/v3/gitignore/#get-a-single-template
*
* @param string $template
*
* @return array
*/
public function show($template)
{
return $this->get('/gitignore/templates/'.rawurlencode($template));
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace Github\Api;
use DateTime;
/**
* API for accessing Notifications from your Git/Github repositories.
*
* Important! You have to be authenticated to perform these methods
*
* @link https://developer.github.com/v3/activity/notifications/
*
* @author Dennis de Greef <github@link0.net>
*/
class Notification extends AbstractApi
{
/**
* Get a listing of notifications.
*
* @link https://developer.github.com/v3/activity/notifications/
*
* @param bool $includingRead
* @param bool $participating
* @param DateTime|null $since
*
* @return array array of notifications
*/
public function all($includingRead = false, $participating = false, DateTime $since = null, DateTime $before = null)
{
$parameters = [
'all' => $includingRead,
'participating' => $participating,
];
if ($since !== null) {
$parameters['since'] = $since->format(DateTime::ISO8601);
}
if ($before !== null) {
$parameters['before'] = $before->format(DateTime::ISO8601);
}
return $this->get('/notifications', $parameters);
}
/**
* Marks all notifications as read from the current date.
*
* Optionally give DateTime to mark as read before that date.
*
* @link https://developer.github.com/v3/activity/notifications/#mark-as-read
*
* @param DateTime|null $since
*/
public function markRead(DateTime $since = null)
{
$parameters = [];
if ($since !== null) {
$parameters['last_read_at'] = $since->format(DateTime::ISO8601);
}
$this->put('/notifications', $parameters);
}
/**
* Mark a single thread as read using its ID.
*
* @link https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
*
* @param int $id
*/
public function markThreadRead($id)
{
$this->patch('/notifications/threads/'.$id);
}
/**
* Gets a single thread using its ID.
*
* @link https://developer.github.com/v3/activity/notifications/#view-a-single-thread
*
* @param int $id
*/
public function id($id)
{
return $this->get('/notifications/threads/'.$id);
}
}

View File

@@ -0,0 +1,104 @@
<?php
namespace Github\Api;
use Github\Api\Organization\Hooks;
use Github\Api\Organization\Members;
use Github\Api\Organization\Teams;
/**
* Getting organization information and managing authenticated organization account information.
*
* @link http://developer.github.com/v3/orgs/
*
* @author Antoine Berranger <antoine at ihqs dot net>
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Organization extends AbstractApi
{
/**
* @link https://developer.github.com/v3/orgs/#list-all-organizations
*
* @return array the organizations
*/
public function all($since = '')
{
return $this->get('/organizations?since='.rawurlencode($since));
}
/**
* Get extended information about an organization by its name.
*
* @link http://developer.github.com/v3/orgs/#get
*
* @param string $organization the organization to show
*
* @return array information about the organization
*/
public function show($organization)
{
return $this->get('/orgs/'.rawurlencode($organization));
}
public function update($organization, array $params)
{
return $this->patch('/orgs/'.rawurlencode($organization), $params);
}
/**
* List all repositories across all the organizations that you can access.
*
* @link http://developer.github.com/v3/repos/#list-organization-repositories
*
* @param string $organization the user name
* @param string $type the type of repositories
* @param int $page the page
*
* @return array the repositories
*/
public function repositories($organization, $type = 'all', $page = 1)
{
return $this->get('/orgs/'.rawurlencode($organization).'/repos', [
'type' => $type,
'page' => $page,
]);
}
/**
* @return Members
*/
public function members()
{
return new Members($this->client);
}
/**
* @return Hooks
*/
public function hooks()
{
return new Hooks($this->client);
}
/**
* @return Teams
*/
public function teams()
{
return new Teams($this->client);
}
/**
* @link http://developer.github.com/v3/issues/#list-issues
*
* @param $organization
* @param array $params
* @param int $page
*
* @return array
*/
public function issues($organization, array $params = [], $page = 1)
{
return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(['page' => $page], $params));
}
}

View File

@@ -0,0 +1,111 @@
<?php
namespace Github\Api\Organization;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
class Hooks extends AbstractApi
{
/**
* List hooks.
*
* @link https://developer.github.com/v3/orgs/hooks/#list-hooks
*
* @param string $organization
*
* @return array
*/
public function all($organization)
{
return $this->get('/orgs/'.rawurlencode($organization).'/hooks');
}
/**
* Get a single hook.
*
* @link https://developer.github.com/v3/orgs/hooks/#get-single-hook
*
* @param string $organization
* @param int $id
*
* @return array
*/
public function show($organization, $id)
{
return $this->get('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id));
}
/**
* Create a hook.
*
* @link https://developer.github.com/v3/orgs/hooks/#create-a-hook
*
* @param string $organization
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($organization, array $params)
{
if (!isset($params['name'], $params['config'])) {
throw new MissingArgumentException(['name', 'config']);
}
return $this->post('/orgs/'.rawurlencode($organization).'/hooks', $params);
}
/**
* Edit a hook.
*
* @link https://developer.github.com/v3/orgs/hooks/#edit-a-hook
*
* @param string $organization
* @param int $id
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function update($organization, $id, array $params)
{
if (!isset($params['config'])) {
throw new MissingArgumentException(['config']);
}
return $this->patch('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id), $params);
}
/**
* Ping a hook.
*
* @link https://developer.github.com/v3/orgs/hooks/#ping-a-hook
*
* @param string $organization
* @param int $id
*
* @return null
*/
public function ping($organization, $id)
{
return $this->post('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id).'/pings');
}
/**
* Delete a hook.
*
* @link https://developer.github.com/v3/orgs/hooks/#delete-a-hook
*
* @param string $organization
* @param int $id
*
* @return null
*/
public function remove($organization, $id)
{
return $this->delete('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id));
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace Github\Api\Organization;
use Github\Api\AbstractApi;
/**
* @link http://developer.github.com/v3/orgs/members/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Members extends AbstractApi
{
public function all($organization, $type = null, $filter = 'all', $role = null)
{
$parameters = [];
$path = '/orgs/'.rawurlencode($organization).'/';
if (null === $type) {
$path .= 'members';
if (null !== $filter) {
$parameters['filter'] = $filter;
}
if (null !== $role) {
$parameters['role'] = $role;
}
} else {
$path .= 'public_members';
}
return $this->get($path, $parameters);
}
public function show($organization, $username)
{
return $this->get('/orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username));
}
public function member($organization, $username)
{
return $this->get('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username));
}
public function check($organization, $username)
{
return $this->get('/orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username));
}
public function publicize($organization, $username)
{
return $this->put('/orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username));
}
public function conceal($organization, $username)
{
return $this->delete('/orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username));
}
/*
* Add user to organization
*/
public function add($organization, $username)
{
return $this->put('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username));
}
public function addMember($organization, $username)
{
return $this->add($organization, $username);
}
public function remove($organization, $username)
{
return $this->delete('/orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username));
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Github\Api\Organization;
use Github\Api\Project\AbstractProjectApi;
use Github\Exception\MissingArgumentException;
class Projects extends AbstractProjectApi
{
public function all($organization, array $params = [])
{
return $this->get('/orgs/'.rawurlencode($organization).'/projects', array_merge(['page' => 1], $params));
}
public function create($organization, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException(['name']);
}
return $this->post('/orgs/'.rawurlencode($organization).'/projects', $params);
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace Github\Api\Organization;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/orgs/teams/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Teams extends AbstractApi
{
public function all($organization)
{
return $this->get('/orgs/'.rawurlencode($organization).'/teams');
}
public function create($organization, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException('name');
}
if (isset($params['repo_names']) && !is_array($params['repo_names'])) {
$params['repo_names'] = [$params['repo_names']];
}
if (isset($params['permission']) && !in_array($params['permission'], ['pull', 'push', 'admin'])) {
$params['permission'] = 'pull';
}
return $this->post('/orgs/'.rawurlencode($organization).'/teams', $params);
}
public function show($team)
{
return $this->get('/teams/'.rawurlencode($team));
}
public function update($team, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException('name');
}
if (isset($params['permission']) && !in_array($params['permission'], ['pull', 'push', 'admin'])) {
$params['permission'] = 'pull';
}
return $this->patch('/teams/'.rawurlencode($team), $params);
}
public function remove($team)
{
return $this->delete('/teams/'.rawurlencode($team));
}
public function members($team)
{
return $this->get('/teams/'.rawurlencode($team).'/members');
}
public function check($team, $username)
{
return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
}
public function addMember($team, $username)
{
return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
}
public function removeMember($team, $username)
{
return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
}
public function repositories($team)
{
return $this->get('/teams/'.rawurlencode($team).'/repos');
}
public function repository($team, $organization, $repository)
{
return $this->get('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository));
}
public function addRepository($team, $organization, $repository, $params = [])
{
if (isset($params['permission']) && !in_array($params['permission'], ['pull', 'push', 'admin'])) {
$params['permission'] = 'pull';
}
return $this->put('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository), $params);
}
public function removeRepository($team, $organization, $repository)
{
return $this->delete('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository));
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Github\Api\Project;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
abstract class AbstractProjectApi extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the accept header for Early Access to the projects api.
*
* @see https://developer.github.com/v3/repos/projects/#projects
*
* @return self
*/
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
return $this;
}
public function show($id, array $params = [])
{
return $this->get('/projects/'.rawurlencode($id), array_merge(['page' => 1], $params));
}
public function update($id, array $params)
{
return $this->patch('/projects/'.rawurlencode($id), $params);
}
public function deleteProject($id)
{
return $this->delete('/projects/'.rawurlencode($id));
}
public function columns()
{
return new Columns($this->client);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Github\Api\Project;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;
class Cards extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the accept header for Early Access to the projects api.
*
* @see https://developer.github.com/v3/repos/projects/#projects
*
* @return self
*/
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
return $this;
}
public function all($columnId, array $params = [])
{
return $this->get('/projects/columns/'.rawurlencode($columnId).'/cards', array_merge(['page' => 1], $params));
}
public function show($id)
{
return $this->get('/projects/columns/cards/'.rawurlencode($id));
}
public function create($columnId, array $params)
{
return $this->post('/projects/columns/'.rawurlencode($columnId).'/cards', $params);
}
public function update($id, array $params)
{
return $this->patch('/projects/columns/cards/'.rawurlencode($id), $params);
}
public function deleteCard($id)
{
return $this->delete('/projects/columns/cards/'.rawurlencode($id));
}
public function move($id, array $params)
{
if (!isset($params['position'])) {
throw new MissingArgumentException(['position']);
}
return $this->post('/projects/columns/cards/'.rawurlencode($id).'/moves', $params);
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Github\Api\Project;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;
class Columns extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the accept header for Early Access to the projects api.
*
* @see https://developer.github.com/v3/repos/projects/#projects
*
* return self
*/
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
return $this;
}
public function all($projectId, array $params = [])
{
return $this->get('/projects/'.rawurlencode($projectId).'/columns', array_merge(['page' => 1], $params));
}
public function show($id)
{
return $this->get('/projects/columns/'.rawurlencode($id));
}
public function create($projectId, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException(['name']);
}
return $this->post('/projects/'.rawurlencode($projectId).'/columns', $params);
}
public function update($id, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException(['name']);
}
return $this->patch('/projects/columns/'.rawurlencode($id), $params);
}
public function deleteColumn($id)
{
return $this->delete('/projects/columns/'.rawurlencode($id));
}
public function move($id, array $params)
{
if (!isset($params['position'])) {
throw new MissingArgumentException(['position']);
}
return $this->post('/projects/columns/'.rawurlencode($id).'/moves', $params);
}
public function cards()
{
return new Cards($this->client);
}
}

View File

@@ -0,0 +1,203 @@
<?php
namespace Github\Api;
use Github\Api\PullRequest\Comments;
use Github\Api\PullRequest\Review;
use Github\Api\PullRequest\ReviewRequest;
use Github\Exception\InvalidArgumentException;
use Github\Exception\MissingArgumentException;
/**
* API for accessing Pull Requests from your Git/Github repositories.
*
* @see http://developer.github.com/v3/pulls/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class PullRequest extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/pulls/#custom-media-types
*
* @param string|null $bodyType
* @param string|null $apiVersion
*
* @return self
*/
public function configure($bodyType = null, $apiVersion = null)
{
if (!in_array($apiVersion, [])) {
$apiVersion = $this->client->getApiVersion();
}
if (!in_array($bodyType, ['text', 'html', 'full', 'diff', 'patch'])) {
$bodyType = 'raw';
}
if (!in_array($bodyType, ['diff', 'patch'])) {
$bodyType .= '+json';
}
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $apiVersion, $bodyType);
return $this;
}
/**
* Get a listing of a project's pull requests by the username, repository and (optionally) state.
*
* @link http://developer.github.com/v3/pulls/
*
* @param string $username the username
* @param string $repository the repository
* @param array $params a list of extra parameters.
*
* @return array array of pull requests for the project
*/
public function all($username, $repository, array $params = [])
{
$parameters = array_merge([
'page' => 1,
'per_page' => 30,
], $params);
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters);
}
/**
* Show all details of a pull request, including the discussions.
*
* @link http://developer.github.com/v3/pulls/
*
* @param string $username the username
* @param string $repository the repository
* @param int $id the ID of the pull request for which details are retrieved
*
* @return array|string pull request details
*/
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id));
}
public function commits($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits');
}
public function files($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files');
}
/**
* All statuses which are the statuses of its head branch.
*
* @see http://developer.github.com/v3/pulls/
*
* @param string $username the username
* @param string $repository the repository
* @param int $id the ID of the pull request for which statuses are retrieved
*
* @return array array of statuses for the project
*/
public function status($username, $repository, $id)
{
$link = $this->show($username, $repository, $id)['_links']['statuses']['href'];
return $this->get($link);
}
public function comments()
{
return new Comments($this->client);
}
public function reviews()
{
return new Review($this->client);
}
public function reviewRequests()
{
return new ReviewRequest($this->client);
}
/**
* Create a pull request.
*
* @link http://developer.github.com/v3/pulls/
*
* @param string $username the username
* @param string $repository the repository
* @param array $params A String of the branch or commit SHA that you want your changes to be pulled to.
* A String of the branch or commit SHA of your changes. Typically this will be a branch.
* If the branch is in a fork of the original repository, specify the username first:
* "my-user:some-branch". The String title of the Pull Request. The String body of
* the Pull Request. The issue number. Used when title and body is not set.
*
* @throws MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
// Two ways to create PR, using issue or title
if (!isset($params['issue']) && !isset($params['title'])) {
throw new MissingArgumentException(['issue', 'title']);
}
if (!isset($params['base'], $params['head'])) {
throw new MissingArgumentException(['base', 'head']);
}
// If `issue` is not sent, then `body` must be sent
if (!isset($params['issue']) && !isset($params['body'])) {
throw new MissingArgumentException(['issue', 'body']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params);
}
public function update($username, $repository, $id, array $params)
{
if (isset($params['state']) && !in_array($params['state'], ['open', 'closed'])) {
$params['state'] = 'open';
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id), $params);
}
public function merged($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge');
}
public function merge($username, $repository, $id, $message, $sha, $mergeMethod = 'merge', $title = null)
{
if (is_bool($mergeMethod)) {
$mergeMethod = $mergeMethod ? 'squash' : 'merge';
}
if (!in_array($mergeMethod, ['merge', 'squash', 'rebase'], true)) {
throw new InvalidArgumentException(sprintf('"$mergeMethod" must be one of ["merge", "squash", "rebase"] ("%s" given).', $mergeMethod));
}
$params = [
'commit_message' => $message,
'sha' => $sha,
'merge_method' => $mergeMethod,
];
if (is_string($title)) {
$params['commit_title'] = $title;
}
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', $params);
}
}

View File

@@ -0,0 +1,153 @@
<?php
namespace Github\Api\PullRequest;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/pulls/comments/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Comments extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/pulls/comments/#custom-media-types
*
* @param string|null $bodyType
* @param string|null @apiVersion
*
* @return self
*/
public function configure($bodyType = null, $apiVersion = null)
{
if (!in_array($apiVersion, ['squirrel-girl-preview'])) {
$apiVersion = $this->client->getApiVersion();
}
if (!in_array($bodyType, ['text', 'html', 'full'])) {
$bodyType = 'raw';
}
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $apiVersion, $bodyType);
return $this;
}
/**
* Get a listing of a pull request's comments by the username, repository and pull request number
* or all repository comments by the username and repository.
*
* @link https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request
* @link https://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository
*
* @param string $username the username
* @param string $repository the repository
* @param int|null $pullRequest the pull request number
* @param array $params a list of extra parameters.
*
* @return array
*/
public function all($username, $repository, $pullRequest = null, array $params = [])
{
if (null !== $pullRequest) {
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments');
}
$parameters = array_merge([
'page' => 1,
'per_page' => 30,
], $params);
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments', $parameters);
}
/**
* Get a single pull request comment by the username, repository and comment id.
*
* @link https://developer.github.com/v3/pulls/comments/#get-a-single-comment
*
* @param string $username the username
* @param string $repository the repository
* @param int $comment the comment id
*
* @return array
*/
public function show($username, $repository, $comment)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment));
}
/**
* Create a pull request comment by the username, repository and pull request number.
*
* @link https://developer.github.com/v3/pulls/comments/#create-a-comment
*
* @param string $username the username
* @param string $repository the repository
* @param int $pullRequest the pull request number
* @param array $params a list of extra parameters.
*
* @throws MissingArgumentException
*
* @return array
*/
public function create($username, $repository, $pullRequest, array $params)
{
if (!isset($params['body'])) {
throw new MissingArgumentException('body');
}
// If `in_reply_to` is set, other options are not necessary anymore
if (!isset($params['in_reply_to']) && !isset($params['commit_id'], $params['path'], $params['position'])) {
throw new MissingArgumentException(['commit_id', 'path', 'position']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments', $params);
}
/**
* Update a pull request comment by the username, repository and comment id.
*
* @link https://developer.github.com/v3/pulls/comments/#edit-a-comment
*
* @param string $username the username
* @param string $repository the repository
* @param int $comment the comment id
* @param array $params a list of extra parameters.
*
* @throws MissingArgumentException
*
* @return array
*/
public function update($username, $repository, $comment, array $params)
{
if (!isset($params['body'])) {
throw new MissingArgumentException('body');
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment), $params);
}
/**
* Delete a pull request comment by the username, repository and comment id.
*
* @link https://developer.github.com/v3/pulls/comments/#delete-a-comment
*
* @param string $username the username
* @param string $repository the repository
* @param int $comment the comment id
*
* @return string
*/
public function remove($username, $repository, $comment)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment));
}
}

View File

@@ -0,0 +1,177 @@
<?php
namespace Github\Api\PullRequest;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\InvalidArgumentException;
use Github\Exception\MissingArgumentException;
/**
* API for accessing Pull Request Reviews from your Git/Github repositories.
*
* @link https://developer.github.com/v3/pulls/reviews/
*
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
*/
class Review extends AbstractApi
{
use AcceptHeaderTrait;
public function configure()
{
return $this;
}
/**
* Get a listing of a pull request's reviews by the username, repository and pull request number.
*
* @link https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request
*
* @param string $username the username
* @param string $repository the repository
* @param int $pullRequest the pull request number
* @param array $params a list of extra parameters.
*
* @return array array of pull request reviews for the pull request
*/
public function all($username, $repository, $pullRequest, array $params = [])
{
$parameters = array_merge([
'page' => 1,
'per_page' => 30,
], $params);
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews', $parameters);
}
/**
* Get a single pull request review by the username, repository, pull request number and the review id.
*
* @link https://developer.github.com/v3/pulls/reviews/#get-a-single-review
*
* @param string $username the username
* @param string $repository the repository
* @param int $pullRequest the pull request number
* @param int $id the review id
*
* @return array the pull request review
*/
public function show($username, $repository, $pullRequest, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id);
}
/**
* Delete a single pull request review by the username, repository, pull request number and the review id.
*
* @link https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review
*
* @param string $username the username
* @param string $repository the repository
* @param int $pullRequest the pull request number
* @param int $id the review id
*
* @return array|string
*/
public function remove($username, $repository, $pullRequest, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id);
}
/**
* Get comments for a single pull request review.
*
* @link https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review
*
* @param string $username the username
* @param string $repository the repository
* @param int $pullRequest the pull request number
* @param int $id the review id
*
* @return array|string
*/
public function comments($username, $repository, $pullRequest, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/reviews/'.rawurlencode($id).'/comments');
}
/**
* Create a pull request review by the username, repository and pull request number.
*
* @link https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
*
* @param string $username the username
* @param string $repository the repository
* @param int $pullRequest the pull request number
* @param array $params a list of extra parameters.
*
* @throws MissingArgumentException
*
* @return array the pull request review
*/
public function create($username, $repository, $pullRequest, array $params = [])
{
if (array_key_exists('event', $params) && !in_array($params['event'], ['APPROVE', 'REQUEST_CHANGES', 'COMMENT'], true)) {
throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event']));
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews', $params);
}
/**
* Submit a pull request review by the username, repository, pull request number and the review id.
*
* @link https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review
*
* @param string $username the username
* @param string $repository the repository
* @param int $pullRequest the pull request number
* @param int $id the review id
* @param array $params a list of extra parameters.
*
* @throws MissingArgumentException
*
* @return array the pull request review
*/
public function submit($username, $repository, $pullRequest, $id, array $params = [])
{
if (!isset($params['event'])) {
throw new MissingArgumentException('event');
}
if (!in_array($params['event'], ['APPROVE', 'REQUEST_CHANGES', 'COMMENT'], true)) {
throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event']));
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/events', $params);
}
/**
* Dismiss a pull request review by the username, repository, pull request number and the review id.
*
* @link https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review
*
* @param string $username the username
* @param string $repository the repository
* @param int $pullRequest the pull request number
* @param int $id the review id
* @param string $message a mandatory dismissal message
*
* @return array|string
*/
public function dismiss($username, $repository, $pullRequest, $id, $message)
{
if (!is_string($message)) {
throw new InvalidArgumentException(sprintf('"message" must be a valid string ("%s" given).', gettype($message)));
}
if (empty($message)) {
throw new InvalidArgumentException('"message" is mandatory and cannot be empty');
}
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/dismissals', [
'message' => $message,
]);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Github\Api\PullRequest;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
/**
* @link https://developer.github.com/v3/pulls/review_requests/
*/
class ReviewRequest extends AbstractApi
{
use AcceptHeaderTrait;
public function configure()
{
return $this;
}
/**
* @link https://developer.github.com/v3/pulls/review_requests/#list-review-requests
*
* @param string $username
* @param string $repository
* @param int $pullRequest
* @param array $params
*
* @return array
*/
public function all($username, $repository, $pullRequest, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', $params);
}
/**
* @link https://developer.github.com/v3/pulls/review_requests/#create-a-review-request
*
* @param string $username
* @param string $repository
* @param int $pullRequest
* @param array $reviewers
*
* @return string
*/
public function create($username, $repository, $pullRequest, array $reviewers)
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers]);
}
/**
* @link https://developer.github.com/v3/pulls/review_requests/#delete-a-review-request
*
* @param string $username
* @param string $repository
* @param int $pullRequest
* @param array $reviewers
*
* @return string
*/
public function remove($username, $repository, $pullRequest, array $reviewers)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers]);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Github\Api;
/**
* Get rate limits.
*
* @link https://developer.github.com/v3/rate_limit/
*
* @author Jeff Finley <quickliketurtle@gmail.com>
*/
class RateLimit extends AbstractApi
{
/**
* Get rate limits.
*
* @return array
*/
public function getRateLimits()
{
return $this->get('/rate_limit');
}
/**
* Get core rate limit.
*
* @return int
*/
public function getCoreLimit()
{
$response = $this->getRateLimits();
return $response['resources']['core']['limit'];
}
/**
* Get search rate limit.
*
* @return int
*/
public function getSearchLimit()
{
$response = $this->getRateLimits();
return $response['resources']['search']['limit'];
}
}

View File

@@ -0,0 +1,682 @@
<?php
namespace Github\Api;
use Github\Api\Repository\Collaborators;
use Github\Api\Repository\Comments;
use Github\Api\Repository\Commits;
use Github\Api\Repository\Contents;
use Github\Api\Repository\DeployKeys;
use Github\Api\Repository\Downloads;
use Github\Api\Repository\Forks;
use Github\Api\Repository\Hooks;
use Github\Api\Repository\Labels;
use Github\Api\Repository\Projects;
use Github\Api\Repository\Protection;
use Github\Api\Repository\Releases;
use Github\Api\Repository\Stargazers;
use Github\Api\Repository\Statuses;
use Github\Api\Repository\Traffic;
/**
* Searching repositories, getting repository information
* and managing repository information for authenticated users.
*
* @link http://developer.github.com/v3/repos/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Thibault Duplessis <thibault.duplessis at gmail dot com>
*/
class Repo extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Search repositories by keyword.
*
* @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated
* @link http://developer.github.com/v3/search/#search-repositories
*
* @param string $keyword the search query
* @param array $params
*
* @return array list of found repositories
*/
public function find($keyword, array $params = [])
{
return $this->get('/legacy/repos/search/'.rawurlencode($keyword), array_merge(['start_page' => 1], $params));
}
/**
* List all public repositories.
*
* @link https://developer.github.com/v3/repos/#list-all-public-repositories
*
* @param int|null $id The integer ID of the last Repository that youve seen.
*
* @return array list of users found
*/
public function all($id = null)
{
if (!is_int($id)) {
return $this->get('/repositories');
}
return $this->get('/repositories?since='.rawurldecode($id));
}
/**
* Get the last year of commit activity for a repository grouped by week.
*
* @link http://developer.github.com/v3/repos/statistics/#commit-activity
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array commit activity grouped by week
*/
public function activity($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/commit_activity');
}
/**
* Get contributor commit statistics for a repository.
*
* @link http://developer.github.com/v3/repos/statistics/#contributors
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array list of contributors and their commit statistics
*/
public function statistics($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors');
}
/**
* Get a weekly aggregate of the number of additions and deletions pushed to a repository.
*
* @link http://developer.github.com/v3/repos/statistics/#code-frequency
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array list of weeks and their commit statistics
*/
public function frequency($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/code_frequency');
}
/**
* Get the weekly commit count for the repository owner and everyone else.
*
* @link http://developer.github.com/v3/repos/statistics/#participation
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array list of weekly commit count grouped by 'all' and 'owner'
*/
public function participation($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/participation');
}
/**
* List all repositories for an organization.
*
* @link http://developer.github.com/v3/repos/#list-organization-repositories
*
* @param string $organization the name of the organization
* @param array $params
*
* @return array list of organization repositories
*/
public function org($organization, array $params = [])
{
return $this->get('/orgs/'.$organization.'/repos', array_merge(['start_page' => 1], $params));
}
/**
* Get extended information about a repository by its username and repository name.
*
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array information about the repository
*/
public function show($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository));
}
/**
* Get extended information about a repository by its id.
* Note: at time of writing this is an undocumented feature but GitHub support have advised that it can be relied on.
*
* @link http://developer.github.com/v3/repos/
* @link https://github.com/piotrmurach/github/issues/283
* @link https://github.com/piotrmurach/github/issues/282
*
* @param int $id the id of the repository
*
* @return array information about the repository
*/
public function showById($id)
{
return $this->get('/repositories/'.rawurlencode($id));
}
/**
* Create repository.
*
* @link http://developer.github.com/v3/repos/
*
* @param string $name name of the repository
* @param string $description repository description
* @param string $homepage homepage url
* @param bool $public `true` for public, `false` for private
* @param null|string $organization username of organization if applicable
* @param bool $hasIssues `true` to enable issues for this repository, `false` to disable them
* @param bool $hasWiki `true` to enable the wiki for this repository, `false` to disable it
* @param bool $hasDownloads `true` to enable downloads for this repository, `false` to disable them
* @param int $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization.
* @param bool $autoInit `true` to create an initial commit with empty README, `false` for no initial commit
*
* @return array returns repository data
*/
public function create(
$name,
$description = '',
$homepage = '',
$public = true,
$organization = null,
$hasIssues = false,
$hasWiki = false,
$hasDownloads = false,
$teamId = null,
$autoInit = false
) {
$path = null !== $organization ? '/orgs/'.$organization.'/repos' : '/user/repos';
$parameters = [
'name' => $name,
'description' => $description,
'homepage' => $homepage,
'private' => !$public,
'has_issues' => $hasIssues,
'has_wiki' => $hasWiki,
'has_downloads' => $hasDownloads,
'auto_init' => $autoInit,
];
if ($organization && $teamId) {
$parameters['team_id'] = $teamId;
}
return $this->post($path, $parameters);
}
/**
* Set information of a repository.
*
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param array $values the key => value pairs to post
*
* @return array information about the repository
*/
public function update($username, $repository, array $values)
{
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository), $values);
}
/**
* Delete a repository.
*
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return mixed null on success, array on error with 'message'
*/
public function remove($username, $repository)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository));
}
/**
* Get the readme content for a repository by its username and repository name.
*
* @link http://developer.github.com/v3/repos/contents/#get-the-readme
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param string $format one of formats: "raw", "html", or "v3+json"
*
* @return string|array the readme content
*/
public function readme($username, $repository, $format = 'raw')
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', [], [
'Accept' => "application/vnd.github.$format",
]);
}
/**
* Manage the collaborators of a repository.
*
* @link http://developer.github.com/v3/repos/collaborators/
*
* @return Collaborators
*/
public function collaborators()
{
return new Collaborators($this->client);
}
/**
* Manage the comments of a repository.
*
* @link http://developer.github.com/v3/repos/comments/
*
* @return Comments
*/
public function comments()
{
return new Comments($this->client);
}
/**
* Manage the commits of a repository.
*
* @link http://developer.github.com/v3/repos/commits/
*
* @return Commits
*/
public function commits()
{
return new Commits($this->client);
}
/**
* Manage the content of a repository.
*
* @link http://developer.github.com/v3/repos/contents/
*
* @return Contents
*/
public function contents()
{
return new Contents($this->client);
}
/**
* Manage the content of a repository.
*
* @link http://developer.github.com/v3/repos/downloads/
*
* @return Downloads
*/
public function downloads()
{
return new Downloads($this->client);
}
/**
* Manage the releases of a repository (Currently Undocumented).
*
* @link http://developer.github.com/v3/repos/
*
* @return Releases
*/
public function releases()
{
return new Releases($this->client);
}
/**
* Manage the deploy keys of a repository.
*
* @link http://developer.github.com/v3/repos/keys/
*
* @return DeployKeys
*/
public function keys()
{
return new DeployKeys($this->client);
}
/**
* Manage the forks of a repository.
*
* @link http://developer.github.com/v3/repos/forks/
*
* @return Forks
*/
public function forks()
{
return new Forks($this->client);
}
/**
* Manage the stargazers of a repository.
*
* @link https://developer.github.com/v3/activity/starring/#list-stargazers
*
* @return Stargazers
*/
public function stargazers()
{
return new Stargazers($this->client);
}
/**
* Manage the hooks of a repository.
*
* @link http://developer.github.com/v3/issues/jooks/
*
* @return Hooks
*/
public function hooks()
{
return new Hooks($this->client);
}
/**
* Manage the labels of a repository.
*
* @link http://developer.github.com/v3/issues/labels/
*
* @return Labels
*/
public function labels()
{
return new Labels($this->client);
}
/**
* Manage the statuses of a repository.
*
* @link http://developer.github.com/v3/repos/statuses/
*
* @return Statuses
*/
public function statuses()
{
return new Statuses($this->client);
}
/**
* Get the branch(es) of a repository.
*
* @link http://developer.github.com/v3/repos/
*
* @param string $username the username
* @param string $repository the name of the repository
* @param string $branch the name of the branch
*
* @return array list of the repository branches
*/
public function branches($username, $repository, $branch = null)
{
$url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches';
if (null !== $branch) {
$url .= '/'.rawurlencode($branch);
}
return $this->get($url);
}
/**
* Manage the protection of a repository branch.
*
* @link https://developer.github.com/v3/repos/branches/#get-branch-protection
*
* @return Protection
*/
public function protection()
{
return new Protection($this->client);
}
/**
* Get the contributors of a repository.
*
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param bool $includingAnonymous by default, the list only shows GitHub users.
* You can include non-users too by setting this to true
*
* @return array list of the repo contributors
*/
public function contributors($username, $repository, $includingAnonymous = false)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contributors', [
'anon' => $includingAnonymous ?: null,
]);
}
/**
* Get the language breakdown of a repository.
*
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array list of the languages
*/
public function languages($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/languages');
}
/**
* Get the tags of a repository.
*
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param array $params the additional parameters like milestone, assignees, labels, sort, direction
*
* @return array list of the repository tags
*/
public function tags($username, $repository, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/tags', $params);
}
/**
* Get the teams of a repository.
*
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array list of the languages
*/
public function teams($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/teams');
}
/**
* @deprecated see subscribers method
*
* @param string $username
* @param string $repository
* @param int $page
*
* @return array
*/
public function watchers($username, $repository, $page = 1)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', [
'page' => $page,
]);
}
/**
* @param string $username
* @param string $repository
* @param int $page
*
* @return array
*/
public function subscribers($username, $repository, $page = 1)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/subscribers', [
'page' => $page,
]);
}
/**
* Perform a merge.
*
* @link http://developer.github.com/v3/repos/merging/
*
* @param string $username
* @param string $repository
* @param string $base The name of the base branch that the head will be merged into.
* @param string $head The head to merge. This can be a branch name or a commit SHA1.
* @param string $message Commit message to use for the merge commit. If omitted, a default message will be used.
*
* @return array|null
*/
public function merge($username, $repository, $base, $head, $message = null)
{
$parameters = [
'base' => $base,
'head' => $head,
];
if (is_string($message)) {
$parameters['commit_message'] = $message;
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/merges', $parameters);
}
/**
* @param string $username
* @param string $repository
*
* @return array
*/
public function milestones($username, $repository)
{
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones');
}
public function projects()
{
return new Projects($this->client);
}
public function traffic()
{
return new Traffic($this->client);
}
/**
* @param string $username
* @param string $repository
* @param int $page
*
* @return array|string
*
* @see https://developer.github.com/v3/activity/events/#list-repository-events
*/
public function events($username, $repository, $page = 1)
{
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]);
}
/**
* Get the contents of a repository's code of conduct.
*
* @link https://developer.github.com/v3/codes_of_conduct/#get-the-contents-of-a-repositorys-code-of-conduct
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function codeOfConduct($username, $repository)
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.scarlet-witch-preview+json';
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/community/code_of_conduct');
}
/**
* List all topics for a repository.
*
* @link https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function topics($username, $repository)
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics');
}
/**
* Replace all topics for a repository.
*
* @link https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
*
* @param string $username
* @param string $repository
* @param array $topics
*
* @return array
*/
public function replaceTopics($username, $repository, array $topics)
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';
return $this->put('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics', ['names' => $topics]);
}
/**
* Transfer a repository.
*
* @link https://developer.github.com/v3/repos/#transfer-a-repository
*
* @param string $username
* @param string $repository
* @param string $newOwner
* @param array $teamId
*
* @return array
*/
public function transfer($username, $repository, $newOwner, $teamId = [])
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.nightshade-preview+json';
return $this->post('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/transfer', ['new_owner' => $newOwner, 'team_id' => $teamId]);
}
}

View File

@@ -0,0 +1,118 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Exception\ErrorException;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/repos/releases/
*
* @author Evgeniy Guseletov <d46k16@gmail.com>
*/
class Assets extends AbstractApi
{
/**
* Get all release's assets in selected repository
* GET /repos/:owner/:repo/releases/:id/assets.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the release
*
* @return array
*/
public function all($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets');
}
/**
* Get an asset in selected repository's release
* GET /repos/:owner/:repo/releases/assets/:id.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the asset
*
* @return array
*/
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id));
}
/**
* Create an asset for selected repository's release
* POST /repos/:owner/:repo/releases/:id/assets?name=:filename.
*
* Creating an asset requires support for server name indentification (SNI)
* so this must be supported by your PHP version.
*
* @see http://developer.github.com/v3/repos/releases/#upload-a-release-asset
* @see http://php.net/manual/en/openssl.constsni.php
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the release
* @param string $name the filename for the asset
* @param string $contentType the content type for the asset
* @param string $content the content of the asset
*
* @throws MissingArgumentException
* @throws ErrorException
*
* @return array
*/
public function create($username, $repository, $id, $name, $contentType, $content)
{
if (!defined('OPENSSL_TLSEXT_SERVER_NAME') || !OPENSSL_TLSEXT_SERVER_NAME) {
throw new ErrorException('Asset upload support requires Server Name Indication. This is not supported by your PHP version. See http://php.net/manual/en/openssl.constsni.php.');
}
// Asset creation requires a separate endpoint, uploads.github.com.
// Change the base url for the HTTP client temporarily while we execute
// this request.
$response = $this->postRaw('https://uploads.github.com/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, ['Content-Type' => $contentType]);
return $response;
}
/**
* Edit an asset in selected repository's release
* PATCH /repos/:owner/:repo/releases/assets/:id.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the asset
* @param array $params request parameters
*
* @throws MissingArgumentException
*
* @return array
*/
public function edit($username, $repository, $id, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException('name');
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id), $params);
}
/**
* Delete an asset in selected repository's release
* DELETE /repos/:owner/:repo/releases/assets/:id.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the asset
*
* @return array
*/
public function remove($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id));
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
/**
* @link http://developer.github.com/v3/repos/collaborators/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Collaborators extends AbstractApi
{
/**
* @link https://developer.github.com/v3/repos/collaborators/#list-collaborators
*
* @param $username
* @param $repository
* @param array $params
*
* @return array|string
*/
public function all($username, $repository, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators', $params);
}
/**
* @link https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator
*
* @param $username
* @param $repository
* @param $collaborator
*
* @return array|string
*/
public function check($username, $repository, $collaborator)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator));
}
/**
* @link https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
*
* @param $username
* @param $repository
* @param $collaborator
* @param array $params
*
* @return array|string
*/
public function add($username, $repository, $collaborator, array $params = [])
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator), $params);
}
/**
* @link https://developer.github.com/v3/repos/collaborators/#remove-user-as-a-collaborator
*
* @param $username
* @param $repository
* @param $collaborator
*
* @return array|string
*/
public function remove($username, $repository, $collaborator)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator));
}
/**
* @link https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
*
* @param $username
* @param $repository
* @param $collaborator
*
* @return array|string
*/
public function permission($username, $repository, $collaborator)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator).'/permission');
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/repos/comments/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class Comments extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/repos/comments/#custom-media-types
*
* @param string|null $bodyType
*
* @return self
*/
public function configure($bodyType = null)
{
if (!in_array($bodyType, ['raw', 'text', 'html'])) {
$bodyType = 'full';
}
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType);
return $this;
}
public function all($username, $repository, $sha = null)
{
if (null === $sha) {
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments');
}
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/comments');
}
public function show($username, $repository, $comment)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment));
}
public function create($username, $repository, $sha, array $params)
{
if (!isset($params['body'])) {
throw new MissingArgumentException('body');
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/comments', $params);
}
public function update($username, $repository, $comment, array $params)
{
if (!isset($params['body'])) {
throw new MissingArgumentException('body');
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment), $params);
}
public function remove($username, $repository, $comment)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment));
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
/**
* @link http://developer.github.com/v3/repos/commits/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Commits extends AbstractApi
{
public function all($username, $repository, array $params)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits', $params);
}
public function compare($username, $repository, $base, $head, $mediaType = null)
{
$headers = [];
if (null !== $mediaType) {
$headers['Accept'] = $mediaType;
}
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), [], $headers);
}
public function show($username, $repository, $sha)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha));
}
}

View File

@@ -0,0 +1,297 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\ErrorException;
use Github\Exception\InvalidArgumentException;
use Github\Exception\MissingArgumentException;
use Github\Exception\TwoFactorAuthenticationRequiredException;
/**
* @link http://developer.github.com/v3/repos/contents/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Contents extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/repo/contents/#custom-media-types
*
* @param string|null $bodyType
*
* @return self
*/
public function configure($bodyType = null)
{
if (!in_array($bodyType, ['html', 'object'])) {
$bodyType = 'raw';
}
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType);
return $this;
}
/**
* Get content of README file in a repository.
*
* @link http://developer.github.com/v3/repos/contents/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param null|string $reference reference to a branch or commit
*
* @return array information for README file
*/
public function readme($username, $repository, $reference = null)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', [
'ref' => $reference,
]);
}
/**
* Get contents of any file or directory in a repository.
*
* @link http://developer.github.com/v3/repos/contents/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param null|string $path path to file or directory
* @param null|string $reference reference to a branch or commit
*
* @return array|string information for file | information for each item in directory
*/
public function show($username, $repository, $path = null, $reference = null)
{
$url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents';
if (null !== $path) {
$url .= '/'.rawurlencode($path);
}
return $this->get($url, [
'ref' => $reference,
]);
}
/**
* Creates a new file in a repository.
*
* @link http://developer.github.com/v3/repos/contents/#create-a-file
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param string $path path to file
* @param string $content contents of the new file
* @param string $message the commit message
* @param null|string $branch name of a branch
* @param null|array $committer information about the committer
*
* @throws MissingArgumentException
*
* @return array information about the new file
*/
public function create($username, $repository, $path, $content, $message, $branch = null, array $committer = null)
{
$url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path);
$parameters = [
'content' => base64_encode($content),
'message' => $message,
];
if (null !== $branch) {
$parameters['branch'] = $branch;
}
if (null !== $committer) {
if (!isset($committer['name'], $committer['email'])) {
throw new MissingArgumentException(['name', 'email']);
}
$parameters['committer'] = $committer;
}
return $this->put($url, $parameters);
}
/**
* Checks that a given path exists in a repository.
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param string $path path of file to check
* @param null|string $reference reference to a branch or commit
*
* @return bool
*/
public function exists($username, $repository, $path, $reference = null)
{
$url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents';
if (null !== $path) {
$url .= '/'.rawurlencode($path);
}
try {
$response = $this->head($url, [
'ref' => $reference,
]);
if ($response->getStatusCode() != 200) {
return false;
}
} catch (TwoFactorAuthenticationRequiredException $ex) {
throw $ex;
} catch (\Exception $ex) {
return false;
}
return true;
}
/**
* Updates the contents of a file in a repository.
*
* @link http://developer.github.com/v3/repos/contents/#update-a-file
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param string $path path to file
* @param string $content contents of the new file
* @param string $message the commit message
* @param string $sha blob SHA of the file being replaced
* @param null|string $branch name of a branch
* @param null|array $committer information about the committer
*
* @throws MissingArgumentException
*
* @return array information about the updated file
*/
public function update($username, $repository, $path, $content, $message, $sha, $branch = null, array $committer = null)
{
$url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path);
$parameters = [
'content' => base64_encode($content),
'message' => $message,
'sha' => $sha,
];
if (null !== $branch) {
$parameters['branch'] = $branch;
}
if (null !== $committer) {
if (!isset($committer['name'], $committer['email'])) {
throw new MissingArgumentException(['name', 'email']);
}
$parameters['committer'] = $committer;
}
return $this->put($url, $parameters);
}
/**
* Deletes a file from a repository.
*
* @link http://developer.github.com/v3/repos/contents/#delete-a-file
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param string $path path to file
* @param string $message the commit message
* @param string $sha blob SHA of the file being deleted
* @param null|string $branch name of a branch
* @param null|array $committer information about the committer
*
* @throws MissingArgumentException
*
* @return array information about the updated file
*/
public function rm($username, $repository, $path, $message, $sha, $branch = null, array $committer = null)
{
$url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path);
$parameters = [
'message' => $message,
'sha' => $sha,
];
if (null !== $branch) {
$parameters['branch'] = $branch;
}
if (null !== $committer) {
if (!isset($committer['name'], $committer['email'])) {
throw new MissingArgumentException(['name', 'email']);
}
$parameters['committer'] = $committer;
}
return $this->delete($url, $parameters);
}
/**
* Get content of archives in a repository.
*
* @link http://developer.github.com/v3/repos/contents/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param string $format format of archive: tarball or zipball
* @param null|string $reference reference to a branch or commit
*
* @return string repository archive binary data
*/
public function archive($username, $repository, $format, $reference = null)
{
if (!in_array($format, ['tarball', 'zipball'])) {
$format = 'tarball';
}
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($format).
((null !== $reference) ? ('/'.rawurlencode($reference)) : ''));
}
/**
* Get the contents of a file in a repository.
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param string $path path to file
* @param null|string $reference reference to a branch or commit
*
* @throws InvalidArgumentException If $path is not a file or if its encoding is different from base64
* @throws ErrorException If $path doesn't include a 'content' index
*
* @return null|string content of file, or null in case of base64_decode failure
*/
public function download($username, $repository, $path, $reference = null)
{
$file = $this->show($username, $repository, $path, $reference);
if (!isset($file['type']) || 'file' !== $file['type']) {
throw new InvalidArgumentException(sprintf('Path "%s" is not a file.', $path));
}
if (!isset($file['content'])) {
throw new ErrorException(sprintf('Unable to access "content" for file "%s" (possible keys: "%s").', $path, implode(', ', array_keys($file))));
}
if (!isset($file['encoding'])) {
throw new InvalidArgumentException(sprintf('Can\'t decode content of file "%s", as no encoding is defined.', $path));
}
if ('base64' !== $file['encoding']) {
throw new InvalidArgumentException(sprintf('Encoding "%s" of file "%s" is not supported.', $file['encoding'], $path));
}
return base64_decode($file['content']) ?: null;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/repos/keys/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class DeployKeys extends AbstractApi
{
public function all($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys');
}
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id));
}
public function create($username, $repository, array $params)
{
if (!isset($params['title'], $params['key'])) {
throw new MissingArgumentException(['title', 'key']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys', $params);
}
public function update($username, $repository, $id, array $params)
{
if (!isset($params['title'], $params['key'])) {
throw new MissingArgumentException(['title', 'key']);
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id), $params);
}
public function remove($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id));
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
/**
* @link http://developer.github.com/v3/repos/downloads/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Downloads extends AbstractApi
{
/**
* List downloads in selected repository.
*
* @link http://developer.github.com/v3/repos/downloads/#list-downloads-for-a-repository
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array
*/
public function all($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads');
}
/**
* Get a download in selected repository.
*
* @link http://developer.github.com/v3/repos/downloads/#get-a-single-download
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the download file
*
* @return array
*/
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id));
}
/**
* Delete a download in selected repository.
*
* @link http://developer.github.com/v3/repos/downloads/#delete-a-download
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the download file
*
* @return array
*/
public function remove($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id));
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
/**
* @link http://developer.github.com/v3/repos/forks/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Forks extends AbstractApi
{
public function all($username, $repository, array $params = [])
{
if (isset($params['sort']) && !in_array($params['sort'], ['newest', 'oldest', 'watchers'])) {
$params['sort'] = 'newest';
}
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', array_merge(['page' => 1], $params));
}
public function create($username, $repository, array $params = [])
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', $params);
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/repos/hooks/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Hooks extends AbstractApi
{
public function all($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks');
}
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id));
}
public function create($username, $repository, array $params)
{
if (!isset($params['name'], $params['config'])) {
throw new MissingArgumentException(['name', 'config']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks', $params);
}
public function update($username, $repository, $id, array $params)
{
if (!isset($params['config'])) {
throw new MissingArgumentException(['config']);
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id), $params);
}
public function ping($username, $repository, $id)
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/pings');
}
public function test($username, $repository, $id)
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/test');
}
public function remove($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id));
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/issues/labels/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Labels extends AbstractApi
{
public function all($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels');
}
public function show($username, $repository, $label)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
}
public function create($username, $repository, array $params)
{
if (!isset($params['name'], $params['color'])) {
throw new MissingArgumentException(['name', 'color']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params);
}
public function update($username, $repository, $label, array $params)
{
if (!isset($params['name'], $params['color'])) {
throw new MissingArgumentException(['name', 'color']);
}
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params);
}
public function remove($username, $repository, $label)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Github\Api\Repository;
use Github\Api\Project\AbstractProjectApi;
use Github\Exception\MissingArgumentException;
class Projects extends AbstractProjectApi
{
public function all($username, $repository, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', array_merge(['page' => 1], $params));
}
public function create($username, $repository, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException(['name']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', $params);
}
}

View File

@@ -0,0 +1,441 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
/**
* @link https://developer.github.com/v3/repos/branches/
*
* @author Brandon Bloodgood <bbloodgood@gmail.com>
*/
class Protection extends AbstractApi
{
use AcceptHeaderTrait;
public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.loki-preview+json';
return $this;
}
/**
* Retrieves configured protection for the provided branch.
*
* @link https://developer.github.com/v3/repos/branches/#get-branch-protection
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*
* @return array The branch protection information
*/
public function show($username, $repository, $branch)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection');
}
/**
* Updates the repo's branch protection.
*
* @link https://developer.github.com/v3/repos/branches/#update-branch-protection
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The branch protection information
*
* @return array The updated branch protection information
*/
public function update($username, $repository, $branch, array $params = [])
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection', $params);
}
/**
* Remove the repo's branch protection.
*
* @link https://developer.github.com/v3/repos/branches/#remove-branch-protection
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*/
public function remove($username, $repository, $branch)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection');
}
/**
* Get required status checks of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*
* @return array The required status checks information
*/
public function showStatusChecks($username, $repository, $branch)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks');
}
/**
* Update required status checks of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The branch status checks information
*
* @return array The updated branch status checks information
*/
public function updateStatusChecks($username, $repository, $branch, array $params = [])
{
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks', $params);
}
/**
* Remove required status checks of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*/
public function removeStatusChecks($username, $repository, $branch)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks');
}
/**
* List required status checks contexts of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*
* @return array The required status checks contexts information
*/
public function showStatusChecksContexts($username, $repository, $branch)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts');
}
/**
* Replace required status checks contexts of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The branch status checks contexts information
*
* @return array The new branch status checks contexts information
*/
public function replaceStatusChecksContexts($username, $repository, $branch, array $params = [])
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params);
}
/**
* Add required status checks contexts of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#add-required-status-checks-contexts-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The branch status checks contexts information
*
* @return array The updated branch status checks contexts information
*/
public function addStatusChecksContexts($username, $repository, $branch, array $params = [])
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params);
}
/**
* Remove required status checks contexts of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The branch status checks contexts information
*
* @return array The updated branch status checks contexts information
*/
public function removeStatusChecksContexts($username, $repository, $branch, array $params = [])
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params);
}
/**
* Get pull request review enforcement of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#get-pull-request-review-enforcement-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*
* @return array The pull request review enforcement information
*/
public function showPullRequestReviewEnforcement($username, $repository, $branch)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews');
}
/**
* Update pull request review enforcement of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The branch status checks information
*
* @return array The updated branch status checks information
*/
public function updatePullRequestReviewEnforcement($username, $repository, $branch, array $params = [])
{
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews', $params);
}
/**
* Remove pull request review enforcement of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#remove-pull-request-review-enforcement-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*/
public function removePullRequestReviewEnforcement($username, $repository, $branch)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews');
}
/**
* Get admin enforcement of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#get-admin-enforcement-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*
* @return array The admin enforcement information
*/
public function showAdminEnforcement($username, $repository, $branch)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/enforce_admins');
}
/**
* Add admin enforcement of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#add-admin-enforcement-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*
* @return array The updated admin enforcement information
*/
public function addAdminEnforcement($username, $repository, $branch)
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/enforce_admins');
}
/**
* Remove admin enforcement of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#remove-admin-enforcement-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*/
public function removeAdminEnforcement($username, $repository, $branch)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/enforce_admins');
}
/**
* Get restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*
* @return array The branch restrictions information
*/
public function showRestrictions($username, $repository, $branch)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions');
}
/**
* Remove restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#remove-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*/
public function removeRestrictions($username, $repository, $branch)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions');
}
/**
* List team restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*
* @return array The branch team restrictions information
*/
public function showTeamRestrictions($username, $repository, $branch)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams');
}
/**
* Replace team restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The list of team slugs with push access
*
* @return array The new branch team restrictions information
*/
public function replaceTeamRestrictions($username, $repository, $branch, array $params = [])
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params);
}
/**
* Add team restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The list of team slugs with push access
*
* @return array The branch team restrictions information
*/
public function addTeamRestrictions($username, $repository, $branch, array $params = [])
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params);
}
/**
* Remove team restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The list of team slugs with push access
*
* @return array The updated branch team restrictions information
*/
public function removeTeamRestrictions($username, $repository, $branch, array $params = [])
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params);
}
/**
* List user restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#list-user-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
*
* @return array The branch user restrictions information
*/
public function showUserRestrictions($username, $repository, $branch)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users');
}
/**
* Replace user restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The list of user logins with push access
*
* @return array The new branch user restrictions information
*/
public function replaceUserRestrictions($username, $repository, $branch, array $params = [])
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params);
}
/**
* Add user restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The list of user logins with push access
*
* @return array The branch user restrictions information
*/
public function addUserRestrictions($username, $repository, $branch, array $params = [])
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params);
}
/**
* Remove user restrictions of protected branch.
*
* @link https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch
*
* @param string $username The user who owns the repository
* @param string $repository The name of the repo
* @param string $branch The name of the branch
* @param array $params The list of user logins with push access
*
* @return array The updated branch user restrictions information
*/
public function removeUserRestrictions($username, $repository, $branch, array $params = [])
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params);
}
}

View File

@@ -0,0 +1,127 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/repos/releases/
*
* @author Matthew Simo <matthew.a.simo@gmail.com>
* @author Evgeniy Guseletov <d46k16@gmail.com>
*/
class Releases extends AbstractApi
{
/**
* Get the latest release.
*
* @param $username
* @param $repository
*
* @return array
*/
public function latest($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest');
}
/**
* List releases for a tag.
*
* @param $username
* @param $repository
* @param $tag
*
* @return array
*/
public function tag($username, $repository, $tag)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/tags/'.rawurlencode($tag));
}
/**
* List releases in selected repository.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param array $params the additional parameters like milestone, assignees, labels, sort, direction
*
* @return array
*/
public function all($username, $repository, array $params = [])
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params);
}
/**
* Get a release in selected repository.
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the release
*
* @return array
*/
public function show($username, $repository, $id)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id));
}
/**
* Create new release in selected repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @throws MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
if (!isset($params['tag_name'])) {
throw new MissingArgumentException('tag_name');
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params);
}
/**
* Edit release in selected repository.
*
* @param string $username
* @param string $repository
* @param int $id
* @param array $params
*
* @return array
*/
public function edit($username, $repository, $id, array $params)
{
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params);
}
/**
* Delete a release in selected repository (Not thoroughly tested!).
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param int $id the id of the release
*
* @return array
*/
public function remove($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id));
}
/**
* @return Assets
*/
public function assets()
{
return new Assets($this->client);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
/**
* @link https://developer.github.com/v3/activity/starring/#list-stargazers
*
* @author Nicolas Dupont <nicolas@akeneo.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class Stargazers extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Configure the body type.
*
* @see https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps
*
* @param string $bodyType
*
* @return self
*/
public function configure($bodyType = null)
{
if ('star' === $bodyType) {
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getApiVersion());
}
return $this;
}
public function all($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stargazers');
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/repos/statuses/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Statuses extends AbstractApi
{
/**
* @link http://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-sha
*
* @param string $username
* @param string $repository
* @param string $sha
*
* @return array
*/
public function show($username, $repository, $sha)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/statuses');
}
/**
* @link https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
*
* @param string $username
* @param string $repository
* @param string $sha
*
* @return array
*/
public function combined($username, $repository, $sha)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/status');
}
/**
* @link http://developer.github.com/v3/repos/statuses/#create-a-status
*
* @param string $username
* @param string $repository
* @param string $sha
* @param array $params
*
* @throws MissingArgumentException
*
* @return array
*/
public function create($username, $repository, $sha, array $params = [])
{
if (!isset($params['state'])) {
throw new MissingArgumentException('state');
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/statuses/'.rawurlencode($sha), $params);
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Github\Api\Repository;
use Github\Api\AbstractApi;
/**
* @link https://developer.github.com/v3/repos/traffic/
*
* @author Miguel Piedrafita <soy@miguelpiedrafita.com>
*/
class Traffic extends AbstractApi
{
/**
* @link https://developer.github.com/v3/repos/traffic/#list-referrers
*
* @param string $owner
* @param string $repository
*
* @return array
*/
public function referers($owner, $repository)
{
return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/popular/referrers');
}
/**
* @link https://developer.github.com/v3/repos/traffic/#list-paths
*
* @param string $owner
* @param string $repository
*
* @return array
*/
public function paths($owner, $repository)
{
return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/popular/paths');
}
/**
* @link https://developer.github.com/v3/repos/traffic/#views
*
* @param string $owner
* @param string $repository
* @param string $per
*
* @return array
*/
public function views($owner, $repository, $per = 'day')
{
return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/views?per='.rawurlencode($per));
}
/**
* @link https://developer.github.com/v3/repos/traffic/#clones
*
* @param string $owner
* @param string $repository
* @param string $per
*
* @return array
*/
public function clones($owner, $repository, $per = 'day')
{
return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/clones?per='.rawurlencode($per));
}
}

View File

@@ -0,0 +1,115 @@
<?php
namespace Github\Api;
/**
* Implement the Search API.
*
* @link https://developer.github.com/v3/search/
*
* @author Greg Payne <greg.payne@gmail.com>
*/
class Search extends AbstractApi
{
use AcceptHeaderTrait;
/**
* Search repositories by filter (q).
*
* @link https://developer.github.com/v3/search/#search-repositories
*
* @param string $q the filter
* @param string $sort the sort field
* @param string $order asc/desc
*
* @return array list of repositories found
*/
public function repositories($q, $sort = 'updated', $order = 'desc')
{
return $this->get('/search/repositories', ['q' => $q, 'sort' => $sort, 'order' => $order]);
}
/**
* Search issues by filter (q).
*
* @link https://developer.github.com/v3/search/#search-issues
*
* @param string $q the filter
* @param string $sort the sort field
* @param string $order asc/desc
*
* @return array list of issues found
*/
public function issues($q, $sort = 'updated', $order = 'desc')
{
return $this->get('/search/issues', ['q' => $q, 'sort' => $sort, 'order' => $order]);
}
/**
* Search code by filter (q).
*
* @link https://developer.github.com/v3/search/#search-code
*
* @param string $q the filter
* @param string $sort the sort field
* @param string $order asc/desc
*
* @return array list of code found
*/
public function code($q, $sort = 'updated', $order = 'desc')
{
return $this->get('/search/code', ['q' => $q, 'sort' => $sort, 'order' => $order]);
}
/**
* Search users by filter (q).
*
* @link https://developer.github.com/v3/search/#search-users
*
* @param string $q the filter
* @param string $sort the sort field
* @param string $order asc/desc
*
* @return array list of users found
*/
public function users($q, $sort = 'updated', $order = 'desc')
{
return $this->get('/search/users', ['q' => $q, 'sort' => $sort, 'order' => $order]);
}
/**
* Search commits by filter (q).
*
* @link https://developer.github.com/v3/search/#search-commits
*
* @param string $q the filter
* @param string $sort the sort field
* @param string $order sort order. asc/desc
*
* @return array
*/
public function commits($q, $sort = null, $order = 'desc')
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.cloak-preview';
return $this->get('/search/commits', ['q' => $q, 'sort' => $sort, 'order' => $order]);
}
/**
* Search commits by filter (q).
*
* @link https://developer.github.com/v3/search/#search-topics
*
* @param string $q the filter
*
* @return array
*/
public function topics($q)
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json';
return $this->get('/search/topics', ['q' => $q]);
}
}

View File

@@ -0,0 +1,251 @@
<?php
namespace Github\Api;
/**
* Searching users, getting user information.
*
* @link http://developer.github.com/v3/users/
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Thibault Duplessis <thibault.duplessis at gmail dot com>
*/
class User extends AbstractApi
{
/**
* Search users by username.
*
* @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated
* @link http://developer.github.com/v3/search/#search-users
*
* @param string $keyword the keyword to search
*
* @return array list of users found
*/
public function find($keyword)
{
return $this->get('/legacy/user/search/'.rawurlencode($keyword));
}
/**
* Request all users.
*
* @link https://developer.github.com/v3/users/#get-all-users
*
* @param int|null $id ID of the last user that you've seen
*
* @return array list of users found
*/
public function all($id = null)
{
if (!is_int($id)) {
return $this->get('/users');
}
return $this->get('/users', ['since' => rawurldecode($id)]);
}
/**
* Get extended information about a user by its username.
*
* @link http://developer.github.com/v3/users/
*
* @param string $username the username to show
*
* @return array information about the user
*/
public function show($username)
{
return $this->get('/users/'.rawurlencode($username));
}
/**
* Get extended information about a user by its username.
*
* @link https://developer.github.com/v3/orgs/
*
* @param string $username the username to show
*
* @return array information about organizations that user belongs to
*/
public function organizations($username)
{
return $this->get('/users/'.rawurlencode($username).'/orgs');
}
/**
* Get user organizations.
*
* @link https://developer.github.com/v3/orgs/#list-your-organizations
*
* @return array information about organizations that authenticated user belongs to
*/
public function orgs()
{
return $this->get('/user/orgs');
}
/**
* Request the users that a specific user is following.
*
* @link http://developer.github.com/v3/users/followers/
*
* @param string $username the username
* @param array $parameters parameters for the query string
* @param array $requestHeaders additional headers to set in the request
*
* @return array list of followed users
*/
public function following($username, array $parameters = [], array $requestHeaders = [])
{
return $this->get('/users/'.rawurlencode($username).'/following', $parameters, $requestHeaders);
}
/**
* Request the users following a specific user.
*
* @link http://developer.github.com/v3/users/followers/
*
* @param string $username the username
* @param array $parameters parameters for the query string
* @param array $requestHeaders additional headers to set in the request
*
* @return array list of following users
*/
public function followers($username, array $parameters = [], array $requestHeaders = [])
{
return $this->get('/users/'.rawurlencode($username).'/followers', $parameters, $requestHeaders);
}
/**
* Request the repository that a specific user is watching.
*
* @deprecated see subscriptions method
*
* @param string $username the username
*
* @return array list of watched repositories
*/
public function watched($username)
{
return $this->get('/users/'.rawurlencode($username).'/watched');
}
/**
* Request starred repositories that a specific user has starred.
*
* @link http://developer.github.com/v3/activity/starring/
*
* @param string $username the username
* @param int $page the page number of the paginated result set
* @param int $perPage the number of results per page
* @param string $sort sort by (possible values: created, updated)
* @param string $direction direction of sort (possible values: asc, desc)
*
* @return array list of starred repositories
*/
public function starred($username, $page = 1, $perPage = 30, $sort = 'created', $direction = 'desc')
{
return $this->get('/users/'.rawurlencode($username).'/starred', [
'page' => $page,
'per_page' => $perPage,
'sort' => $sort,
'direction' => $direction,
]);
}
/**
* Request the repository that a specific user is watching.
*
* @link http://developer.github.com/v3/activity/watching/
*
* @param string $username the username
*
* @return array list of watched repositories
*/
public function subscriptions($username)
{
return $this->get('/users/'.rawurlencode($username).'/subscriptions');
}
/**
* List public repositories for the specified user.
*
* @link https://developer.github.com/v3/repos/#list-user-repositories
*
* @param string $username the username
* @param string $type role in the repository
* @param string $sort sort by
* @param string $direction direction of sort, asc or desc
* @param string $visibility visibility of repository
* @param string $affiliation relationship to repository
*
* @return array list of the user repositories
*/
public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = 'all', $affiliation = 'owner,collaborator,organization_member')
{
return $this->get('/users/'.rawurlencode($username).'/repos', [
'type' => $type,
'sort' => $sort,
'direction' => $direction,
'visibility' => $visibility,
'affiliation' => $affiliation,
]);
}
/**
* List repositories that are accessible to the authenticated user.
*
* @link https://developer.github.com/v3/repos/#list-your-repositories
*
* @param array $params visibility, affiliation, type, sort, direction
*
* @return array list of the user repositories
*/
public function myRepositories(array $params = [])
{
return $this->get('/user/repos', $params);
}
/**
* Get the public gists for a user.
*
* @link http://developer.github.com/v3/gists/
*
* @param string $username the username
*
* @return array list of the user gists
*/
public function gists($username)
{
return $this->get('/users/'.rawurlencode($username).'/gists');
}
/**
* Get the public keys for a user.
*
* @link http://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
*
* @param string $username the username
*
* @return array list of the user public keys
*/
public function keys($username)
{
return $this->get('/users/'.rawurlencode($username).'/keys');
}
/**
* List events performed by a user.
*
* @link http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user
*
* @param string $username
*
* @return array
*/
public function publicEvents($username)
{
return $this->get('/users/'.rawurlencode($username).'/events/public');
}
}