mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-11-14 20:02:40 +09:00
Update to laravel 7
This commit is contained in:
221
vendor/knplabs/github-api/lib/Github/Client.php
vendored
221
vendor/knplabs/github-api/lib/Github/Client.php
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Github;
|
||||
|
||||
use Github\Api\ApiInterface;
|
||||
use Github\Api\AbstractApi;
|
||||
use Github\Exception\BadMethodCallException;
|
||||
use Github\Exception\InvalidArgumentException;
|
||||
use Github\HttpClient\Builder;
|
||||
@@ -10,58 +10,58 @@ use Github\HttpClient\Plugin\Authentication;
|
||||
use Github\HttpClient\Plugin\GithubExceptionThrower;
|
||||
use Github\HttpClient\Plugin\History;
|
||||
use Github\HttpClient\Plugin\PathPrepend;
|
||||
use Http\Client\Common\HttpMethodsClient;
|
||||
use Http\Client\Common\HttpMethodsClientInterface;
|
||||
use Http\Client\Common\Plugin;
|
||||
use Http\Client\HttpClient;
|
||||
use Http\Discovery\UriFactoryDiscovery;
|
||||
use Http\Discovery\Psr17FactoryDiscovery;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Simple yet very cool PHP GitHub client.
|
||||
*
|
||||
* @method Api\CurrentUser currentUser()
|
||||
* @method Api\CurrentUser me()
|
||||
* @method Api\Enterprise ent()
|
||||
* @method Api\Enterprise enterprise()
|
||||
* @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
|
||||
* @method Api\Miscellaneous\Emojis emojis()
|
||||
* @method Api\Miscellaneous\Licenses licenses()
|
||||
* @method Api\GitData git()
|
||||
* @method Api\GitData gitData()
|
||||
* @method Api\Gists gist()
|
||||
* @method Api\Gists gists()
|
||||
* @method Api\Miscellaneous\Gitignore gitignore()
|
||||
* @method Api\Integrations integration() (deprecated)
|
||||
* @method Api\Integrations integrations() (deprecated)
|
||||
* @method Api\Apps apps()
|
||||
* @method Api\Issue issue()
|
||||
* @method Api\Issue issues()
|
||||
* @method Api\Markdown markdown()
|
||||
* @method Api\Notification notification()
|
||||
* @method Api\Notification notifications()
|
||||
* @method Api\Organization organization()
|
||||
* @method Api\Organization organizations()
|
||||
* @method Api\Organization\Projects orgProject()
|
||||
* @method Api\Organization\Projects orgProjects()
|
||||
* @method Api\Organization\Projects organizationProject()
|
||||
* @method Api\Organization\Projects organizationProjects()
|
||||
* @method Api\PullRequest pr()
|
||||
* @method Api\PullRequest pullRequest()
|
||||
* @method Api\PullRequest pullRequests()
|
||||
* @method Api\RateLimit rateLimit()
|
||||
* @method Api\Repo repo()
|
||||
* @method Api\Repo repos()
|
||||
* @method Api\Repo repository()
|
||||
* @method Api\Repo repositories()
|
||||
* @method Api\Search search()
|
||||
* @method Api\Organization\Teams team()
|
||||
* @method Api\Organization\Teams teams()
|
||||
* @method Api\User user()
|
||||
* @method Api\User users()
|
||||
* @method Api\Authorizations authorization()
|
||||
* @method Api\Authorizations authorizations()
|
||||
* @method Api\Meta meta()
|
||||
* @method Api\GraphQL graphql()
|
||||
* @method Api\CurrentUser currentUser()
|
||||
* @method Api\CurrentUser me()
|
||||
* @method Api\Enterprise ent()
|
||||
* @method Api\Enterprise enterprise()
|
||||
* @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
|
||||
* @method Api\Miscellaneous\Emojis emojis()
|
||||
* @method Api\Miscellaneous\Licenses licenses()
|
||||
* @method Api\GitData git()
|
||||
* @method Api\GitData gitData()
|
||||
* @method Api\Gists gist()
|
||||
* @method Api\Gists gists()
|
||||
* @method Api\Miscellaneous\Gitignore gitignore()
|
||||
* @method Api\Apps apps()
|
||||
* @method Api\Issue issue()
|
||||
* @method Api\Issue issues()
|
||||
* @method Api\Markdown markdown()
|
||||
* @method Api\Notification notification()
|
||||
* @method Api\Notification notifications()
|
||||
* @method Api\Organization organization()
|
||||
* @method Api\Organization organizations()
|
||||
* @method Api\Organization\Projects orgProject()
|
||||
* @method Api\Organization\Projects orgProjects()
|
||||
* @method Api\Organization\Projects organizationProject()
|
||||
* @method Api\Organization\Projects organizationProjects()
|
||||
* @method Api\Organization\OutsideCollaborators outsideCollaborators()
|
||||
* @method Api\PullRequest pr()
|
||||
* @method Api\PullRequest pullRequest()
|
||||
* @method Api\PullRequest pullRequests()
|
||||
* @method Api\RateLimit rateLimit()
|
||||
* @method Api\Repo repo()
|
||||
* @method Api\Repo repos()
|
||||
* @method Api\Repo repository()
|
||||
* @method Api\Repo repositories()
|
||||
* @method Api\Search search()
|
||||
* @method Api\Organization\Teams team()
|
||||
* @method Api\Organization\Teams teams()
|
||||
* @method Api\User user()
|
||||
* @method Api\User users()
|
||||
* @method Api\Authorizations authorization()
|
||||
* @method Api\Authorizations authorizations()
|
||||
* @method Api\Meta meta()
|
||||
* @method Api\GraphQL graphql()
|
||||
*
|
||||
* @author Joseph Bielawski <stloyd@gmail.com>
|
||||
*
|
||||
@@ -70,34 +70,34 @@ use Psr\Cache\CacheItemPoolInterface;
|
||||
class Client
|
||||
{
|
||||
/**
|
||||
* Constant for authentication method. Indicates the default, but deprecated
|
||||
* login with username and token in URL.
|
||||
* Authenticate using a client_id/client_secret combination.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @deprecated Use the AuthMethod const
|
||||
*/
|
||||
const AUTH_URL_TOKEN = 'url_token';
|
||||
const AUTH_CLIENT_ID = AuthMethod::CLIENT_ID;
|
||||
|
||||
/**
|
||||
* Constant for authentication method. Not indicates the new login, but allows
|
||||
* usage of unauthenticated rate limited requests for given client_id + client_secret.
|
||||
* Authenticate using a GitHub access token.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @deprecated Use the AuthMethod const
|
||||
*/
|
||||
const AUTH_URL_CLIENT_ID = 'url_client_id';
|
||||
const AUTH_ACCESS_TOKEN = AuthMethod::ACCESS_TOKEN;
|
||||
|
||||
/**
|
||||
* Constant for authentication method. Indicates the new favored login method
|
||||
* with username and password via HTTP Authentication.
|
||||
* Constant for authentication method.
|
||||
*
|
||||
* Indicates JSON Web Token authentication required for GitHub apps access
|
||||
* to the API.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @deprecated Use the AuthMethod const
|
||||
*/
|
||||
const AUTH_HTTP_PASSWORD = 'http_password';
|
||||
|
||||
/**
|
||||
* Constant for authentication method. Indicates the new login method with
|
||||
* with username and token via HTTP Authentication.
|
||||
*/
|
||||
const AUTH_HTTP_TOKEN = 'http_token';
|
||||
|
||||
/**
|
||||
* Constant for authentication method. Indicates JSON Web Token
|
||||
* authentication required for integration access to the API.
|
||||
*/
|
||||
const AUTH_JWT = 'jwt';
|
||||
const AUTH_JWT = AuthMethod::JWT;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -124,32 +124,31 @@ class Client
|
||||
public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null)
|
||||
{
|
||||
$this->responseHistory = new History();
|
||||
$this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder();
|
||||
$this->httpClientBuilder = $builder = $httpClientBuilder ?? new Builder();
|
||||
$this->apiVersion = $apiVersion ?: 'v3';
|
||||
|
||||
$builder->addPlugin(new GithubExceptionThrower());
|
||||
$builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory));
|
||||
$builder->addPlugin(new Plugin\RedirectPlugin());
|
||||
$builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com')));
|
||||
$builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri('https://api.github.com')));
|
||||
$builder->addPlugin(new Plugin\HeaderDefaultsPlugin([
|
||||
'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)',
|
||||
'Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion),
|
||||
]));
|
||||
|
||||
$this->apiVersion = $apiVersion ?: 'v3';
|
||||
$builder->addHeaderValue('Accept', sprintf('application/vnd.github.%s+json', $this->apiVersion));
|
||||
|
||||
if ($enterpriseUrl) {
|
||||
$this->setEnterpriseUrl($enterpriseUrl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Github\Client using a HttpClient.
|
||||
* Create a Github\Client using a HTTP client.
|
||||
*
|
||||
* @param HttpClient $httpClient
|
||||
* @param ClientInterface $httpClient
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
public static function createWithHttpClient(HttpClient $httpClient)
|
||||
public static function createWithHttpClient(ClientInterface $httpClient): self
|
||||
{
|
||||
$builder = new Builder($httpClient);
|
||||
|
||||
@@ -161,9 +160,9 @@ class Client
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*
|
||||
* @return ApiInterface
|
||||
* @return AbstractApi
|
||||
*/
|
||||
public function api($name)
|
||||
public function api($name): AbstractApi
|
||||
{
|
||||
switch ($name) {
|
||||
case 'me':
|
||||
@@ -204,11 +203,6 @@ class Client
|
||||
$api = new Api\Miscellaneous\Gitignore($this);
|
||||
break;
|
||||
|
||||
case 'integration':
|
||||
case 'integrations':
|
||||
$api = new Api\Integrations($this);
|
||||
break;
|
||||
|
||||
case 'apps':
|
||||
$api = new Api\Apps($this);
|
||||
break;
|
||||
@@ -300,6 +294,11 @@ class Client
|
||||
$api = new Api\GraphQL($this);
|
||||
break;
|
||||
|
||||
case 'outsideCollaborators':
|
||||
case 'outside_collaborators':
|
||||
$api = new Api\Organization\OutsideCollaborators($this);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name));
|
||||
}
|
||||
@@ -311,24 +310,22 @@ class Client
|
||||
* Authenticate a user for all next requests.
|
||||
*
|
||||
* @param string $tokenOrLogin GitHub private token/username/client ID
|
||||
* @param null|string $password GitHub password/secret (optionally can contain $authMethod)
|
||||
* @param null|string $authMethod One of the AUTH_* class constants
|
||||
* @param string|null $password GitHub password/secret (optionally can contain $authMethod)
|
||||
* @param string|null $authMethod One of the AUTH_* class constants
|
||||
*
|
||||
* @throws InvalidArgumentException If no authentication method was given
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authenticate($tokenOrLogin, $password = null, $authMethod = null)
|
||||
public function authenticate($tokenOrLogin, $password = null, $authMethod = null): void
|
||||
{
|
||||
if (null === $password && null === $authMethod) {
|
||||
throw new InvalidArgumentException('You need to specify authentication method!');
|
||||
}
|
||||
|
||||
if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT], true)) {
|
||||
if (null === $authMethod && (AuthMethod::JWT === $password || AuthMethod::ACCESS_TOKEN === $password)) {
|
||||
$authMethod = $password;
|
||||
$password = null;
|
||||
}
|
||||
|
||||
if (null === $authMethod) {
|
||||
$authMethod = self::AUTH_HTTP_PASSWORD;
|
||||
throw new InvalidArgumentException('You need to specify authentication method!');
|
||||
}
|
||||
|
||||
$this->getHttpClientBuilder()->removePlugin(Authentication::class);
|
||||
@@ -339,21 +336,30 @@ class Client
|
||||
* Sets the URL of your GitHub Enterprise instance.
|
||||
*
|
||||
* @param string $enterpriseUrl URL of the API in the form of http(s)://hostname
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setEnterpriseUrl($enterpriseUrl)
|
||||
private function setEnterpriseUrl($enterpriseUrl): void
|
||||
{
|
||||
$builder = $this->getHttpClientBuilder();
|
||||
$builder->removePlugin(Plugin\AddHostPlugin::class);
|
||||
$builder->removePlugin(PathPrepend::class);
|
||||
|
||||
$builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl)));
|
||||
$builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion())));
|
||||
$builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri($enterpriseUrl)));
|
||||
|
||||
// For GHE, v4 API endpoint is at `api/graphql` so we don't want to add the version number
|
||||
// For earlier versions add the version number after /api
|
||||
if ($this->getApiVersion() === 'v4') {
|
||||
$builder->addPlugin(new PathPrepend('/api'));
|
||||
} else {
|
||||
$builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion())));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApiVersion()
|
||||
public function getApiVersion(): string
|
||||
{
|
||||
return $this->apiVersion;
|
||||
}
|
||||
@@ -363,28 +369,31 @@ class Client
|
||||
*
|
||||
* @param CacheItemPoolInterface $cachePool
|
||||
* @param array $config
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
|
||||
public function addCache(CacheItemPoolInterface $cachePool, array $config = []): void
|
||||
{
|
||||
$this->getHttpClientBuilder()->addCache($cachePool, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache plugin.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeCache()
|
||||
public function removeCache(): void
|
||||
{
|
||||
$this->getHttpClientBuilder()->removeCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*
|
||||
* @throws BadMethodCallException
|
||||
*
|
||||
* @return ApiInterface
|
||||
* @return AbstractApi
|
||||
*/
|
||||
public function __call($name, $args)
|
||||
public function __call($name, $args): AbstractApi
|
||||
{
|
||||
try {
|
||||
return $this->api($name);
|
||||
@@ -396,15 +405,15 @@ class Client
|
||||
/**
|
||||
* @return null|\Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
public function getLastResponse()
|
||||
public function getLastResponse(): ?ResponseInterface
|
||||
{
|
||||
return $this->responseHistory->getLastResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HttpMethodsClient
|
||||
* @return HttpMethodsClientInterface
|
||||
*/
|
||||
public function getHttpClient()
|
||||
public function getHttpClient(): HttpMethodsClientInterface
|
||||
{
|
||||
return $this->getHttpClientBuilder()->getHttpClient();
|
||||
}
|
||||
@@ -412,7 +421,7 @@ class Client
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
protected function getHttpClientBuilder()
|
||||
protected function getHttpClientBuilder(): Builder
|
||||
{
|
||||
return $this->httpClientBuilder;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user