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,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));
}
}