Skip to content

Commit

Permalink
Bump bitbucket/client from 2.1.5 to 4.0.0 (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas authored Feb 1, 2021
1 parent 950e44b commit 8ba7299
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 47 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ext-json": "*",
"ext-pdo_pgsql": "*",
"ext-zip": "*",
"bitbucket/client": "^2.1",
"bitbucket/client": "^4.0",
"buddy-works/buddy-works-php-api": "^1.3",
"buddy-works/oauth2-client": "^1.0",
"cbschuld/browser.php": "^1.9",
Expand Down
42 changes: 23 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ services:
- '@?Http\Message\RequestFactory'
- '@?Http\Message\StreamFactory'

Bitbucket\ResultPager:
Bitbucket\ResultPagerInterface:
class: Bitbucket\ResultPager
arguments:
- '@Bitbucket\Client'

Expand Down
14 changes: 7 additions & 7 deletions src/Service/Integration/BitbucketApi/RestBitbucketApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Buddy\Repman\Service\Integration\BitbucketApi;

use Bitbucket\Client;
use Bitbucket\ResultPager;
use Bitbucket\ResultPagerInterface;
use Buddy\Repman\Service\Integration\BitbucketApi;

final class RestBitbucketApi implements BitbucketApi
{
private Client $client;
private ResultPager $pager;
private ResultPagerInterface $pager;

public function __construct(Client $client, ResultPager $pager)
public function __construct(Client $client, ResultPagerInterface $pager)
{
$this->client = $client;
$this->pager = $pager;
Expand Down Expand Up @@ -47,8 +47,8 @@ public function repositories(string $accessToken): Repositories
public function addHook(string $accessToken, string $fullName, string $hookUrl): void
{
$this->client->authenticate(Client::AUTH_OAUTH_TOKEN, $accessToken);
[$username, $repo] = explode('/', $fullName);
$hooks = $this->client->repositories()->users($username)->hooks($repo);
[$workspace, $repo] = explode('/', $fullName);
$hooks = $this->client->repositories()->workspaces($workspace)->hooks($repo);

foreach ($this->pager->fetchAll($hooks, 'list') as $hook) {
if ($hook['url'] === $hookUrl) {
Expand All @@ -67,9 +67,9 @@ public function addHook(string $accessToken, string $fullName, string $hookUrl):
public function removeHook(string $accessToken, string $fullName, string $hookUrl): void
{
$this->client->authenticate(Client::AUTH_OAUTH_TOKEN, $accessToken);
[$username, $repo] = explode('/', $fullName);
[$workspace, $repo] = explode('/', $fullName);

$hooks = $this->client->repositories()->users($username)->hooks($repo);
$hooks = $this->client->repositories()->workspaces($workspace)->hooks($repo);

foreach ($this->pager->fetchAll($hooks, 'list') as $hook) {
if ($hook['url'] === $hookUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Bitbucket\Api\CurrentUser;
use Bitbucket\Api\Repositories as RepositoriesApi;
use Bitbucket\Client;
use Bitbucket\ResultPager;
use Bitbucket\ResultPagerInterface;
use Buddy\Repman\Service\Integration\BitbucketApi\Repositories;
use Buddy\Repman\Service\Integration\BitbucketApi\Repository;
use Buddy\Repman\Service\Integration\BitbucketApi\RestBitbucketApi;
Expand All @@ -22,7 +22,7 @@ final class RestBitbucketApiTest extends TestCase
private $clientMock;

/**
* @var MockObject|ResultPager
* @var MockObject|ResultPagerInterface
*/
private $pagerMock;

Expand All @@ -32,7 +32,7 @@ protected function setUp(): void
{
$this->clientMock = $this->createMock(Client::class);
$this->clientMock->expects(self::once())->method('authenticate');
$this->pagerMock = $this->createMock(ResultPager::class);
$this->pagerMock = $this->createMock(ResultPagerInterface::class);

$this->api = new RestBitbucketApi($this->clientMock, $this->pagerMock);
}
Expand Down Expand Up @@ -101,14 +101,14 @@ public function testFetchRepositories(): void
public function testAddHookWhenNotExist(): void
{
$repos = $this->createMock(RepositoriesApi::class);
$users = $this->createMock(RepositoriesApi\Users::class);
$hooks = $this->createMock(RepositoriesApi\Users\Hooks::class);
$workspaces = $this->createMock(RepositoriesApi\Workspaces::class);
$hooks = $this->createMock(RepositoriesApi\Workspaces\Hooks::class);
$this->pagerMock->method('fetchAll')->willReturn([
['url' => 'https://bitbucket-pipelines.prod.public.atl-paas.net/rest/bitbucket/event/connect/onpush'],
]);
$this->clientMock->method('repositories')->willReturn($repos);
$repos->method('users')->willReturn($users);
$users->method('hooks')->willReturn($hooks);
$repos->method('workspaces')->willReturn($workspaces);
$workspaces->method('hooks')->willReturn($hooks);

$hooks->expects(self::once())->method('create');

Expand All @@ -118,15 +118,15 @@ public function testAddHookWhenNotExist(): void
public function testDoNotAddHookWhenExist(): void
{
$repos = $this->createMock(RepositoriesApi::class);
$users = $this->createMock(RepositoriesApi\Users::class);
$hooks = $this->createMock(RepositoriesApi\Users\Hooks::class);
$workspaces = $this->createMock(RepositoriesApi\Workspaces::class);
$hooks = $this->createMock(RepositoriesApi\Workspaces\Hooks::class);
$this->pagerMock->method('fetchAll')->willReturn([
['url' => 'https://bitbucket-pipelines.prod.public.atl-paas.net/rest/bitbucket/event/connect/onpush'],
['url' => 'https://webhook.url'],
]);
$this->clientMock->method('repositories')->willReturn($repos);
$repos->method('users')->willReturn($users);
$users->method('hooks')->willReturn($hooks);
$repos->method('workspaces')->willReturn($workspaces);
$workspaces->method('hooks')->willReturn($hooks);

$hooks->expects(self::never())->method('create');

Expand All @@ -136,17 +136,17 @@ public function testDoNotAddHookWhenExist(): void
public function testRemoveHookWhenExist(): void
{
$repos = $this->createMock(RepositoriesApi::class);
$users = $this->createMock(RepositoriesApi\Users::class);
$hooks = $this->createMock(RepositoriesApi\Users\Hooks::class);
$workspaces = $this->createMock(RepositoriesApi\Workspaces::class);
$hooks = $this->createMock(RepositoriesApi\Workspaces\Hooks::class);
$this->pagerMock->method('fetchAll')->willReturn([
[
'uuid' => '1d2c6ec8-1294-4471-b703-1d050f86bdd5',
'url' => 'https://webhook.url',
],
]);
$this->clientMock->method('repositories')->willReturn($repos);
$repos->method('users')->willReturn($users);
$users->method('hooks')->willReturn($hooks);
$repos->method('workspaces')->willReturn($workspaces);
$workspaces->method('hooks')->willReturn($hooks);

$hooks->expects(self::once())->method('remove')->with('1d2c6ec8-1294-4471-b703-1d050f86bdd5');

Expand All @@ -156,17 +156,17 @@ public function testRemoveHookWhenExist(): void
public function testRemoveHookWhenNotExist(): void
{
$repos = $this->createMock(RepositoriesApi::class);
$users = $this->createMock(RepositoriesApi\Users::class);
$hooks = $this->createMock(RepositoriesApi\Users\Hooks::class);
$workspaces = $this->createMock(RepositoriesApi\Workspaces::class);
$hooks = $this->createMock(RepositoriesApi\Workspaces\Hooks::class);
$this->pagerMock->method('fetchAll')->willReturn([
[
'uuid' => '1d2c6ec8-1294-4471-b703-1d050f86bdd5',
'url' => 'https://other.url',
],
]);
$this->clientMock->method('repositories')->willReturn($repos);
$repos->method('users')->willReturn($users);
$users->method('hooks')->willReturn($hooks);
$repos->method('workspaces')->willReturn($workspaces);
$workspaces->method('hooks')->willReturn($hooks);

$hooks->expects(self::never())->method('remove');

Expand Down

0 comments on commit 8ba7299

Please sign in to comment.