/** * Create a new instance of GitlabClient. * @param array $config * @return GitlabGuzzleClient */ public static function createClient($config = []) { $default = ['ssl.certificate_authority' => 'system']; $required = ['base_url', 'api_token']; $config = Collection::fromConfig($config, $default, $required); $config['base_url'] = self::completeBaseUrl($config['base_url']); $serviceDescriptionFilePath = __DIR__ . '/ServiceDescription/service_description.yml'; $definition = self::loadServiceDefinition($serviceDescriptionFilePath); self::emulateGuzzle3ResponseModels($definition); $description = new Description($definition); $client = new Client($config->toArray()); $client->setDefaultOption('headers/accept', 'application/json'); $privateTokenPlugin = new PrivateTokenPlugin($config['api_token']); $client->getEmitter()->attach($privateTokenPlugin); $gitlabClient = new GitlabGuzzleClient($client, $description); $gitlabClient->getEmitter()->attach(new ResponseClassProcessor($description)); return $gitlabClient; }
public function testGuzzleServicesIssue70() { $client = GitlabGuzzleClient::factory(['base_url' => 'https://example.com/gitlab/api/v3', 'api_token' => 'QVy1PB7sTxfy4pqfZM1U']); $fixturePath = __DIR__ . '/fixtures/issues/list_issues.http'; $mock = new Mock([$fixturePath]); $client->getHttpClient()->getEmitter()->attach($mock); $result = $client->listIssues([]); $this->assertNotEmpty($result); }
public function testGetMergeRequestComments() { $expectedResult = new CommentCollection(); $expectedResult[] = new Comment('Foo'); $expectedResult[] = new Comment('Bar'); $this->guzzle->shouldReceive('getMergeRequestComments')->once()->with(Mockery::on(function ($params) { $this->assertEquals(['project_id' => 'fgrosse/example', 'merge_request_id' => 42], $params); return true; }))->andReturn($expectedResult); $actualResult = $this->client->getMergeRequestComments('fgrosse/example', 42); $this->assertEquals($expectedResult, $actualResult); }
#!/bin/php <?php /* * This file is part of fgrosse/gitlab-api. * * Copyright © Friedrich Große <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Gitlab\Client\GitlabGuzzleClient; use Gitlab\Client\HttpGitlabClient; include __DIR__ . '/../vendor/autoload.php'; include __DIR__ . '/cli_helper.php'; $baseUrl = getParameter('base-url', $argv); $token = getParameter('token', $argv); $project = getParameter('project', $argv); try { $guzzleClient = GitlabGuzzleClient::factory(['base_url' => $baseUrl, 'api_token' => $token]); $client = new HttpGitlabClient($guzzleClient); $mergeRequests = $client->listMergeRequests($project, $state = 'closed', $order = 'updated_at', $sort = 'asc', $page = 1, $perPage = 5); foreach ($mergeRequests as $mergeRequest) { echo $mergeRequest . PHP_EOL; } } catch (Exception $exception) { printError('An Exception of type ' . get_class($exception) . ' occurred:'); printError($exception->getMessage()); exit(1); }
protected function setMockResponse($path) { $mock = new ResponseMock([$path]); $this->client->getHttpClient()->getEmitter()->attach($mock); }