├── LICENSE ├── composer.json └── src ├── Api ├── AbstractApi.php ├── Addon.php ├── Addon │ ├── AbstractAddonApi.php │ ├── Linkers.php │ ├── Linkers │ │ ├── AbstractLinkersApi.php │ │ └── Values.php │ ├── Users.php │ └── Users │ │ ├── AbstractUsersApi.php │ │ └── Events.php ├── CurrentUser.php ├── HookEvents.php ├── PullRequests.php ├── Repositories.php ├── Repositories │ ├── AbstractRepositoriesApi.php │ ├── Workspaces.php │ └── Workspaces │ │ ├── AbstractWorkspacesApi.php │ │ ├── BranchRestrictions.php │ │ ├── BranchingModel.php │ │ ├── Commit.php │ │ ├── Commit │ │ ├── AbstractCommitApi.php │ │ ├── Approval.php │ │ ├── Comments.php │ │ ├── Properties.php │ │ ├── PullRequests.php │ │ ├── Reports.php │ │ ├── Reports │ │ │ ├── AbstractReportsApi.php │ │ │ └── Annotations.php │ │ ├── Statuses.php │ │ └── Statuses │ │ │ ├── AbstractStatusesApi.php │ │ │ └── Build.php │ │ ├── Commits.php │ │ ├── Components.php │ │ ├── DefaultReviewers.php │ │ ├── DeployKeys.php │ │ ├── Deployments.php │ │ ├── Deployments │ │ ├── AbstractDeploymentsApi.php │ │ └── EnvironmentVariables.php │ │ ├── DiffStat.php │ │ ├── Diffs.php │ │ ├── Downloads.php │ │ ├── Environments.php │ │ ├── FileHistory.php │ │ ├── Forks.php │ │ ├── Hooks.php │ │ ├── Issues.php │ │ ├── Issues │ │ ├── AbstractIssuesApi.php │ │ ├── Attachments.php │ │ ├── Changes.php │ │ ├── Comments.php │ │ ├── Voting.php │ │ └── Watching.php │ │ ├── MergeBases.php │ │ ├── Milestones.php │ │ ├── Patches.php │ │ ├── Pipelines.php │ │ ├── Pipelines │ │ ├── AbstractPipelinesApi.php │ │ ├── RemoteTriggers.php │ │ └── Steps.php │ │ ├── PipelinesConfig.php │ │ ├── PipelinesConfig │ │ ├── AbstractPipelinesConfigApi.php │ │ ├── BuildNumber.php │ │ ├── Schedules.php │ │ ├── Schedules │ │ │ ├── AbstractSchedulesApi.php │ │ │ └── Executions.php │ │ ├── Ssh.php │ │ ├── Ssh │ │ │ ├── AbstractSshApi.php │ │ │ ├── KeyPair.php │ │ │ └── KnownHosts.php │ │ └── Variables.php │ │ ├── Properties.php │ │ ├── PullRequests.php │ │ ├── PullRequests │ │ ├── AbstractPullRequestsApi.php │ │ ├── Approval.php │ │ ├── Comments.php │ │ ├── Commits.php │ │ ├── Diff.php │ │ ├── DiffStat.php │ │ ├── Patch.php │ │ ├── Properties.php │ │ └── Statuses.php │ │ ├── Refs.php │ │ ├── Refs │ │ ├── AbstractRefsApi.php │ │ ├── Branches.php │ │ └── Tags.php │ │ ├── Src.php │ │ ├── Versions.php │ │ └── Watchers.php ├── Snippets.php ├── Snippets │ ├── AbstractSnippetsApi.php │ ├── Workspaces.php │ └── Workspaces │ │ ├── AbstractWorkspacesApi.php │ │ ├── Comments.php │ │ ├── Commits.php │ │ ├── Diffs.php │ │ ├── Files.php │ │ ├── Patches.php │ │ ├── Watchers.php │ │ └── Watching.php ├── Users.php ├── Users │ ├── AbstractUsersApi.php │ ├── Properties.php │ ├── Repositories.php │ └── SshKeys.php ├── Workspaces.php └── Workspaces │ ├── AbstractWorkspacesApi.php │ ├── Hooks.php │ ├── Members.php │ ├── Permissions.php │ ├── Permissions │ ├── AbstractPermissionsApi.php │ └── Repositories.php │ ├── PipelinesConfig.php │ ├── PipelinesConfig │ ├── AbstractPipelinesConfigApi.php │ └── Variables.php │ └── Projects.php ├── Client.php ├── Exception ├── ApiLimitExceededException.php ├── ErrorException.php ├── ExceptionInterface.php ├── RuntimeException.php └── ValidationFailedException.php ├── HttpClient ├── Builder.php ├── Message │ ├── FileResource.php │ └── ResponseMediator.php ├── Plugin │ ├── Authentication.php │ ├── ExceptionThrower.php │ └── History.php └── Util │ ├── JsonArray.php │ ├── QueryStringBuilder.php │ └── UriBuilder.php ├── ResultPager.php └── ResultPagerInterface.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018-2025 Graham Campbell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bitbucket/client", 3 | "description": "Bitbucket API 2.0 client for PHP", 4 | "keywords": ["bitbucket", "bitbucket api", "Bitbucket API", "BitbucketAPI", "Bitbucket", "Bitbucket Client", "Bitbucket API Client", "Graham Campbell", "GrahamCampbell"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Graham Campbell", 9 | "email": "hello@gjcampbell.co.uk", 10 | "homepage": "https://github.com/GrahamCampbell" 11 | } 12 | ], 13 | "require": { 14 | "php": "^8.1", 15 | "ext-json": "*", 16 | "php-http/cache-plugin": "^2.0.1", 17 | "php-http/client-common": "^2.7.2", 18 | "php-http/discovery": "^1.20.0", 19 | "php-http/httplug": "^2.4.1", 20 | "php-http/multipart-stream-builder": "^1.4.2", 21 | "psr/cache": "^2.0 || ^3.0", 22 | "psr/http-client-implementation": "^1.0", 23 | "psr/http-factory-implementation": "^1.0", 24 | "psr/http-message": "^1.1 || ^2.0" 25 | }, 26 | "require-dev": { 27 | "bamarni/composer-bin-plugin": "^1.8.2", 28 | "guzzlehttp/guzzle": "^7.9.2", 29 | "php-http/mock-client": "^1.6.1" 30 | }, 31 | "autoload": { 32 | "psr-4": { 33 | "Bitbucket\\": "src/" 34 | } 35 | }, 36 | "autoload-dev": { 37 | "psr-4": { 38 | "Bitbucket\\Tests\\": "tests/" 39 | } 40 | }, 41 | "config": { 42 | "preferred-install": "dist", 43 | "allow-plugins": { 44 | "bamarni/composer-bin-plugin": true, 45 | "php-http/discovery": true 46 | } 47 | }, 48 | "extra": { 49 | "bamarni-bin": { 50 | "bin-links": true, 51 | "forward-command": false 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Api/Addon.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api; 15 | 16 | use Bitbucket\Api\Addon\Linkers; 17 | use Bitbucket\Api\Addon\Users as UsersAddon; 18 | use Bitbucket\HttpClient\Util\UriBuilder; 19 | 20 | /** 21 | * The addon API class. 22 | * 23 | * @author Graham Campbell 24 | */ 25 | class Addon extends AbstractApi 26 | { 27 | /** 28 | * @throws \Http\Client\Exception 29 | */ 30 | public function update(array $params = []): array 31 | { 32 | $uri = $this->buildAddonUri(); 33 | 34 | return $this->put($uri, $params); 35 | } 36 | 37 | /** 38 | * @throws \Http\Client\Exception 39 | */ 40 | public function remove(array $params = []): array 41 | { 42 | $uri = $this->buildAddonUri(); 43 | 44 | return $this->delete($uri, $params); 45 | } 46 | 47 | public function linkers(): Linkers 48 | { 49 | return new Linkers($this->getClient()); 50 | } 51 | 52 | public function users(): UsersAddon 53 | { 54 | return new UsersAddon($this->getClient()); 55 | } 56 | 57 | /** 58 | * Build the addon URI from the given parts. 59 | */ 60 | protected function buildAddonUri(string ...$parts): string 61 | { 62 | return UriBuilder::build('addon', ...$parts); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Api/Addon/AbstractAddonApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Addon; 15 | 16 | use Bitbucket\Api\AbstractApi; 17 | 18 | /** 19 | * The abstract addon API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | abstract class AbstractAddonApi extends AbstractApi 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/Addon/Linkers.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Addon; 15 | 16 | use Bitbucket\Api\Addon\Linkers\Values; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | 19 | /** 20 | * The linkers API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | class Linkers extends AbstractAddonApi 25 | { 26 | /** 27 | * @throws \Http\Client\Exception 28 | */ 29 | public function list(array $params = []): array 30 | { 31 | $uri = $this->buildLinkersUri(); 32 | 33 | return $this->get($uri, $params); 34 | } 35 | 36 | /** 37 | * @throws \Http\Client\Exception 38 | */ 39 | public function show(string $linker, array $params = []): array 40 | { 41 | $uri = $this->buildLinkersUri($linker); 42 | 43 | return $this->get($uri, $params); 44 | } 45 | 46 | public function values(string $linker): Values 47 | { 48 | return new Values($this->getClient(), $linker); 49 | } 50 | 51 | /** 52 | * Build the linkers URI from the given parts. 53 | */ 54 | protected function buildLinkersUri(string ...$parts): string 55 | { 56 | return UriBuilder::build('addon', 'linkers', ...$parts); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Api/Addon/Linkers/AbstractLinkersApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Addon\Linkers; 15 | 16 | use Bitbucket\Api\Addon\AbstractAddonApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract linkers API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractLinkersApi extends AbstractAddonApi 25 | { 26 | protected readonly string $linker; 27 | 28 | public function __construct(Client $client, string $linker) 29 | { 30 | parent::__construct($client); 31 | $this->linker = $linker; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Addon/Linkers/Values.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Addon\Linkers; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The values API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Values extends AbstractLinkersApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildValuesUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = UriBuilder::appendSeparator($this->buildValuesUri()); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $id, array $params = []): array 49 | { 50 | $uri = $this->buildValuesUri($id); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $id, array $params = []): array 59 | { 60 | $uri = $this->buildValuesUri($id); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $id, array $params = []): array 69 | { 70 | $uri = $this->buildValuesUri($id); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the values URI from the given parts. 77 | */ 78 | protected function buildValuesUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('addon', 'linkers', $this->linker, 'values', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Addon/Users.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Addon; 15 | 16 | use Bitbucket\Api\Addon\Users\Events; 17 | 18 | /** 19 | * The users API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Users extends AbstractAddonApi 24 | { 25 | public function events(string $username): Events 26 | { 27 | return new Events($this->getClient(), $username); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Api/Addon/Users/AbstractUsersApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Addon\Users; 15 | 16 | use Bitbucket\Api\Addon\AbstractAddonApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract users API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractUsersApi extends AbstractAddonApi 25 | { 26 | protected readonly string $username; 27 | 28 | public function __construct(Client $client, string $username) 29 | { 30 | parent::__construct($client); 31 | $this->username = $username; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Addon/Users/Events.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Addon\Users; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The events API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Events extends AbstractUsersApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function create(string $event, array $params = []): array 29 | { 30 | $uri = $this->buildEventsUri($event); 31 | 32 | return $this->post($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the events URI from the given parts. 37 | */ 38 | protected function buildEventsUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('addon', 'users', $this->username, 'events', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/CurrentUser.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The current user API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class CurrentUser extends AbstractApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function show(array $params = []): array 29 | { 30 | $uri = $this->buildCurrentUserUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function listEmails(array $params = []): array 39 | { 40 | $uri = $this->buildCurrentUserUri('emails'); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function showEmail(string $email, array $params = []): array 49 | { 50 | $uri = $this->buildCurrentUserUri('emails', $email); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function listRepositoryPermissions(array $params = []): array 59 | { 60 | $uri = $this->buildCurrentUserUri('permissions', 'repositories'); 61 | 62 | return $this->get($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function listTeamPermissions(array $params = []): array 69 | { 70 | $uri = $this->buildCurrentUserUri('permissions', 'teams'); 71 | 72 | return $this->get($uri, $params); 73 | } 74 | 75 | /** 76 | * @throws \Http\Client\Exception 77 | */ 78 | public function listWorkspacePermissions(array $params = []): array 79 | { 80 | $uri = $this->buildCurrentUserUri('permissions', 'workspaces'); 81 | 82 | return $this->get($uri, $params); 83 | } 84 | 85 | /** 86 | * @throws \Http\Client\Exception 87 | */ 88 | public function listWorkspaces(array $params = []): array 89 | { 90 | $uri = UriBuilder::build('workspaces'); 91 | 92 | return $this->get($uri, $params); 93 | } 94 | 95 | /** 96 | * Build the current user URI from the given parts. 97 | */ 98 | protected function buildCurrentUserUri(string ...$parts): string 99 | { 100 | return UriBuilder::build('user', ...$parts); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Api/HookEvents.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The hook events API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class HookEvents extends AbstractApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function listUserEvents(array $params = []): array 29 | { 30 | $uri = $this->buildHookEventsUri('user'); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function listRepositoryEvents(array $params = []): array 39 | { 40 | $uri = $this->buildHookEventsUri('repository'); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function listTeamEvents(array $params = []): array 49 | { 50 | $uri = $this->buildHookEventsUri('team'); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function listWorkspaceEvents(array $params = []): array 59 | { 60 | $uri = $this->buildHookEventsUri('workspace'); 61 | 62 | return $this->get($uri, $params); 63 | } 64 | 65 | /** 66 | * Build the hook events URI from the given parts. 67 | */ 68 | protected function buildHookEventsUri(string ...$parts): string 69 | { 70 | return UriBuilder::build('hook_events', ...$parts); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Api/PullRequests.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The pull requests API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class PullRequests extends AbstractApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(string $username, array $params = []): array 29 | { 30 | $uri = $this->buildPullRequestsUri($username); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the pull requests URI from the given parts. 37 | */ 38 | protected function buildPullRequestsUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('pullrequests', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces as RepositoriesWorkspaces; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | 19 | /** 20 | * The repositories API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | class Repositories extends AbstractApi 25 | { 26 | /** 27 | * @throws \Http\Client\Exception 28 | */ 29 | public function list(array $params = []): array 30 | { 31 | $uri = $this->buildRepositoriesUri(); 32 | 33 | return $this->get($uri, $params); 34 | } 35 | 36 | public function workspaces(string $workspace): RepositoriesWorkspaces 37 | { 38 | return new RepositoriesWorkspaces($this->getClient(), $workspace); 39 | } 40 | 41 | /** 42 | * Build the repositories URI from the given parts. 43 | */ 44 | protected function buildRepositoriesUri(string ...$parts): string 45 | { 46 | return UriBuilder::build('repositories', ...$parts); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Api/Repositories/AbstractRepositoriesApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories; 15 | 16 | use Bitbucket\Api\AbstractApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract repository API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractRepositoriesApi extends AbstractApi 25 | { 26 | protected readonly string $workspace; 27 | 28 | public function __construct(Client $client, string $workspace) 29 | { 30 | parent::__construct($client); 31 | $this->workspace = $workspace; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/AbstractWorkspacesApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\Api\Repositories\AbstractRepositoriesApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract workspaces API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractWorkspacesApi extends AbstractRepositoriesApi 25 | { 26 | protected readonly string $repo; 27 | 28 | public function __construct(Client $client, string $workspace, string $repo) 29 | { 30 | parent::__construct($client, $workspace); 31 | $this->repo = $repo; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/BranchRestrictions.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The branch restrictions API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class BranchRestrictions extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildBranchRestrictionsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildBranchRestrictionsUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $restriction, array $params = []): array 49 | { 50 | $uri = $this->buildBranchRestrictionsUri($restriction); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $restriction, array $params = []): array 59 | { 60 | $uri = $this->buildBranchRestrictionsUri($restriction); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $restriction, array $params = []): array 69 | { 70 | $uri = $this->buildBranchRestrictionsUri($restriction); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the branch restrictions URI from the given parts. 77 | */ 78 | protected function buildBranchRestrictionsUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'branch-restrictions', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/BranchingModel.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The branching model API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class BranchingModel extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function show(array $params = []): array 29 | { 30 | $uri = $this->buildBranchingModelUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function showSettings(array $params = []): array 39 | { 40 | $uri = $this->buildBranchingModelUri('settings'); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function updateSettings(array $params = []): array 49 | { 50 | $uri = $this->buildBranchingModelUri('settings'); 51 | 52 | return $this->put($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the branching model URI from the given parts. 57 | */ 58 | protected function buildBranchingModelUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'branching-model', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\Commit\Approval; 17 | use Bitbucket\Api\Repositories\Workspaces\Commit\Comments; 18 | use Bitbucket\Api\Repositories\Workspaces\Commit\Properties as CommitProperties; 19 | use Bitbucket\Api\Repositories\Workspaces\Commit\PullRequests as CommitPullRequests; 20 | use Bitbucket\Api\Repositories\Workspaces\Commit\Reports; 21 | use Bitbucket\Api\Repositories\Workspaces\Commit\Statuses; 22 | use Bitbucket\HttpClient\Util\UriBuilder; 23 | 24 | /** 25 | * The commit API class. 26 | * 27 | * @author Graham Campbell 28 | */ 29 | class Commit extends AbstractWorkspacesApi 30 | { 31 | /** 32 | * @throws \Http\Client\Exception 33 | */ 34 | public function show(string $commit, array $params = []): array 35 | { 36 | $uri = $this->buildCommitUri($commit); 37 | 38 | return $this->get($uri, $params); 39 | } 40 | 41 | public function approval(string $commit): Approval 42 | { 43 | return new Approval($this->getClient(), $this->workspace, $this->repo, $commit); 44 | } 45 | 46 | public function comments(string $commit): Comments 47 | { 48 | return new Comments($this->getClient(), $this->workspace, $this->repo, $commit); 49 | } 50 | 51 | public function properties(string $commit): CommitProperties 52 | { 53 | return new CommitProperties($this->getClient(), $this->workspace, $this->repo, $commit); 54 | } 55 | 56 | public function pullRequests(string $commit): CommitPullRequests 57 | { 58 | return new CommitPullRequests($this->getClient(), $this->workspace, $this->repo, $commit); 59 | } 60 | 61 | public function reports(string $commit): Reports 62 | { 63 | return new Reports($this->getClient(), $this->workspace, $this->repo, $commit); 64 | } 65 | 66 | public function statuses(string $commit): Statuses 67 | { 68 | return new Statuses($this->getClient(), $this->workspace, $this->repo, $commit); 69 | } 70 | 71 | /** 72 | * Build the commit URI from the given parts. 73 | */ 74 | protected function buildCommitUri(string ...$parts): string 75 | { 76 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', ...$parts); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/AbstractCommitApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\AbstractWorkspacesApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract commit API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractCommitApi extends AbstractWorkspacesApi 25 | { 26 | protected readonly string $commit; 27 | 28 | public function __construct(Client $client, string $workspace, string $repo, string $commit) 29 | { 30 | parent::__construct($client, $workspace, $repo); 31 | $this->commit = $commit; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/Approval.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The approval API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Approval extends AbstractCommitApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function approve(array $params = []): array 29 | { 30 | $uri = $this->buildApprovalUri(); 31 | 32 | return $this->post($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function redact(array $params = []): array 39 | { 40 | $uri = $this->buildApprovalUri(); 41 | 42 | return $this->delete($uri, $params); 43 | } 44 | 45 | /** 46 | * Build the approval URI from the given parts. 47 | */ 48 | protected function buildApprovalUri(string ...$parts): string 49 | { 50 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', $this->commit, 'approve', ...$parts); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/Comments.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The comments API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Comments extends AbstractCommitApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildCommentsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildCommentsUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $comment, array $params = []): array 49 | { 50 | $uri = $this->buildCommentsUri($comment); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the comments URI from the given parts. 57 | */ 58 | protected function buildCommentsUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', $this->commit, 'comments', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/Properties.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The properties API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Properties extends AbstractCommitApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function show(string $app, string $property, array $params = []): array 29 | { 30 | $uri = $this->buildPropertiesUri($app, $property); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function update(string $app, string $property, array $params = []): array 39 | { 40 | $uri = $this->buildPropertiesUri($app, $property); 41 | 42 | return $this->put($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function remove(string $app, string $property, array $params = []): array 49 | { 50 | $uri = $this->buildPropertiesUri($app, $property); 51 | 52 | return $this->delete($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the properties URI from the given parts. 57 | */ 58 | protected function buildPropertiesUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', $this->commit, 'properties', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/PullRequests.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The pull requests API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class PullRequests extends AbstractCommitApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildPullRequestsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the pull requests URI from the given parts. 37 | */ 38 | protected function buildPullRequestsUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', $this->commit, 'pullrequests', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/Reports.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\Commit\Reports\Annotations; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | 19 | /** 20 | * The reports API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | class Reports extends AbstractCommitApi 25 | { 26 | /** 27 | * @throws \Http\Client\Exception 28 | */ 29 | public function list(array $params = []): array 30 | { 31 | $uri = $this->buildReportsUri(); 32 | 33 | return $this->get($uri, $params); 34 | } 35 | 36 | /** 37 | * @throws \Http\Client\Exception 38 | */ 39 | public function create(string $report, array $params = []): array 40 | { 41 | $uri = $this->buildReportsUri($report); 42 | 43 | return $this->put($uri, $params); 44 | } 45 | 46 | /** 47 | * @throws \Http\Client\Exception 48 | */ 49 | public function show(string $report, array $params = []): array 50 | { 51 | $uri = $this->buildReportsUri($report); 52 | 53 | return $this->get($uri, $params); 54 | } 55 | 56 | public function annotations(): Annotations 57 | { 58 | return new Annotations($this->getClient(), $this->workspace, $this->repo, $this->commit); 59 | } 60 | 61 | /** 62 | * Build the reports URI from the given parts. 63 | */ 64 | protected function buildReportsUri(string ...$parts): string 65 | { 66 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', $this->commit, 'reports', ...$parts); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/Reports/AbstractReportsApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit\Reports; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\Commit\AbstractCommitApi; 17 | 18 | /** 19 | * The abstract reports API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | abstract class AbstractReportsApi extends AbstractCommitApi 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/Reports/Annotations.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit\Reports; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The annotations API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Annotations extends AbstractReportsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildAnnotationsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildAnnotationsUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $annotation, array $params = []): array 49 | { 50 | $uri = $this->buildAnnotationsUri($annotation); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $annotation, array $params = []): array 59 | { 60 | $uri = $this->buildAnnotationsUri($annotation); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $annotation, array $params = []): array 69 | { 70 | $uri = $this->buildAnnotationsUri($annotation); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Annotations the build URI from the given parts. 77 | */ 78 | protected function buildAnnotationsUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', $this->commit, 'reports', 'annotations', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/Statuses.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\Commit\Statuses\Build; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | 19 | /** 20 | * The statuses API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | class Statuses extends AbstractCommitApi 25 | { 26 | /** 27 | * @throws \Http\Client\Exception 28 | */ 29 | public function list(array $params = []): array 30 | { 31 | $uri = $this->buildStatusesUri(); 32 | 33 | return $this->get($uri, $params); 34 | } 35 | 36 | public function build(): Build 37 | { 38 | return new Build($this->getClient(), $this->workspace, $this->repo, $this->commit); 39 | } 40 | 41 | /** 42 | * Build the statuses URI from the given parts. 43 | */ 44 | protected function buildStatusesUri(string ...$parts): string 45 | { 46 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', $this->commit, 'statuses', ...$parts); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/Statuses/AbstractStatusesApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit\Statuses; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\Commit\AbstractCommitApi; 17 | 18 | /** 19 | * The abstract statuses API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | abstract class AbstractStatusesApi extends AbstractCommitApi 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commit/Statuses/Build.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Commit\Statuses; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The build API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Build extends AbstractStatusesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function create(array $params = []): array 29 | { 30 | $uri = $this->buildBuildUri(); 31 | 32 | return $this->post($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $key, array $params = []): array 39 | { 40 | $uri = $this->buildBuildUri(...\explode('/', $key)); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function update(string $key, array $params = []): array 49 | { 50 | $uri = $this->buildBuildUri(...\explode('/', $key)); 51 | 52 | return $this->put($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the build URI from the given parts. 57 | */ 58 | protected function buildBuildUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', $this->commit, 'statuses', 'build', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Commits.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The branch restrictions API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Commits extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::build('repositories', $this->workspace, $this->repo, 'commits'); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $commit, array $params = []): array 39 | { 40 | $uri = UriBuilder::build('repositories', $this->workspace, $this->repo, 'commit', $commit); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Components.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The components API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Components extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildComponentsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $component, array $params = []): array 39 | { 40 | $uri = $this->buildComponentsUri($component); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * Build the components URI from the given parts. 47 | */ 48 | protected function buildComponentsUri(string ...$parts): string 49 | { 50 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'components', ...$parts); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/DefaultReviewers.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The default reviewers API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class DefaultReviewers extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildDefaultReviewersUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $reviewer, array $params = []): array 39 | { 40 | $uri = $this->buildDefaultReviewersUri($reviewer); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function add(string $reviewer, array $params = []): array 49 | { 50 | $uri = $this->buildDefaultReviewersUri($reviewer); 51 | 52 | return $this->put($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function remove(string $reviewer, array $params = []): array 59 | { 60 | $uri = $this->buildDefaultReviewersUri($reviewer); 61 | 62 | return $this->delete($uri, $params); 63 | } 64 | 65 | /** 66 | * Build the default reviewers URI from the given parts. 67 | */ 68 | protected function buildDefaultReviewersUri(string ...$parts): string 69 | { 70 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'default-reviewers', ...$parts); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/DeployKeys.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The deploy keys API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class DeployKeys extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildDeployKeysUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildDeployKeysUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $id, array $params = []): array 49 | { 50 | $uri = $this->buildDeployKeysUri($id); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $id, array $params = []): array 59 | { 60 | $uri = $this->buildDeployKeysUri($id); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $id, array $params = []): array 69 | { 70 | $uri = $this->buildDeployKeysUri($id); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the deploy keys URI from the given parts. 77 | */ 78 | protected function buildDeployKeysUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'deploy-keys', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Deployments.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\Deployments\EnvironmentVariables; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | 19 | /** 20 | * The deployments API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | class Deployments extends AbstractWorkspacesApi 25 | { 26 | /** 27 | * @throws \Http\Client\Exception 28 | */ 29 | public function list(array $params = []): array 30 | { 31 | $uri = $this->buildDeploymentsUri(); 32 | 33 | return $this->get($uri, $params); 34 | } 35 | 36 | /** 37 | * @throws \Http\Client\Exception 38 | */ 39 | public function show(string $deployments, array $params = []): array 40 | { 41 | $uri = $this->buildDeploymentsUri($deployments); 42 | 43 | return $this->get($uri, $params); 44 | } 45 | 46 | public function environmentVariables(string $environment): EnvironmentVariables 47 | { 48 | return new EnvironmentVariables($this->getClient(), $this->workspace, $this->repo, $environment); 49 | } 50 | 51 | /** 52 | * Build the deployments URI from the given parts. 53 | */ 54 | protected function buildDeploymentsUri(string ...$parts): string 55 | { 56 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'deployments', ...$parts); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Deployments/AbstractDeploymentsApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Deployments; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\AbstractWorkspacesApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract deployments API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractDeploymentsApi extends AbstractWorkspacesApi 25 | { 26 | protected readonly string $environment; 27 | 28 | public function __construct(Client $client, string $workspace, string $repo, string $environment) 29 | { 30 | parent::__construct($client, $workspace, $repo); 31 | $this->environment = $environment; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Deployments/EnvironmentVariables.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Deployments; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The environment ariables API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class EnvironmentVariables extends AbstractDeploymentsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildEnvironmentVariablesUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildEnvironmentVariablesUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function update(string $variable, array $params = []): array 49 | { 50 | $uri = $this->buildEnvironmentVariablesUri($variable); 51 | 52 | return $this->put($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function remove(string $variable, array $params = []): array 59 | { 60 | $uri = $this->buildEnvironmentVariablesUri($variable); 61 | 62 | return $this->delete($uri, $params); 63 | } 64 | 65 | /** 66 | * Build the variables URI from the given parts. 67 | */ 68 | protected function buildEnvironmentVariablesUri(string ...$parts): string 69 | { 70 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'deployments_config', 'environments', $this->environment, 'variables', ...$parts); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/DiffStat.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The diffs stat API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class DiffStat extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function download(string $spec, array $params = []): array 29 | { 30 | $uri = $this->buildDiffStatUri($spec); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the diff stat URI from the given parts. 37 | */ 38 | protected function buildDiffStatUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'diffstat', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Diffs.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The diffs API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Diffs extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function download(string $spec, array $params = []): \Psr\Http\Message\StreamInterface 29 | { 30 | $uri = $this->buildDiffsUri($spec); 31 | 32 | return $this->getAsResponse($uri, $params, ['Accept' => 'text/plain'])->getBody(); 33 | } 34 | 35 | /** 36 | * Build the diff URI from the given parts. 37 | */ 38 | protected function buildDiffsUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'diff', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Downloads.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Message\FileResource; 17 | use Bitbucket\HttpClient\Message\ResponseMediator; 18 | use Bitbucket\HttpClient\Util\UriBuilder; 19 | use Http\Message\MultipartStream\MultipartStreamBuilder; 20 | 21 | /** 22 | * The downloads API class. 23 | * 24 | * @author Graham Campbell 25 | */ 26 | class Downloads extends AbstractWorkspacesApi 27 | { 28 | /** 29 | * @throws \Http\Client\Exception 30 | */ 31 | public function list(array $params = []): array 32 | { 33 | $uri = $this->buildDownloadsUri(); 34 | 35 | return $this->get($uri, $params); 36 | } 37 | 38 | /** 39 | * @throws \Http\Client\Exception 40 | */ 41 | public function upload(FileResource $file): array 42 | { 43 | $uri = $this->buildDownloadsUri(); 44 | $builder = (new MultipartStreamBuilder())->addResource($file->getName(), $file->getResource(), $file->getOptions()); 45 | $headers = [ResponseMediator::CONTENT_TYPE_HEADER => \sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())]; 46 | 47 | return $this->postRaw($uri, $builder->build(), $headers); 48 | } 49 | 50 | /** 51 | * @throws \Http\Client\Exception 52 | */ 53 | public function download(string $filename, array $params = []): \Psr\Http\Message\StreamInterface 54 | { 55 | $uri = $this->buildDownloadsUri(...\explode('/', $filename)); 56 | 57 | return $this->getAsResponse($uri, $params, ['Accept' => '*/*'])->getBody(); 58 | } 59 | 60 | /** 61 | * @throws \Http\Client\Exception 62 | */ 63 | public function remove(string $filename, array $params = []): array 64 | { 65 | $uri = $this->buildDownloadsUri(...\explode('/', $filename)); 66 | 67 | return $this->delete($uri, $params); 68 | } 69 | 70 | /** 71 | * Build the downloads URI from the given parts. 72 | */ 73 | protected function buildDownloadsUri(string ...$parts): string 74 | { 75 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'downloads', ...$parts); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Environments.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The environments API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Environments extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildEnvironmentsUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $env, array $params = []): array 39 | { 40 | $uri = $this->buildEnvironmentsUri($env); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function create(array $params = []): array 49 | { 50 | $uri = UriBuilder::appendSeparator($this->buildEnvironmentsUri()); 51 | 52 | return $this->post($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $env, array $params = []): array 59 | { 60 | $uri = UriBuilder::appendSeparator($this->buildEnvironmentsUri($env, 'changes')); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $env): array 69 | { 70 | $uri = $this->buildEnvironmentsUri($env); 71 | 72 | return $this->delete($uri); 73 | } 74 | 75 | /** 76 | * Build the environments URI from the given parts. 77 | */ 78 | protected function buildEnvironmentsUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'environments', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/FileHistory.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The file history API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class FileHistory extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(string $commit, string $uri, array $params = []): array 29 | { 30 | $uri = $this->buildFileHistoryUri($commit, ...\explode('/', $uri)); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the file history URI from the given parts. 37 | */ 38 | protected function buildFileHistoryUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'filehistory', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Forks.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The forks API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Forks extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildForksUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildForksUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * Build the forks URI from the given parts. 47 | */ 48 | protected function buildForksUri(string ...$parts): string 49 | { 50 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'forks', ...$parts); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Hooks.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The hooks API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Hooks extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildHooksUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildHooksUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $hook, array $params = []): array 49 | { 50 | $uri = $this->buildHooksUri($hook); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $hook, array $params = []): array 59 | { 60 | $uri = $this->buildHooksUri($hook); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $hook, array $params = []): array 69 | { 70 | $uri = $this->buildHooksUri($hook); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the hooks URI from the given parts. 77 | */ 78 | protected function buildHooksUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'hooks', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Issues.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\Issues\Attachments; 17 | use Bitbucket\Api\Repositories\Workspaces\Issues\Changes; 18 | use Bitbucket\Api\Repositories\Workspaces\Issues\Comments; 19 | use Bitbucket\Api\Repositories\Workspaces\Issues\Voting; 20 | use Bitbucket\Api\Repositories\Workspaces\Issues\Watching; 21 | use Bitbucket\HttpClient\Util\UriBuilder; 22 | 23 | /** 24 | * The issues API class. 25 | * 26 | * @author Graham Campbell 27 | */ 28 | class Issues extends AbstractWorkspacesApi 29 | { 30 | /** 31 | * @throws \Http\Client\Exception 32 | */ 33 | public function list(array $params = []): array 34 | { 35 | $uri = $this->buildIssuesUri(); 36 | 37 | return $this->get($uri, $params); 38 | } 39 | 40 | /** 41 | * @throws \Http\Client\Exception 42 | */ 43 | public function create(array $params = []): array 44 | { 45 | $uri = $this->buildIssuesUri(); 46 | 47 | return $this->post($uri, $params); 48 | } 49 | 50 | /** 51 | * @throws \Http\Client\Exception 52 | */ 53 | public function show(string $issue, array $params = []): array 54 | { 55 | $uri = $this->buildIssuesUri($issue); 56 | 57 | return $this->get($uri, $params); 58 | } 59 | 60 | /** 61 | * @throws \Http\Client\Exception 62 | */ 63 | public function update(string $issue, array $params = []): array 64 | { 65 | $uri = $this->buildIssuesUri($issue); 66 | 67 | return $this->put($uri, $params); 68 | } 69 | 70 | /** 71 | * @throws \Http\Client\Exception 72 | */ 73 | public function remove(string $issue, array $params = []): array 74 | { 75 | $uri = $this->buildIssuesUri($issue); 76 | 77 | return $this->delete($uri, $params); 78 | } 79 | 80 | public function attachments(string $issue): Attachments 81 | { 82 | return new Attachments($this->getClient(), $this->workspace, $this->repo, $issue); 83 | } 84 | 85 | public function changes(string $issue): Changes 86 | { 87 | return new Changes($this->getClient(), $this->workspace, $this->repo, $issue); 88 | } 89 | 90 | public function comments(string $issue): Comments 91 | { 92 | return new Comments($this->getClient(), $this->workspace, $this->repo, $issue); 93 | } 94 | 95 | public function voting(string $issue): Voting 96 | { 97 | return new Voting($this->getClient(), $this->workspace, $this->repo, $issue); 98 | } 99 | 100 | public function watching(string $issue): Watching 101 | { 102 | return new Watching($this->getClient(), $this->workspace, $this->repo, $issue); 103 | } 104 | 105 | /** 106 | * Build the issues URI from the given parts. 107 | */ 108 | protected function buildIssuesUri(string ...$parts): string 109 | { 110 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'issues', ...$parts); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Issues/AbstractIssuesApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Issues; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\AbstractWorkspacesApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract issues API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractIssuesApi extends AbstractWorkspacesApi 25 | { 26 | protected readonly string $issue; 27 | 28 | public function __construct(Client $client, string $workspace, string $repo, string $issue) 29 | { 30 | parent::__construct($client, $workspace, $repo); 31 | $this->issue = $issue; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Issues/Attachments.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Issues; 15 | 16 | use Bitbucket\HttpClient\Message\FileResource; 17 | use Bitbucket\HttpClient\Message\ResponseMediator; 18 | use Bitbucket\HttpClient\Util\UriBuilder; 19 | use Http\Message\MultipartStream\MultipartStreamBuilder; 20 | 21 | /** 22 | * The attachments API class. 23 | * 24 | * @author Graham Campbell 25 | */ 26 | class Attachments extends AbstractIssuesApi 27 | { 28 | /** 29 | * @throws \Http\Client\Exception 30 | */ 31 | public function list(array $params = []): array 32 | { 33 | $uri = $this->buildAttachmentsUri(); 34 | 35 | return $this->get($uri, $params); 36 | } 37 | 38 | /** 39 | * @throws \Http\Client\Exception 40 | */ 41 | public function upload(FileResource $file): array 42 | { 43 | $uri = $this->buildAttachmentsUri(); 44 | $builder = (new MultipartStreamBuilder())->addResource($file->getName(), $file->getResource(), $file->getOptions()); 45 | $headers = [ResponseMediator::CONTENT_TYPE_HEADER => \sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())]; 46 | 47 | return $this->postRaw($uri, $builder->build(), $headers); 48 | } 49 | 50 | /** 51 | * @throws \Http\Client\Exception 52 | */ 53 | public function download(string $filename, array $params = []): \Psr\Http\Message\StreamInterface 54 | { 55 | $uri = $this->buildAttachmentsUri($filename); 56 | 57 | return $this->getAsResponse($uri, $params, ['Accept' => '*/*'])->getBody(); 58 | } 59 | 60 | /** 61 | * @throws \Http\Client\Exception 62 | */ 63 | public function remove(string $filename, array $params = []): array 64 | { 65 | $uri = $this->buildAttachmentsUri($filename); 66 | 67 | return $this->delete($uri, $params); 68 | } 69 | 70 | /** 71 | * Build the attachments URI from the given parts. 72 | */ 73 | protected function buildAttachmentsUri(string ...$parts): string 74 | { 75 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'issues', $this->issue, 'attachments', ...$parts); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Issues/Changes.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Issues; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The changes API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Changes extends AbstractIssuesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildChangesUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildChangesUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $change, array $params = []): array 49 | { 50 | $uri = $this->buildChangesUri($change); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the changes URI from the given parts. 57 | */ 58 | protected function buildChangesUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'issues', $this->issue, 'changes', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Issues/Comments.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Issues; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The comments API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Comments extends AbstractIssuesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildCommentsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $comment, array $params = []): array 39 | { 40 | $uri = $this->buildCommentsUri($comment); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function create(array $params = []): array 49 | { 50 | $uri = $this->buildCommentsUri(); 51 | 52 | return $this->post($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $comment, array $params = []): array 59 | { 60 | $uri = $this->buildCommentsUri($comment); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $comment): array 69 | { 70 | $uri = $this->buildCommentsUri($comment); 71 | 72 | return $this->delete($uri); 73 | } 74 | 75 | /** 76 | * Build the comments URI from the given parts. 77 | */ 78 | protected function buildCommentsUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'issues', $this->issue, 'comments', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Issues/Voting.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Issues; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The voting class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Voting extends AbstractIssuesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function check(array $params = []): array 29 | { 30 | $uri = $this->buildVotingUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function vote(array $params = []): array 39 | { 40 | $uri = $this->buildVotingUri(); 41 | 42 | return $this->put($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function retract(array $params = []): array 49 | { 50 | $uri = $this->buildVotingUri(); 51 | 52 | return $this->delete($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the voting URI from the given parts. 57 | */ 58 | protected function buildVotingUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'issues', $this->issue, 'vote', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Issues/Watching.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Issues; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The watching class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Watching extends AbstractIssuesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function check(array $params = []): array 29 | { 30 | $uri = $this->buildWatchingUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function watch(array $params = []): array 39 | { 40 | $uri = $this->buildWatchingUri(); 41 | 42 | return $this->put($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function ignore(array $params = []): array 49 | { 50 | $uri = $this->buildWatchingUri(); 51 | 52 | return $this->delete($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the watching URI from the given parts. 57 | */ 58 | protected function buildWatchingUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'issues', $this->issue, 'watch', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/MergeBases.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The merge bases API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class MergeBases extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function show(string $spec, array $params = []): array 29 | { 30 | $uri = $this->buildMergeBasesUri($spec); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the merge base URI from the given parts. 37 | */ 38 | protected function buildMergeBasesUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'merge-base', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Milestones.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The milestones API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Milestones extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildMilestonesUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $milestone, array $params = []): array 39 | { 40 | $uri = $this->buildMilestonesUri($milestone); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * Build the milestones URI from the given parts. 47 | */ 48 | protected function buildMilestonesUri(string ...$parts): string 49 | { 50 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'milestones', ...$parts); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Patches.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The patches API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Patches extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function download(string $spec, array $params = []): \Psr\Http\Message\StreamInterface 29 | { 30 | $uri = $this->buildPatchesUri($spec); 31 | 32 | return $this->getAsResponse($uri, $params, ['Accept' => 'text/plain'])->getBody(); 33 | } 34 | 35 | /** 36 | * Build the patches URI from the given parts. 37 | */ 38 | protected function buildPatchesUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'patch', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Pipelines.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\Pipelines\RemoteTriggers; 17 | use Bitbucket\Api\Repositories\Workspaces\Pipelines\Steps; 18 | use Bitbucket\HttpClient\Util\UriBuilder; 19 | 20 | /** 21 | * The pipelines API class. 22 | * 23 | * @author Graham Campbell 24 | */ 25 | class Pipelines extends AbstractWorkspacesApi 26 | { 27 | /** 28 | * @throws \Http\Client\Exception 29 | */ 30 | public function list(array $params = []): array 31 | { 32 | $uri = UriBuilder::appendSeparator($this->buildPipelinesUri()); 33 | 34 | return $this->get($uri, $params); 35 | } 36 | 37 | /** 38 | * @throws \Http\Client\Exception 39 | */ 40 | public function create(array $params = []): array 41 | { 42 | $uri = UriBuilder::appendSeparator($this->buildPipelinesUri()); 43 | 44 | return $this->post($uri, $params); 45 | } 46 | 47 | /** 48 | * @throws \Http\Client\Exception 49 | */ 50 | public function show(string $pipeline, array $params = []): array 51 | { 52 | $uri = $this->buildPipelinesUri($pipeline); 53 | 54 | return $this->get($uri, $params); 55 | } 56 | 57 | /** 58 | * @throws \Http\Client\Exception 59 | */ 60 | public function stop(string $pipeline, array $params = []): array 61 | { 62 | $uri = $this->buildPipelinesUri($pipeline, 'stopPipeline'); 63 | 64 | return $this->post($uri, $params); 65 | } 66 | 67 | public function remoteTriggers(string $pipeline): RemoteTriggers 68 | { 69 | return new RemoteTriggers($this->getClient(), $this->workspace, $this->repo, $pipeline); 70 | } 71 | 72 | public function steps(string $pipeline): Steps 73 | { 74 | return new Steps($this->getClient(), $this->workspace, $this->repo, $pipeline); 75 | } 76 | 77 | /** 78 | * Build the pipelines URI from the given parts. 79 | */ 80 | protected function buildPipelinesUri(string ...$parts): string 81 | { 82 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines', ...$parts); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Pipelines/AbstractPipelinesApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Pipelines; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\AbstractWorkspacesApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract pipelines API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractPipelinesApi extends AbstractWorkspacesApi 25 | { 26 | protected readonly string $pipeline; 27 | 28 | public function __construct(Client $client, string $workspace, string $repo, string $pipeline) 29 | { 30 | parent::__construct($client, $workspace, $repo); 31 | $this->pipeline = $pipeline; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Pipelines/RemoteTriggers.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Pipelines; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The remote triggers API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class RemoteTriggers extends AbstractPipelinesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function update(string $key, array $params = []): array 29 | { 30 | $uri = $this->buildRemoteTriggersUri($key); 31 | 32 | return $this->put($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the remote triggers URI from the given parts. 37 | */ 38 | protected function buildRemoteTriggersUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines', $this->pipeline, 'remote-triggers', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Pipelines/Steps.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Pipelines; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The steps API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Steps extends AbstractPipelinesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildStepsUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $step, array $params = []): array 39 | { 40 | $uri = $this->buildStepsUri($step); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function log(string $step, array $params = []): \Psr\Http\Message\StreamInterface 49 | { 50 | $uri = $this->buildStepsUri($step, 'log'); 51 | 52 | return $this->getAsResponse($uri, $params, ['Accept' => 'application/octet-stream'])->getBody(); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function specificLog(string $step, string $uuid, array $params = []): \Psr\Http\Message\StreamInterface 59 | { 60 | $uri = $this->buildStepsUri($step, 'logs', $uuid); 61 | 62 | return $this->getAsResponse($uri, $params, ['Accept' => 'application/octet-stream'])->getBody(); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function stop(string $step, array $params = []): array 69 | { 70 | $uri = $this->buildStepsUri($step, 'stopPipeline'); 71 | 72 | return $this->post($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the steps URI from the given parts. 77 | */ 78 | protected function buildStepsUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines', $this->pipeline, 'steps', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\Variables; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | 19 | /** 20 | * The pipelines config API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | class PipelinesConfig extends AbstractWorkspacesApi 25 | { 26 | public function variables(): Variables 27 | { 28 | return new Variables($this->getClient(), $this->workspace, $this->repo); 29 | } 30 | 31 | /** 32 | * @throws \Http\Client\Exception 33 | */ 34 | public function show(array $params = []): array 35 | { 36 | $uri = $this->buildPipelinesConfigUri(); 37 | 38 | return $this->get($uri, $params); 39 | } 40 | 41 | /** 42 | * @throws \Http\Client\Exception 43 | */ 44 | public function update(array $params = []): array 45 | { 46 | $uri = $this->buildPipelinesConfigUri(); 47 | 48 | return $this->put($uri, $params); 49 | } 50 | 51 | /** 52 | * Build the pipelines config URI from the given parts. 53 | */ 54 | protected function buildPipelinesConfigUri(string ...$parts): string 55 | { 56 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines_config', ...$parts); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/AbstractPipelinesConfigApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\AbstractWorkspacesApi; 17 | 18 | /** 19 | * The abstract pipelines config API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | abstract class AbstractPipelinesConfigApi extends AbstractWorkspacesApi 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/BuildNumber.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The build number API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class BuildNumber extends AbstractPipelinesConfigApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function update(array $params = []): array 29 | { 30 | $uri = $this->buildBuildNumberUri(); 31 | 32 | return $this->put($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the build number URI from the given parts. 37 | */ 38 | protected function buildBuildNumberUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines_config', 'build_number', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/Schedules.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\Schedules\Executions; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | 19 | /** 20 | * The schedules API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | class Schedules extends AbstractPipelinesConfigApi 25 | { 26 | /** 27 | * @throws \Http\Client\Exception 28 | */ 29 | public function list(array $params = []): array 30 | { 31 | $uri = UriBuilder::appendSeparator($this->buildSchedulesUri()); 32 | 33 | return $this->get($uri, $params); 34 | } 35 | 36 | /** 37 | * @throws \Http\Client\Exception 38 | */ 39 | public function create(array $params = []): array 40 | { 41 | $uri = UriBuilder::appendSeparator($this->buildSchedulesUri()); 42 | 43 | return $this->post($uri, $params); 44 | } 45 | 46 | /** 47 | * @throws \Http\Client\Exception 48 | */ 49 | public function show(string $schedule, array $params = []): array 50 | { 51 | $uri = $this->buildSchedulesUri($schedule); 52 | 53 | return $this->get($uri, $params); 54 | } 55 | 56 | /** 57 | * @throws \Http\Client\Exception 58 | */ 59 | public function update(string $schedule, array $params = []): array 60 | { 61 | $uri = $this->buildSchedulesUri($schedule); 62 | 63 | return $this->put($uri, $params); 64 | } 65 | 66 | /** 67 | * @throws \Http\Client\Exception 68 | */ 69 | public function remove(string $schedule, array $params = []): array 70 | { 71 | $uri = $this->buildSchedulesUri($schedule); 72 | 73 | return $this->delete($uri, $params); 74 | } 75 | 76 | public function executions(string $schedule): Executions 77 | { 78 | return new Executions($this->getClient(), $this->workspace, $this->repo, $schedule); 79 | } 80 | 81 | /** 82 | * Build the schedules URI from the given parts. 83 | */ 84 | protected function buildSchedulesUri(string ...$parts): string 85 | { 86 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines_config', 'schedules', ...$parts); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/Schedules/AbstractSchedulesApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\Schedules; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\AbstractPipelinesConfigApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract schedules API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractSchedulesApi extends AbstractPipelinesConfigApi 25 | { 26 | protected readonly string $schedule; 27 | 28 | public function __construct(Client $client, string $workspace, string $repo, string $schedule) 29 | { 30 | parent::__construct($client, $workspace, $repo); 31 | $this->schedule = $schedule; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/Schedules/Executions.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\Schedules; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The executions API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Executions extends AbstractSchedulesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildExecutionsUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the executions URI from the given parts. 37 | */ 38 | protected function buildExecutionsUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines_config', 'schedules', $this->schedule, 'executions', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/Ssh.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\Ssh\KeyPair; 17 | use Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\Ssh\KnownHosts; 18 | use Bitbucket\HttpClient\Util\UriBuilder; 19 | 20 | /** 21 | * The ssh API class. 22 | * 23 | * @author Graham Campbell 24 | */ 25 | class Ssh extends AbstractPipelinesConfigApi 26 | { 27 | public function keyPair(): KeyPair 28 | { 29 | return new KeyPair($this->getClient(), $this->workspace, $this->repo); 30 | } 31 | 32 | public function knownHosts(): KnownHosts 33 | { 34 | return new KnownHosts($this->getClient(), $this->workspace, $this->repo); 35 | } 36 | 37 | /** 38 | * Build the ssh URI from the given parts. 39 | */ 40 | protected function buildSshUri(string ...$parts): string 41 | { 42 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines_config', 'ssh', ...$parts); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/Ssh/AbstractSshApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\Ssh; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\AbstractPipelinesConfigApi; 17 | 18 | /** 19 | * The abstract ssh API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | abstract class AbstractSshApi extends AbstractPipelinesConfigApi 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/Ssh/KeyPair.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\Ssh; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The key pair API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class KeyPair extends AbstractSshApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function show(array $params = []): array 29 | { 30 | $uri = $this->buildKeyPairUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function update(array $params = []): array 39 | { 40 | $uri = $this->buildKeyPairUri(); 41 | 42 | return $this->put($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function remove(array $params = []): array 49 | { 50 | $uri = $this->buildKeyPairUri(); 51 | 52 | return $this->delete($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the key pair URI from the given parts. 57 | */ 58 | protected function buildKeyPairUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines_config', 'ssh', 'key_pair', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/Ssh/KnownHosts.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig\Ssh; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The known hosts API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class KnownHosts extends AbstractSshApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildKnownHostsUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = UriBuilder::appendSeparator($this->buildKnownHostsUri()); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $host, array $params = []): array 49 | { 50 | $uri = $this->buildKnownHostsUri($host); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $host, array $params = []): array 59 | { 60 | $uri = $this->buildKnownHostsUri($host); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $host, array $params = []): array 69 | { 70 | $uri = $this->buildKnownHostsUri($host); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the known hosts URI from the given parts. 77 | */ 78 | protected function buildKnownHostsUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines_config', 'ssh', 'known_hosts', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PipelinesConfig/Variables.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PipelinesConfig; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The variables API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Variables extends AbstractPipelinesConfigApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildVariablesUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = UriBuilder::appendSeparator($this->buildVariablesUri()); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $variable, array $params = []): array 49 | { 50 | $uri = $this->buildVariablesUri($variable); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $variable, array $params = []): array 59 | { 60 | $uri = $this->buildVariablesUri($variable); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $variable, array $params = []): array 69 | { 70 | $uri = $this->buildVariablesUri($variable); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the variables URI from the given parts. 77 | */ 78 | protected function buildVariablesUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pipelines_config', 'variables', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Properties.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The properties API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Properties extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function show(string $app, string $property, array $params = []): array 29 | { 30 | $uri = $this->buildPropertiesUri($app, $property); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function update(string $app, string $property, array $params = []): array 39 | { 40 | $uri = $this->buildPropertiesUri($app, $property); 41 | 42 | return $this->put($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function remove(string $app, string $property, array $params = []): array 49 | { 50 | $uri = $this->buildPropertiesUri($app, $property); 51 | 52 | return $this->delete($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the properties URI from the given parts. 57 | */ 58 | protected function buildPropertiesUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'properties', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\PullRequests\Approval; 17 | use Bitbucket\Api\Repositories\Workspaces\PullRequests\Comments; 18 | use Bitbucket\Api\Repositories\Workspaces\PullRequests\Commits as PullRequestsCommits; 19 | use Bitbucket\Api\Repositories\Workspaces\PullRequests\Diff; 20 | use Bitbucket\Api\Repositories\Workspaces\PullRequests\DiffStat; 21 | use Bitbucket\Api\Repositories\Workspaces\PullRequests\Patch; 22 | use Bitbucket\Api\Repositories\Workspaces\PullRequests\Properties as PullRequestsProperties; 23 | use Bitbucket\Api\Repositories\Workspaces\PullRequests\Statuses; 24 | use Bitbucket\HttpClient\Util\UriBuilder; 25 | 26 | /** 27 | * The pull requests API class. 28 | * 29 | * @author Graham Campbell 30 | */ 31 | class PullRequests extends AbstractWorkspacesApi 32 | { 33 | /** 34 | * @throws \Http\Client\Exception 35 | */ 36 | public function list(array $params = []): array 37 | { 38 | $uri = $this->buildPullRequestsUri(); 39 | 40 | return $this->get($uri, $params); 41 | } 42 | 43 | /** 44 | * @throws \Http\Client\Exception 45 | */ 46 | public function activity(array $params = []): array 47 | { 48 | $uri = $this->buildPullRequestsUri('activity'); 49 | 50 | return $this->get($uri, $params); 51 | } 52 | 53 | /** 54 | * @throws \Http\Client\Exception 55 | */ 56 | public function create(array $params = []): array 57 | { 58 | $uri = $this->buildPullRequestsUri(); 59 | 60 | return $this->post($uri, $params); 61 | } 62 | 63 | /** 64 | * @throws \Http\Client\Exception 65 | */ 66 | public function show(string $pr, array $params = []): array 67 | { 68 | $uri = $this->buildPullRequestsUri($pr); 69 | 70 | return $this->get($uri, $params); 71 | } 72 | 73 | /** 74 | * @throws \Http\Client\Exception 75 | */ 76 | public function activityByPr(string $pr, array $params = []): array 77 | { 78 | $uri = $this->buildPullRequestsUri($pr, 'activity'); 79 | 80 | return $this->get($uri, $params); 81 | } 82 | 83 | /** 84 | * @throws \Http\Client\Exception 85 | */ 86 | public function update(string $pr, array $params = []): array 87 | { 88 | $uri = $this->buildPullRequestsUri($pr); 89 | 90 | return $this->put($uri, $params); 91 | } 92 | 93 | /** 94 | * @throws \Http\Client\Exception 95 | */ 96 | public function decline(string $pr, array $params = []): array 97 | { 98 | $uri = $this->buildPullRequestsUri($pr, 'decline'); 99 | 100 | return $this->post($uri, $params); 101 | } 102 | 103 | /** 104 | * @throws \Http\Client\Exception 105 | */ 106 | public function merge(string $pr, array $params = []): array 107 | { 108 | $uri = $this->buildPullRequestsUri($pr, 'merge'); 109 | 110 | return $this->post($uri, $params); 111 | } 112 | 113 | /** 114 | * @throws \Http\Client\Exception 115 | */ 116 | public function mergeTaskStatus(string $pr, string $task, array $params = []): array 117 | { 118 | $uri = $this->buildPullRequestsUri($pr, 'merge', 'task-status', $task); 119 | 120 | return $this->get($uri, $params); 121 | } 122 | 123 | public function approval(string $pr): Approval 124 | { 125 | return new Approval($this->getClient(), $this->workspace, $this->repo, $pr); 126 | } 127 | 128 | public function comments(string $pr): Comments 129 | { 130 | return new Comments($this->getClient(), $this->workspace, $this->repo, $pr); 131 | } 132 | 133 | public function commits(string $pr): PullRequestsCommits 134 | { 135 | return new PullRequestsCommits($this->getClient(), $this->workspace, $this->repo, $pr); 136 | } 137 | 138 | public function diff(string $pr): Diff 139 | { 140 | return new Diff($this->getClient(), $this->workspace, $this->repo, $pr); 141 | } 142 | 143 | public function diffstat(string $pr): DiffStat 144 | { 145 | return new DiffStat($this->getClient(), $this->workspace, $this->repo, $pr); 146 | } 147 | 148 | public function patch(string $pr): Patch 149 | { 150 | return new Patch($this->getClient(), $this->workspace, $this->repo, $pr); 151 | } 152 | 153 | public function properties(string $pr): PullRequestsProperties 154 | { 155 | return new PullRequestsProperties($this->getClient(), $this->workspace, $this->repo, $pr); 156 | } 157 | 158 | public function statuses(string $pr): Statuses 159 | { 160 | return new Statuses($this->getClient(), $this->workspace, $this->repo, $pr); 161 | } 162 | 163 | /** 164 | * Build the pull requests URI from the given parts. 165 | */ 166 | protected function buildPullRequestsUri(string ...$parts): string 167 | { 168 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pullrequests', ...$parts); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests/AbstractPullRequestsApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PullRequests; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\AbstractWorkspacesApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract pull requests API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractPullRequestsApi extends AbstractWorkspacesApi 25 | { 26 | protected readonly string $pr; 27 | 28 | public function __construct(Client $client, string $workspace, string $repo, string $pr) 29 | { 30 | parent::__construct($client, $workspace, $repo); 31 | $this->pr = $pr; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests/Approval.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PullRequests; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The approval API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Approval extends AbstractPullRequestsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function approve(array $params = []): array 29 | { 30 | $uri = $this->buildApprovalUri(); 31 | 32 | return $this->post($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function redact(array $params = []): array 39 | { 40 | $uri = $this->buildApprovalUri(); 41 | 42 | return $this->delete($uri, $params); 43 | } 44 | 45 | /** 46 | * Build the approval URI from the given parts. 47 | */ 48 | protected function buildApprovalUri(string ...$parts): string 49 | { 50 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pullrequests', $this->pr, 'approve', ...$parts); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests/Comments.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PullRequests; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The comments API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Comments extends AbstractPullRequestsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildCommentsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $comment, array $params = []): array 39 | { 40 | $uri = $this->buildCommentsUri($comment); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function create(array $params = []): array 49 | { 50 | $uri = $this->buildCommentsUri(); 51 | 52 | return $this->post($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $comment, array $params = []): array 59 | { 60 | $uri = $this->buildCommentsUri($comment); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $comment): array 69 | { 70 | $uri = $this->buildCommentsUri($comment); 71 | 72 | return $this->delete($uri); 73 | } 74 | 75 | /** 76 | * Build the comments URI from the given parts. 77 | */ 78 | protected function buildCommentsUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pullrequests', $this->pr, 'comments', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests/Commits.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PullRequests; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The commits API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Commits extends AbstractPullRequestsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildCommitsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the commits URI from the given parts. 37 | */ 38 | protected function buildCommitsUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pullrequests', $this->pr, 'commits', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests/Diff.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PullRequests; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The diff API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Diff extends AbstractPullRequestsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function download(array $params = []): \Psr\Http\Message\StreamInterface 29 | { 30 | $uri = $this->buildDiffUri(); 31 | 32 | return $this->getAsResponse($uri, $params, ['Accept' => 'text/plain'])->getBody(); 33 | } 34 | 35 | /** 36 | * Build the diff URI from the given parts. 37 | */ 38 | protected function buildDiffUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pullrequests', $this->pr, 'diff', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests/DiffStat.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PullRequests; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The diff stat API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class DiffStat extends AbstractPullRequestsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function download(array $params = []): array 29 | { 30 | $uri = $this->buildDiffStatUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the diff stat URI from the given parts. 37 | */ 38 | protected function buildDiffStatUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pullrequests', $this->pr, 'diffstat', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests/Patch.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PullRequests; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The patch API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Patch extends AbstractPullRequestsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function download(array $params = []): \Psr\Http\Message\StreamInterface 29 | { 30 | $uri = $this->buildPatchUri(); 31 | 32 | return $this->getAsResponse($uri, $params, ['Accept' => 'text/plain'])->getBody(); 33 | } 34 | 35 | /** 36 | * Build the patch URI from the given parts. 37 | */ 38 | protected function buildPatchUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pullrequests', $this->pr, 'patch', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests/Properties.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PullRequests; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The properties API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Properties extends AbstractPullRequestsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function show(string $app, string $property, array $params = []): array 29 | { 30 | $uri = $this->buildPropertiesUri($app, $property); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function update(string $app, string $property, array $params = []): array 39 | { 40 | $uri = $this->buildPropertiesUri($app, $property); 41 | 42 | return $this->put($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function remove(string $app, string $property, array $params = []): array 49 | { 50 | $uri = $this->buildPropertiesUri($app, $property); 51 | 52 | return $this->delete($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the properties URI from the given parts. 57 | */ 58 | protected function buildPropertiesUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pullrequests', $this->pr, 'properties', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/PullRequests/Statuses.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\PullRequests; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The statuses API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Statuses extends AbstractPullRequestsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildStatusesUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the statuses URI from the given parts. 37 | */ 38 | protected function buildStatusesUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'pullrequests', $this->pr, 'statuses', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Refs.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\Refs\Branches; 17 | use Bitbucket\Api\Repositories\Workspaces\Refs\Tags; 18 | use Bitbucket\HttpClient\Util\UriBuilder; 19 | 20 | /** 21 | * The refs API class. 22 | * 23 | * @author Graham Campbell 24 | */ 25 | class Refs extends AbstractWorkspacesApi 26 | { 27 | /** 28 | * @throws \Http\Client\Exception 29 | */ 30 | public function list(array $params = []): array 31 | { 32 | $uri = $this->buildRefsUri(); 33 | 34 | return $this->get($uri, $params); 35 | } 36 | 37 | public function branches(): Branches 38 | { 39 | return new Branches($this->getClient(), $this->workspace, $this->repo); 40 | } 41 | 42 | public function tags(): Tags 43 | { 44 | return new Tags($this->getClient(), $this->workspace, $this->repo); 45 | } 46 | 47 | /** 48 | * Build the refs URI from the given parts. 49 | */ 50 | protected function buildRefsUri(string ...$parts): string 51 | { 52 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'refs', ...$parts); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Refs/AbstractRefsApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Refs; 15 | 16 | use Bitbucket\Api\Repositories\Workspaces\AbstractWorkspacesApi; 17 | 18 | /** 19 | * The abstract refs API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | abstract class AbstractRefsApi extends AbstractWorkspacesApi 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Refs/Branches.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Refs; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The branches API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Branches extends AbstractRefsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildBranchesUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildBranchesUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $branch, array $params = []): array 49 | { 50 | $uri = $this->buildBranchesUri($branch); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function remove(string $branch, array $params = []): array 59 | { 60 | $uri = $this->buildBranchesUri($branch); 61 | 62 | return $this->delete($uri, $params); 63 | } 64 | 65 | /** 66 | * Build the branches URI from the given parts. 67 | */ 68 | protected function buildBranchesUri(string ...$parts): string 69 | { 70 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'refs', 'branches', ...$parts); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Refs/Tags.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces\Refs; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The tags API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Tags extends AbstractRefsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildTagsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildTagsUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $tag, array $params = []): array 49 | { 50 | $uri = $this->buildTagsUri($tag); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function remove(string $tag, array $params = []): array 59 | { 60 | $uri = $this->buildTagsUri($tag); 61 | 62 | return $this->delete($uri, $params); 63 | } 64 | 65 | /** 66 | * Build the tags URI from the given parts. 67 | */ 68 | protected function buildTagsUri(string ...$parts): string 69 | { 70 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'refs', 'tags', ...$parts); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Src.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Message\ResponseMediator; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | use Http\Message\MultipartStream\MultipartStreamBuilder; 19 | 20 | /** 21 | * The src API class. 22 | * 23 | * @author Graham Campbell 24 | */ 25 | class Src extends AbstractWorkspacesApi 26 | { 27 | /** 28 | * @throws \Http\Client\Exception 29 | */ 30 | public function list(array $params = []): array 31 | { 32 | $uri = $this->buildSrcUri(); 33 | 34 | return $this->get($uri, $params); 35 | } 36 | 37 | /** 38 | * @param array $params 39 | * 40 | * @throws \Http\Client\Exception 41 | */ 42 | public function create(array $params = []): array 43 | { 44 | $uri = $this->buildSrcUri(); 45 | 46 | return $this->post($uri, $params); 47 | } 48 | 49 | /** 50 | * @param \Bitbucket\HttpClient\Message\FileResource[] $files 51 | * @param array $params 52 | * 53 | * @throws \Http\Client\Exception 54 | */ 55 | public function createWithFiles(array $files, array $params = []): array 56 | { 57 | $uri = $this->buildSrcUri(); 58 | 59 | $builder = new MultipartStreamBuilder(); 60 | 61 | foreach ($params as $name => $value) { 62 | $builder->addResource($name, $value); 63 | } 64 | 65 | foreach ($files as $file) { 66 | if ('' === $file->getResource()) { 67 | $builder->addResource('files', $file->getName()); 68 | } else { 69 | $builder->addResource($file->getName(), $file->getResource(), $file->getOptions()); 70 | } 71 | } 72 | 73 | $headers = [ResponseMediator::CONTENT_TYPE_HEADER => \sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())]; 74 | 75 | return $this->postRaw($uri, $builder->build(), $headers); 76 | } 77 | 78 | /** 79 | * @throws \Http\Client\Exception 80 | */ 81 | public function show(string $commit, string $filepath, array $params = []): array 82 | { 83 | $uri = $this->buildSrcUri($commit, ...\explode('/', $filepath)); 84 | 85 | if (!isset($params['format'])) { 86 | $params['format'] = 'meta'; 87 | } 88 | 89 | return $this->get($uri, $params); 90 | } 91 | 92 | /** 93 | * @throws \Http\Client\Exception 94 | */ 95 | public function download(string $commit, string $filepath, array $params = []): \Psr\Http\Message\StreamInterface 96 | { 97 | $uri = $this->buildSrcUri($commit, ...\explode('/', $filepath)); 98 | 99 | return $this->getAsResponse($uri, $params, ['Accept' => '*/*'])->getBody(); 100 | } 101 | 102 | /** 103 | * Build the src URI from the given parts. 104 | */ 105 | protected function buildSrcUri(string ...$parts): string 106 | { 107 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'src', ...$parts); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Versions.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The versions API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Versions extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildVersionsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $version, array $params = []): array 39 | { 40 | $uri = $this->buildVersionsUri($version); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * Build the versions URI from the given parts. 47 | */ 48 | protected function buildVersionsUri(string ...$parts): string 49 | { 50 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'versions', ...$parts); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Api/Repositories/Workspaces/Watchers.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Repositories\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The watchers API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Watchers extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildWatchersUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the watchers URI from the given parts. 37 | */ 38 | protected function buildWatchersUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('repositories', $this->workspace, $this->repo, 'watchers', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Snippets.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api; 15 | 16 | use Bitbucket\Api\Snippets\Workspaces as SnippetsWorkspaces; 17 | use Bitbucket\HttpClient\Message\FileResource; 18 | use Bitbucket\HttpClient\Message\ResponseMediator; 19 | use Bitbucket\HttpClient\Util\UriBuilder; 20 | use Http\Message\MultipartStream\MultipartStreamBuilder; 21 | 22 | /** 23 | * The snippets API class. 24 | * 25 | * @author Graham Campbell 26 | */ 27 | class Snippets extends AbstractApi 28 | { 29 | /** 30 | * @throws \Http\Client\Exception 31 | */ 32 | public function list(array $params = []): array 33 | { 34 | $uri = $this->buildSnippetsUri(); 35 | 36 | return $this->get($uri, $params); 37 | } 38 | 39 | /** 40 | * @throws \Http\Client\Exception 41 | */ 42 | public function create(FileResource $file): array 43 | { 44 | $uri = $this->buildSnippetsUri(); 45 | $builder = (new MultipartStreamBuilder())->addResource($file->getName(), $file->getResource(), $file->getOptions()); 46 | $headers = [ResponseMediator::CONTENT_TYPE_HEADER => \sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())]; 47 | 48 | return $this->postRaw($uri, $builder->build(), $headers); 49 | } 50 | 51 | public function workspaces(string $workspace): SnippetsWorkspaces 52 | { 53 | return new SnippetsWorkspaces($this->getClient(), $workspace); 54 | } 55 | 56 | /** 57 | * Build the snippets URI from the given parts. 58 | */ 59 | protected function buildSnippetsUri(string ...$parts): string 60 | { 61 | return UriBuilder::build('snippets', ...$parts); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Api/Snippets/AbstractSnippetsApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets; 15 | 16 | use Bitbucket\Api\AbstractApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract snippets API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractSnippetsApi extends AbstractApi 25 | { 26 | protected readonly string $workspace; 27 | 28 | public function __construct(Client $client, string $workspace) 29 | { 30 | parent::__construct($client); 31 | $this->workspace = $workspace; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Snippets/Workspaces.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets; 15 | 16 | use Bitbucket\Api\Snippets\Workspaces\Comments; 17 | use Bitbucket\Api\Snippets\Workspaces\Commits; 18 | use Bitbucket\Api\Snippets\Workspaces\Diffs; 19 | use Bitbucket\Api\Snippets\Workspaces\Files; 20 | use Bitbucket\Api\Snippets\Workspaces\Patches; 21 | use Bitbucket\Api\Snippets\Workspaces\Watchers; 22 | use Bitbucket\Api\Snippets\Workspaces\Watching; 23 | use Bitbucket\HttpClient\Message\FileResource; 24 | use Bitbucket\HttpClient\Message\ResponseMediator; 25 | use Bitbucket\HttpClient\Util\UriBuilder; 26 | use Http\Message\MultipartStream\MultipartStreamBuilder; 27 | 28 | /** 29 | * The workspaces API class. 30 | * 31 | * @author Graham Campbell 32 | */ 33 | class Workspaces extends AbstractSnippetsApi 34 | { 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function list(array $params = []): array 39 | { 40 | $uri = $this->buildWorkspacesUri(); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function create(FileResource $file): array 49 | { 50 | $uri = $this->buildWorkspacesUri(); 51 | $builder = (new MultipartStreamBuilder())->addResource($file->getName(), $file->getResource(), $file->getOptions()); 52 | $headers = [ResponseMediator::CONTENT_TYPE_HEADER => \sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())]; 53 | 54 | return $this->postRaw($uri, $builder->build(), $headers); 55 | } 56 | 57 | /** 58 | * @throws \Http\Client\Exception 59 | */ 60 | public function show(string $snippet, array $params = []): array 61 | { 62 | $uri = $this->buildWorkspacesUri($snippet); 63 | 64 | return $this->get($uri, $params); 65 | } 66 | 67 | /** 68 | * @throws \Http\Client\Exception 69 | */ 70 | public function update(string $snippet, array $params = []): array 71 | { 72 | $uri = $this->buildWorkspacesUri($snippet); 73 | 74 | return $this->post($uri, $params); 75 | } 76 | 77 | /** 78 | * @param \Bitbucket\HttpClient\Message\FileResource[] $files 79 | * 80 | * @throws \Http\Client\Exception 81 | */ 82 | public function updateFiles(string $snippet, array $files): array 83 | { 84 | $uri = $this->buildWorkspacesUri($snippet); 85 | 86 | $builder = new MultipartStreamBuilder(); 87 | 88 | foreach ($files as $file) { 89 | $builder->addResource($file->getName(), $file->getResource(), $file->getOptions()); 90 | } 91 | 92 | $headers = [ResponseMediator::CONTENT_TYPE_HEADER => \sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())]; 93 | 94 | return $this->postRaw($uri, $builder->build(), $headers); 95 | } 96 | 97 | /** 98 | * @throws \Http\Client\Exception 99 | */ 100 | public function remove(string $snippet, array $params = []): array 101 | { 102 | $uri = $this->buildWorkspacesUri($snippet); 103 | 104 | return $this->delete($uri, $params); 105 | } 106 | 107 | public function comments(string $snippet): Comments 108 | { 109 | return new Comments($this->getClient(), $this->workspace, $snippet); 110 | } 111 | 112 | public function commits(string $snippet): Commits 113 | { 114 | return new Commits($this->getClient(), $this->workspace, $snippet); 115 | } 116 | 117 | public function diffs(string $snippet): Diffs 118 | { 119 | return new Diffs($this->getClient(), $this->workspace, $snippet); 120 | } 121 | 122 | public function files(string $snippet): Files 123 | { 124 | return new Files($this->getClient(), $this->workspace, $snippet); 125 | } 126 | 127 | public function patches(string $snippet): Patches 128 | { 129 | return new Patches($this->getClient(), $this->workspace, $snippet); 130 | } 131 | 132 | public function watchers(string $snippet): Watchers 133 | { 134 | return new Watchers($this->getClient(), $this->workspace, $snippet); 135 | } 136 | 137 | public function watching(string $snippet): Watching 138 | { 139 | return new Watching($this->getClient(), $this->workspace, $snippet); 140 | } 141 | 142 | /** 143 | * Build the workspaces URI from the given parts. 144 | */ 145 | protected function buildWorkspacesUri(string ...$parts): string 146 | { 147 | return UriBuilder::build('snippets', $this->workspace, ...$parts); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/Api/Snippets/Workspaces/AbstractWorkspacesApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets\Workspaces; 15 | 16 | use Bitbucket\Api\Snippets\AbstractSnippetsApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract workspaces API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractWorkspacesApi extends AbstractSnippetsApi 25 | { 26 | protected readonly string $snippet; 27 | 28 | public function __construct(Client $client, string $workspace, string $snippet) 29 | { 30 | parent::__construct($client, $workspace); 31 | $this->snippet = $snippet; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Snippets/Workspaces/Comments.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The comments API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Comments extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildCommentsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildCommentsUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $comment, array $params = []): array 49 | { 50 | $uri = $this->buildCommentsUri($comment); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $comment, array $params = []): array 59 | { 60 | $uri = $this->buildCommentsUri($comment); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $comment, array $params = []): array 69 | { 70 | $uri = $this->buildCommentsUri($comment); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the comments URI from the given parts. 77 | */ 78 | protected function buildCommentsUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('snippets', $this->workspace, $this->snippet, 'comments', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Snippets/Workspaces/Commits.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The commits API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Commits extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildCommitsUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $commit, array $params = []): array 39 | { 40 | $uri = $this->buildCommitsUri($commit); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * Build the commits URI from the given parts. 47 | */ 48 | protected function buildCommitsUri(string ...$parts): string 49 | { 50 | return UriBuilder::build('snippets', $this->workspace, $this->snippet, 'commits', ...$parts); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Api/Snippets/Workspaces/Diffs.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The diffs API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Diffs extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function download(string $commit, array $params = []): \Psr\Http\Message\StreamInterface 29 | { 30 | $uri = $this->buildDiffsUri($commit, 'diff'); 31 | 32 | return $this->getAsResponse($uri, $params, ['Accept' => 'text/plain'])->getBody(); 33 | } 34 | 35 | /** 36 | * Build the diffs URI from the given parts. 37 | */ 38 | protected function buildDiffsUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('snippets', $this->workspace, $this->snippet, ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Snippets/Workspaces/Files.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Message\ResponseMediator; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | use Http\Message\MultipartStream\MultipartStreamBuilder; 19 | 20 | /** 21 | * The files API class. 22 | * 23 | * @author Graham Campbell 24 | */ 25 | class Files extends AbstractWorkspacesApi 26 | { 27 | /** 28 | * @throws \Http\Client\Exception 29 | */ 30 | public function show(string $commit, array $params = []): array 31 | { 32 | $uri = $this->buildFilesUri($commit); 33 | 34 | return $this->get($uri, $params); 35 | } 36 | 37 | /** 38 | * @throws \Http\Client\Exception 39 | */ 40 | public function download(string $commit, string $uri, array $params = []): \Psr\Http\Message\StreamInterface 41 | { 42 | $uri = $this->buildFilesUri($commit, 'files', ...\explode('/', $uri)); 43 | 44 | return $this->getAsResponse($uri, $params, ['Accept' => '*/*'])->getBody(); 45 | } 46 | 47 | /** 48 | * @throws \Http\Client\Exception 49 | */ 50 | public function update(string $commit, array $params = []): array 51 | { 52 | $uri = $this->buildFilesUri($commit); 53 | 54 | return $this->post($uri, $params); 55 | } 56 | 57 | /** 58 | * @param \Bitbucket\HttpClient\Message\FileResource[] $files 59 | * 60 | * @throws \Http\Client\Exception 61 | */ 62 | public function updateFiles(string $commit, array $files): array 63 | { 64 | $uri = $this->buildFilesUri($commit); 65 | 66 | $builder = new MultipartStreamBuilder(); 67 | 68 | foreach ($files as $file) { 69 | $builder->addResource($file->getName(), $file->getResource(), $file->getOptions()); 70 | } 71 | 72 | $headers = [ResponseMediator::CONTENT_TYPE_HEADER => \sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())]; 73 | 74 | return $this->postRaw($uri, $builder->build(), $headers); 75 | } 76 | 77 | /** 78 | * @throws \Http\Client\Exception 79 | */ 80 | public function remove(string $commit, array $params = []): array 81 | { 82 | $uri = $this->buildFilesUri($commit); 83 | 84 | return $this->delete($uri, $params); 85 | } 86 | 87 | /** 88 | * Build the files URI from the given parts. 89 | */ 90 | protected function buildFilesUri(string ...$parts): string 91 | { 92 | return UriBuilder::build('snippets', $this->workspace, $this->snippet, ...$parts); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Api/Snippets/Workspaces/Patches.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The patches API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Patches extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function download(string $commit, array $params = []): \Psr\Http\Message\StreamInterface 29 | { 30 | $uri = $this->buildPatchesUri($commit, 'patch'); 31 | 32 | return $this->getAsResponse($uri, $params, ['Accept' => 'text/plain'])->getBody(); 33 | } 34 | 35 | /** 36 | * Build the patches URI from the given parts. 37 | */ 38 | protected function buildPatchesUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('snippets', $this->workspace, $this->snippet, ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Snippets/Workspaces/Watchers.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The watchers API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Watchers extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildWatchersUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the watchers URI from the given parts. 37 | */ 38 | protected function buildWatchersUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('snippets', $this->workspace, $this->snippet, 'watchers', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Snippets/Workspaces/Watching.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Snippets\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The watching API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Watching extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function check(array $params = []): array 29 | { 30 | $uri = $this->buildWatchingUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function watch(array $params = []): array 39 | { 40 | $uri = $this->buildWatchingUri(); 41 | 42 | return $this->put($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function ignore(array $params = []): array 49 | { 50 | $uri = $this->buildWatchingUri(); 51 | 52 | return $this->delete($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the watching URI from the given parts. 57 | */ 58 | protected function buildWatchingUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('snippets', $this->workspace, $this->snippet, 'watch', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Users.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api; 15 | 16 | use Bitbucket\Api\Users\Properties; 17 | use Bitbucket\Api\Users\Repositories as UsersRepositories; 18 | use Bitbucket\Api\Users\SshKeys; 19 | use Bitbucket\Client; 20 | use Bitbucket\HttpClient\Util\UriBuilder; 21 | 22 | /** 23 | * The users API class. 24 | * 25 | * @author Graham Campbell 26 | */ 27 | class Users extends AbstractApi 28 | { 29 | protected readonly string $username; 30 | 31 | public function __construct(Client $client, string $username) 32 | { 33 | parent::__construct($client); 34 | $this->username = $username; 35 | } 36 | 37 | public function properties(): Properties 38 | { 39 | return new Properties($this->getClient(), $this->username); 40 | } 41 | 42 | public function repositories(): UsersRepositories 43 | { 44 | return new UsersRepositories($this->getClient(), $this->username); 45 | } 46 | 47 | public function sshKeys(): SshKeys 48 | { 49 | return new SshKeys($this->getClient(), $this->username); 50 | } 51 | 52 | /** 53 | * Build the users URI from the given parts. 54 | */ 55 | protected function buildUsersUri(string ...$parts): string 56 | { 57 | return UriBuilder::build('users', $this->username, ...$parts); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Api/Users/AbstractUsersApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Users; 15 | 16 | use Bitbucket\Api\AbstractApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract user API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractUsersApi extends AbstractApi 25 | { 26 | protected readonly string $username; 27 | 28 | public function __construct(Client $client, string $username) 29 | { 30 | parent::__construct($client); 31 | $this->username = $username; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Users/Properties.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Users; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The properties API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Properties extends AbstractUsersApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function show(string $app, string $property, array $params = []): array 29 | { 30 | $uri = $this->buildPropertiesUri($app, $property); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function update(string $app, string $property, array $params = []): array 39 | { 40 | $uri = $this->buildPropertiesUri($app, $property); 41 | 42 | return $this->put($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function remove(string $app, string $property, array $params = []): array 49 | { 50 | $uri = $this->buildPropertiesUri($app, $property); 51 | 52 | return $this->delete($uri, $params); 53 | } 54 | 55 | /** 56 | * Build the properties URI from the given parts. 57 | */ 58 | protected function buildPropertiesUri(string ...$parts): string 59 | { 60 | return UriBuilder::build('users', $this->username, 'properties', ...$parts); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Api/Users/Repositories.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Users; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The repositories API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Repositories extends AbstractUsersApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildRepositoriesUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * Build the repositories URI from the given parts. 37 | */ 38 | protected function buildRepositoriesUri(string ...$parts): string 39 | { 40 | return UriBuilder::build('users', $this->username, 'repositories', ...$parts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Api/Users/SshKeys.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Users; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The ssh keys API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class SshKeys extends AbstractUsersApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildSshKeysUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = UriBuilder::appendSeparator($this->buildSshKeysUri()); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $id, array $params = []): array 49 | { 50 | $uri = $this->buildSshKeysUri($id); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $id, array $params = []): array 59 | { 60 | $uri = $this->buildSshKeysUri($id); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $id, array $params = []): array 69 | { 70 | $uri = $this->buildSshKeysUri($id); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the ssh keys URI from the given parts. 77 | */ 78 | protected function buildSshKeysUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('users', $this->username, 'ssh-keys', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Workspaces.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api; 15 | 16 | use Bitbucket\Api\Workspaces\Hooks; 17 | use Bitbucket\Api\Workspaces\Members; 18 | use Bitbucket\Api\Workspaces\Permissions; 19 | use Bitbucket\Api\Workspaces\PipelinesConfig; 20 | use Bitbucket\Api\Workspaces\Projects; 21 | use Bitbucket\Client; 22 | use Bitbucket\HttpClient\Util\UriBuilder; 23 | 24 | /** 25 | * The workspaces API class. 26 | * 27 | * @author Graham Campbell 28 | */ 29 | class Workspaces extends AbstractApi 30 | { 31 | protected readonly string $workspace; 32 | 33 | public function __construct(Client $client, string $workspace) 34 | { 35 | parent::__construct($client); 36 | $this->workspace = $workspace; 37 | } 38 | 39 | /** 40 | * @throws \Http\Client\Exception 41 | */ 42 | public function show(array $params = []): array 43 | { 44 | $uri = $this->buildWorkspacesUri(); 45 | 46 | return $this->get($uri, $params); 47 | } 48 | 49 | /** 50 | * @throws \Http\Client\Exception 51 | */ 52 | public function codeSearch(array $params = []): array 53 | { 54 | $uri = $this->buildWorkspacesUri('search', 'code'); 55 | 56 | return $this->get($uri, $params); 57 | } 58 | 59 | public function hooks(): Hooks 60 | { 61 | return new Hooks($this->getClient(), $this->workspace); 62 | } 63 | 64 | public function members(): Members 65 | { 66 | return new Members($this->getClient(), $this->workspace); 67 | } 68 | 69 | public function permissions(): Permissions 70 | { 71 | return new Permissions($this->getClient(), $this->workspace); 72 | } 73 | 74 | public function pipelinesConfig(): PipelinesConfig 75 | { 76 | return new PipelinesConfig($this->getClient(), $this->workspace); 77 | } 78 | 79 | public function projects(): Projects 80 | { 81 | return new Projects($this->getClient(), $this->workspace); 82 | } 83 | 84 | /** 85 | * Build the workspaces URI from the given parts. 86 | */ 87 | protected function buildWorkspacesUri(string ...$parts): string 88 | { 89 | return UriBuilder::build('workspaces', $this->workspace, ...$parts); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Api/Workspaces/AbstractWorkspacesApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces; 15 | 16 | use Bitbucket\Api\AbstractApi; 17 | use Bitbucket\Client; 18 | 19 | /** 20 | * The abstract workspace API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | abstract class AbstractWorkspacesApi extends AbstractApi 25 | { 26 | protected readonly string $workspace; 27 | 28 | public function __construct(Client $client, string $workspace) 29 | { 30 | parent::__construct($client); 31 | $this->workspace = $workspace; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Api/Workspaces/Hooks.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The hooks API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Hooks extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildHooksUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = $this->buildHooksUri(); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $hook, array $params = []): array 49 | { 50 | $uri = $this->buildHooksUri($hook); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $hook, array $params = []): array 59 | { 60 | $uri = $this->buildHooksUri($hook); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $hook, array $params = []): array 69 | { 70 | $uri = $this->buildHooksUri($hook); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the hooks URI from the given parts. 77 | */ 78 | protected function buildHooksUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('workspaces', $this->workspace, 'hooks', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Workspaces/Members.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The members API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Members extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = $this->buildMembersUri(); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $member, array $params = []): array 39 | { 40 | $uri = $this->buildMembersUri($member); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * Build the members URI from the given parts. 47 | */ 48 | protected function buildMembersUri(string ...$parts): string 49 | { 50 | return UriBuilder::build('workspaces', $this->workspace, 'members', ...$parts); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Api/Workspaces/Permissions.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces; 15 | 16 | use Bitbucket\Api\Workspaces\Permissions\Repositories; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | 19 | /** 20 | * The permissions API class. 21 | * 22 | * @author Patrick Barsallo 23 | * @author Graham Campbell 24 | */ 25 | class Permissions extends AbstractWorkspacesApi 26 | { 27 | /** 28 | * @throws \Http\Client\Exception 29 | */ 30 | public function list(array $params = []): array 31 | { 32 | $uri = $this->buildPermissionsUri(); 33 | 34 | return $this->get($uri, $params); 35 | } 36 | 37 | public function repositories(): Repositories 38 | { 39 | return new Repositories($this->getClient(), $this->workspace); 40 | } 41 | 42 | /** 43 | * Build the permissions URI from the given parts. 44 | */ 45 | protected function buildPermissionsUri(string ...$parts): string 46 | { 47 | return UriBuilder::build('workspaces', $this->workspace, 'permissions', ...$parts); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Api/Workspaces/Permissions/AbstractPermissionsApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces\Permissions; 15 | 16 | use Bitbucket\Api\Workspaces\AbstractWorkspacesApi; 17 | 18 | /** 19 | * The abstract permissions API class. 20 | * 21 | * @author Patrick Barsallo 22 | */ 23 | abstract class AbstractPermissionsApi extends AbstractWorkspacesApi 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/Workspaces/Permissions/Repositories.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces\Permissions; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The repositories API class. 20 | * 21 | * @author Patrick Barsallo 22 | */ 23 | class Repositories extends AbstractPermissionsApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildRepositoriesUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function show(string $repo, array $params = []): array 39 | { 40 | $uri = $this->buildRepositoriesUri($repo); 41 | 42 | return $this->get($uri, $params); 43 | } 44 | 45 | /** 46 | * Build the repositories URI from the given parts. 47 | */ 48 | protected function buildRepositoriesUri(string ...$parts): string 49 | { 50 | return UriBuilder::build('workspaces', $this->workspace, 'permissions', 'repositories', ...$parts); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Api/Workspaces/PipelinesConfig.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces; 15 | 16 | use Bitbucket\Api\Workspaces\PipelinesConfig\Variables; 17 | use Bitbucket\HttpClient\Util\UriBuilder; 18 | 19 | /** 20 | * The pipelines config API class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | class PipelinesConfig extends AbstractWorkspacesApi 25 | { 26 | public function variables(): Variables 27 | { 28 | return new Variables($this->getClient(), $this->workspace); 29 | } 30 | 31 | /** 32 | * Build the pipelines config URI from the given parts. 33 | */ 34 | protected function buildPipelinesConfigUri(string ...$parts): string 35 | { 36 | return UriBuilder::build('workspaces', $this->workspace, 'pipelines_config', ...$parts); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Api/Workspaces/PipelinesConfig/AbstractPipelinesConfigApi.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces\PipelinesConfig; 15 | 16 | use Bitbucket\Api\Workspaces\AbstractWorkspacesApi; 17 | 18 | /** 19 | * The abstract pipelines config API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | abstract class AbstractPipelinesConfigApi extends AbstractWorkspacesApi 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/Workspaces/PipelinesConfig/Variables.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces\PipelinesConfig; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The variables API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Variables extends AbstractPipelinesConfigApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildVariablesUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = UriBuilder::appendSeparator($this->buildVariablesUri()); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $variable, array $params = []): array 49 | { 50 | $uri = $this->buildVariablesUri($variable); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $variable, array $params = []): array 59 | { 60 | $uri = $this->buildVariablesUri($variable); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $variable, array $params = []): array 69 | { 70 | $uri = $this->buildVariablesUri($variable); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the variables URI from the given parts. 77 | */ 78 | protected function buildVariablesUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('workspaces', $this->workspace, 'pipelines-config', 'variables', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Api/Workspaces/Projects.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Api\Workspaces; 15 | 16 | use Bitbucket\HttpClient\Util\UriBuilder; 17 | 18 | /** 19 | * The projects API class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Projects extends AbstractWorkspacesApi 24 | { 25 | /** 26 | * @throws \Http\Client\Exception 27 | */ 28 | public function list(array $params = []): array 29 | { 30 | $uri = UriBuilder::appendSeparator($this->buildProjectsUri()); 31 | 32 | return $this->get($uri, $params); 33 | } 34 | 35 | /** 36 | * @throws \Http\Client\Exception 37 | */ 38 | public function create(array $params = []): array 39 | { 40 | $uri = UriBuilder::appendSeparator($this->buildProjectsUri()); 41 | 42 | return $this->post($uri, $params); 43 | } 44 | 45 | /** 46 | * @throws \Http\Client\Exception 47 | */ 48 | public function show(string $project, array $params = []): array 49 | { 50 | $uri = $this->buildProjectsUri($project); 51 | 52 | return $this->get($uri, $params); 53 | } 54 | 55 | /** 56 | * @throws \Http\Client\Exception 57 | */ 58 | public function update(string $project, array $params = []): array 59 | { 60 | $uri = $this->buildProjectsUri($project); 61 | 62 | return $this->put($uri, $params); 63 | } 64 | 65 | /** 66 | * @throws \Http\Client\Exception 67 | */ 68 | public function remove(string $project, array $params = []): array 69 | { 70 | $uri = $this->buildProjectsUri($project); 71 | 72 | return $this->delete($uri, $params); 73 | } 74 | 75 | /** 76 | * Build the projects URI from the given parts. 77 | */ 78 | protected function buildProjectsUri(string ...$parts): string 79 | { 80 | return UriBuilder::build('workspaces', $this->workspace, 'projects', ...$parts); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Exception/ApiLimitExceededException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Exception; 15 | 16 | /** 17 | * @author Graham Campbell 18 | */ 19 | class ApiLimitExceededException extends RuntimeException 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /src/Exception/ErrorException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Exception; 15 | 16 | /** 17 | * @author Graham Campbell 18 | */ 19 | class ErrorException extends \ErrorException implements ExceptionInterface 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /src/Exception/ExceptionInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Exception; 15 | 16 | use Http\Client\Exception; 17 | 18 | /** 19 | * @author Graham Campbell 20 | */ 21 | interface ExceptionInterface extends Exception 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/RuntimeException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Exception; 15 | 16 | /** 17 | * @author Graham Campbell 18 | */ 19 | class RuntimeException extends \RuntimeException implements ExceptionInterface 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /src/Exception/ValidationFailedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\Exception; 15 | 16 | /** 17 | * @author Graham Campbell 18 | */ 19 | class ValidationFailedException extends ErrorException 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /src/HttpClient/Builder.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\HttpClient; 15 | 16 | use Http\Client\Common\HttpMethodsClient; 17 | use Http\Client\Common\HttpMethodsClientInterface; 18 | use Http\Client\Common\Plugin; 19 | use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator; 20 | use Http\Client\Common\Plugin\CachePlugin; 21 | use Http\Client\Common\PluginClientFactory; 22 | use Http\Discovery\Psr17FactoryDiscovery; 23 | use Http\Discovery\Psr18ClientDiscovery; 24 | use Psr\Cache\CacheItemPoolInterface; 25 | use Psr\Http\Client\ClientInterface; 26 | use Psr\Http\Message\RequestFactoryInterface; 27 | use Psr\Http\Message\StreamFactoryInterface; 28 | 29 | /** 30 | * The HTTP client builder class. 31 | * 32 | * This will allow you to fluently add and remove plugins. 33 | * 34 | * @author Tobias Nyholm 35 | * @author Graham Campbell 36 | */ 37 | final class Builder 38 | { 39 | private readonly ClientInterface $httpClient; 40 | private readonly RequestFactoryInterface $requestFactory; 41 | private readonly StreamFactoryInterface $streamFactory; 42 | 43 | /** 44 | * @var Plugin[] 45 | */ 46 | private array $plugins = []; 47 | 48 | private ?CachePlugin $cachePlugin; 49 | 50 | private ?HttpMethodsClientInterface $pluginClient; 51 | 52 | public function __construct( 53 | ?ClientInterface $httpClient = null, 54 | ?RequestFactoryInterface $requestFactory = null, 55 | ?StreamFactoryInterface $streamFactory = null, 56 | ) { 57 | $this->httpClient = $httpClient ?? Psr18ClientDiscovery::find(); 58 | $this->requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory(); 59 | $this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory(); 60 | 61 | $this->plugins = []; 62 | $this->cachePlugin = null; 63 | $this->pluginClient = null; 64 | } 65 | 66 | public function getHttpClient(): HttpMethodsClientInterface 67 | { 68 | if (null === $this->pluginClient) { 69 | $plugins = $this->plugins; 70 | if (null !== $this->cachePlugin) { 71 | $plugins[] = $this->cachePlugin; 72 | } 73 | 74 | $this->pluginClient = new HttpMethodsClient( 75 | (new PluginClientFactory())->createClient($this->httpClient, $plugins), 76 | $this->requestFactory, 77 | $this->streamFactory 78 | ); 79 | } 80 | 81 | return $this->pluginClient; 82 | } 83 | 84 | /** 85 | * Add a new plugin to the end of the plugin chain. 86 | */ 87 | public function addPlugin(Plugin $plugin): void 88 | { 89 | $this->plugins[] = $plugin; 90 | $this->pluginClient = null; 91 | } 92 | 93 | /** 94 | * Remove a plugin by its fully qualified class name (FQCN). 95 | */ 96 | public function removePlugin(string $fqcn): void 97 | { 98 | foreach ($this->plugins as $idx => $plugin) { 99 | if ($plugin instanceof $fqcn) { 100 | unset($this->plugins[$idx]); 101 | $this->pluginClient = null; 102 | } 103 | } 104 | } 105 | 106 | /** 107 | * Add a cache plugin to cache responses locally. 108 | */ 109 | public function addCache(CacheItemPoolInterface $cachePool, array $config = []): void 110 | { 111 | if (!isset($config['cache_key_generator'])) { 112 | $config['cache_key_generator'] = new HeaderCacheKeyGenerator(['Authorization', 'Cookie', 'Accept', 'Content-type']); 113 | } 114 | 115 | $this->cachePlugin = CachePlugin::clientCache($cachePool, $this->streamFactory, $config); 116 | $this->pluginClient = null; 117 | } 118 | 119 | /** 120 | * Remove the cache plugin. 121 | */ 122 | public function removeCache(): void 123 | { 124 | $this->cachePlugin = null; 125 | $this->pluginClient = null; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/HttpClient/Message/FileResource.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\HttpClient\Message; 15 | 16 | use Psr\Http\Message\StreamInterface; 17 | 18 | /** 19 | * This is the file resource class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | final class FileResource 24 | { 25 | /** 26 | * Create a new file resource instance. 27 | * 28 | * @param string|resource|StreamInterface $resource 29 | * 30 | * @return void 31 | */ 32 | public function __construct( 33 | private readonly string $name, 34 | private readonly mixed $resource, 35 | private readonly array $options = [], 36 | ) { 37 | } 38 | 39 | /** 40 | * Get the name. 41 | */ 42 | public function getName(): string 43 | { 44 | return $this->name; 45 | } 46 | 47 | /** 48 | * Get the resource. 49 | * 50 | * @return string|resource|StreamInterface 51 | */ 52 | public function getResource() 53 | { 54 | return $this->resource; 55 | } 56 | 57 | /** 58 | * Get the options. 59 | */ 60 | public function getOptions(): array 61 | { 62 | return $this->options; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/HttpClient/Message/ResponseMediator.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\HttpClient\Message; 15 | 16 | use Bitbucket\Exception\RuntimeException; 17 | use Bitbucket\HttpClient\Util\JsonArray; 18 | use Psr\Http\Message\ResponseInterface; 19 | 20 | /** 21 | * This is the response mediator class. 22 | * 23 | * @author Graham Campbell 24 | */ 25 | final class ResponseMediator 26 | { 27 | /** 28 | * The content type header. 29 | * 30 | * @var string 31 | */ 32 | public const CONTENT_TYPE_HEADER = 'Content-Type'; 33 | 34 | /** 35 | * The JSON content type identifier. 36 | * 37 | * @var string 38 | */ 39 | public const JSON_CONTENT_TYPE = 'application/json'; 40 | 41 | /** 42 | * Get the decoded response content. 43 | * 44 | * If the there is no response body, we will always return the empty array. 45 | * 46 | * @throws \Bitbucket\Exception\RuntimeException 47 | */ 48 | public static function getContent(ResponseInterface $response): array 49 | { 50 | if (204 === $response->getStatusCode()) { 51 | return []; 52 | } 53 | 54 | $body = (string) $response->getBody(); 55 | 56 | if ('' === $body) { 57 | return []; 58 | } 59 | 60 | if (0 !== \strpos($response->getHeaderLine(self::CONTENT_TYPE_HEADER), self::JSON_CONTENT_TYPE)) { 61 | throw new RuntimeException(\sprintf('The content type was not %s.', self::JSON_CONTENT_TYPE)); 62 | } 63 | 64 | return JsonArray::decode($body); 65 | } 66 | 67 | /** 68 | * Get the pagination data from the response. 69 | * 70 | * @return array 71 | */ 72 | public static function getPagination(ResponseInterface $response): array 73 | { 74 | try { 75 | /** @var array */ 76 | return \array_filter(self::getContent($response), [self::class, 'paginationFilter'], \ARRAY_FILTER_USE_KEY); 77 | } catch (RuntimeException $e) { 78 | return []; 79 | } 80 | } 81 | 82 | private static function paginationFilter(string|int $key): bool 83 | { 84 | return \in_array($key, ['size', 'page', 'pagelen', 'next', 'previous'], true); 85 | } 86 | 87 | /** 88 | * Get the error message from the response if present. 89 | */ 90 | public static function getErrorMessage(ResponseInterface $response): ?string 91 | { 92 | try { 93 | /** @var scalar|array */ 94 | $error = self::getContent($response)['error'] ?? null; 95 | } catch (RuntimeException $e) { 96 | return null; 97 | } 98 | 99 | return \is_array($error) ? self::getMessageFromError($error) : null; 100 | } 101 | 102 | /** 103 | * Get the error message from the error array if present. 104 | */ 105 | private static function getMessageFromError(array $error): ?string 106 | { 107 | /** @var scalar|array */ 108 | $message = $error['message'] ?? ''; 109 | 110 | if (!\is_string($message)) { 111 | return null; 112 | } 113 | 114 | $detail = self::getDetailAsString($error); 115 | 116 | if ('' !== $message) { 117 | return '' !== $detail ? \sprintf('%s: %s', $message, $detail) : $message; 118 | } 119 | 120 | if ('' !== $detail) { 121 | return $detail; 122 | } 123 | 124 | return null; 125 | } 126 | 127 | /** 128 | * Present the detail portion of the error array. 129 | */ 130 | private static function getDetailAsString(array $error): string 131 | { 132 | /** @var string|array $detail */ 133 | $detail = $error['detail'] ?? ''; 134 | 135 | if ('' === $detail || [] === $detail) { 136 | return ''; 137 | } 138 | 139 | return (string) \strtok(\is_string($detail) ? $detail : JsonArray::encode($detail), "\n"); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/HttpClient/Plugin/Authentication.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\HttpClient\Plugin; 15 | 16 | use Bitbucket\Client; 17 | use Bitbucket\Exception\RuntimeException; 18 | use Http\Client\Common\Plugin; 19 | use Http\Promise\Promise; 20 | use Psr\Http\Message\RequestInterface; 21 | use Psr\Http\Message\ResponseInterface; 22 | 23 | /** 24 | * A plugin to add authentication to the request. 25 | * 26 | * @internal 27 | * 28 | * @author Tobias Nyholm 29 | * @author Graham Campbell 30 | */ 31 | final class Authentication implements Plugin 32 | { 33 | private readonly string $header; 34 | 35 | public function __construct(string $method, string $token, ?string $password = null) 36 | { 37 | $this->header = self::buildAuthorizationHeader($method, $token, $password); 38 | } 39 | 40 | /** 41 | * Handle the request and return the response coming from the next callable. 42 | * 43 | * @param callable(RequestInterface): Promise $next 44 | * @param callable(RequestInterface): Promise $first 45 | * 46 | * @return \Http\Promise\Promise 47 | */ 48 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise 49 | { 50 | $request = $request->withHeader('Authorization', $this->header); 51 | 52 | return $next($request); 53 | } 54 | 55 | /** 56 | * Build the authentication header to be attached to the request. 57 | * 58 | * @throws \Bitbucket\Exception\RuntimeException 59 | */ 60 | private static function buildAuthorizationHeader(string $method, string $token, ?string $password = null): string 61 | { 62 | switch ($method) { 63 | case Client::AUTH_HTTP_PASSWORD: 64 | if (null === $password) { 65 | throw new RuntimeException(\sprintf('Authentication method "%s" requires a password to be set.', $method)); 66 | } 67 | 68 | return \sprintf('Basic %s', \base64_encode(\sprintf('%s:%s', $token, $password))); 69 | case Client::AUTH_OAUTH_TOKEN: 70 | return \sprintf('Bearer %s', $token); 71 | case Client::AUTH_JWT: 72 | return \sprintf('JWT %s', $token); 73 | } 74 | 75 | throw new RuntimeException(\sprintf('Authentication method "%s" not implemented.', $method)); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/HttpClient/Plugin/ExceptionThrower.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\HttpClient\Plugin; 15 | 16 | use Bitbucket\Exception\ApiLimitExceededException; 17 | use Bitbucket\Exception\ExceptionInterface; 18 | use Bitbucket\Exception\RuntimeException; 19 | use Bitbucket\Exception\ValidationFailedException; 20 | use Bitbucket\HttpClient\Message\ResponseMediator; 21 | use Http\Client\Common\Plugin; 22 | use Http\Promise\Promise; 23 | use Psr\Http\Message\RequestInterface; 24 | use Psr\Http\Message\ResponseInterface; 25 | 26 | /** 27 | * A plugin to throw bitbucket exceptions. 28 | * 29 | * @internal 30 | * 31 | * @author Tobias Nyholm 32 | * @author Fabien Bourigault 33 | * @author Graham Campbell 34 | */ 35 | final class ExceptionThrower implements Plugin 36 | { 37 | /** 38 | * Handle the request and return the response coming from the next callable. 39 | * 40 | * @param callable(RequestInterface): Promise $next 41 | * @param callable(RequestInterface): Promise $first 42 | * 43 | * @return \Http\Promise\Promise 44 | */ 45 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise 46 | { 47 | return $next($request)->then(function (ResponseInterface $response): ResponseInterface { 48 | $status = $response->getStatusCode(); 49 | 50 | if ($status >= 400 && $status < 600) { 51 | throw self::createException($status, ResponseMediator::getErrorMessage($response) ?? $response->getReasonPhrase()); 52 | } 53 | 54 | return $response; 55 | }); 56 | } 57 | 58 | /** 59 | * Create an exception from a status code and error message. 60 | * 61 | * @return \Bitbucket\Exception\ErrorException|\Bitbucket\Exception\RuntimeException 62 | */ 63 | private static function createException(int $status, string $message): ExceptionInterface 64 | { 65 | if (400 === $status || 422 === $status) { 66 | return new ValidationFailedException($message, $status); 67 | } 68 | 69 | if (429 === $status) { 70 | return new ApiLimitExceededException($message, $status); 71 | } 72 | 73 | return new RuntimeException($message, $status); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/HttpClient/Plugin/History.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\HttpClient\Plugin; 15 | 16 | use Http\Client\Common\Plugin\Journal; 17 | use Psr\Http\Client\ClientExceptionInterface; 18 | use Psr\Http\Message\RequestInterface; 19 | use Psr\Http\Message\ResponseInterface; 20 | 21 | /** 22 | * A plugin to remember the last response. 23 | * 24 | * @internal 25 | * 26 | * @author Tobias Nyholm 27 | * @author Graham Campbell 28 | */ 29 | final class History implements Journal 30 | { 31 | private ?ResponseInterface $lastResponse; 32 | 33 | public function __construct() 34 | { 35 | $this->lastResponse = null; 36 | } 37 | 38 | /** 39 | * Get the last response. 40 | */ 41 | public function getLastResponse(): ?ResponseInterface 42 | { 43 | return $this->lastResponse; 44 | } 45 | 46 | /** 47 | * Record a successful call. 48 | */ 49 | public function addSuccess(RequestInterface $request, ResponseInterface $response): void 50 | { 51 | $this->lastResponse = $response; 52 | } 53 | 54 | /** 55 | * Record a failed call. 56 | */ 57 | public function addFailure(RequestInterface $request, ClientExceptionInterface $exception): void 58 | { 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/HttpClient/Util/JsonArray.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\HttpClient\Util; 15 | 16 | use Bitbucket\Exception\RuntimeException; 17 | 18 | /** 19 | * The is the JSON array helper class. 20 | * 21 | * @internal 22 | * 23 | * @author Graham Campbell 24 | */ 25 | final class JsonArray 26 | { 27 | /** 28 | * Decode a JSON string into a PHP array. 29 | * 30 | * @throws \Bitbucket\Exception\RuntimeException 31 | */ 32 | public static function decode(string $json): array 33 | { 34 | /** @var scalar|array|null */ 35 | $data = \json_decode($json, true); 36 | 37 | if (\JSON_ERROR_NONE !== \json_last_error()) { 38 | throw new RuntimeException(\sprintf('json_decode error: %s', \json_last_error_msg())); 39 | } 40 | 41 | if (null === $data || !\is_array($data)) { 42 | throw new RuntimeException(\sprintf('json_decode error: Expected JSON of type array, %s given.', \get_debug_type($data))); 43 | } 44 | 45 | return $data; 46 | } 47 | 48 | /** 49 | * Encode a PHP array into a JSON string. 50 | * 51 | * @throws \Bitbucket\Exception\RuntimeException 52 | */ 53 | public static function encode(array $value): string 54 | { 55 | $json = \json_encode($value); 56 | 57 | if (\JSON_ERROR_NONE !== \json_last_error()) { 58 | throw new RuntimeException(\sprintf('json_encode error: %s', \json_last_error_msg())); 59 | } 60 | 61 | /** @var string */ 62 | return $json; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/HttpClient/Util/QueryStringBuilder.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\HttpClient\Util; 15 | 16 | /** 17 | * The is the query string builder helper class. 18 | * 19 | * @internal 20 | * 21 | * @author Graham Campbell 22 | */ 23 | final class QueryStringBuilder 24 | { 25 | /** 26 | * Encode a query as a query string according to RFC 3986. 27 | */ 28 | public static function build(array $query): string 29 | { 30 | if (0 === \count($query)) { 31 | return ''; 32 | } 33 | 34 | return \sprintf('?%s', \http_build_query($query, '', '&', \PHP_QUERY_RFC3986)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/HttpClient/Util/UriBuilder.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket\HttpClient\Util; 15 | 16 | use ValueError; 17 | 18 | /** 19 | * The is the URI builder helper class. 20 | * 21 | * @internal 22 | * 23 | * @author Graham Campbell 24 | */ 25 | final class UriBuilder 26 | { 27 | /** 28 | * Build a URI from the given parts. 29 | */ 30 | public static function build(string ...$parts): string 31 | { 32 | /** @var int $index */ 33 | foreach ($parts as $index => $part) { 34 | if ('' === $part) { 35 | throw new ValueError(\sprintf('%s::buildUri(): Argument #%d ($parts) must non-empty', self::class, $index + 1)); 36 | } 37 | 38 | $parts[$index] = \rawurlencode($part); 39 | } 40 | 41 | return \implode('/', $parts); 42 | } 43 | 44 | /** 45 | * Append a URI separator to the given URI. 46 | */ 47 | public static function appendSeparator(string $uri): string 48 | { 49 | return \sprintf('%s%s', $uri, '/'); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/ResultPagerInterface.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace Bitbucket; 15 | 16 | use Bitbucket\Api\AbstractApi; 17 | use Generator; 18 | 19 | /** 20 | * This is the result pager interface. 21 | * 22 | * @author Ramon de la Fuente 23 | * @author Mitchel Verschoof 24 | * @author Graham Campbell 25 | */ 26 | interface ResultPagerInterface 27 | { 28 | /** 29 | * Fetch a single result from an api call. 30 | * 31 | * @throws \Http\Client\Exception 32 | */ 33 | public function fetch(AbstractApi $api, string $method, array $parameters = []): array; 34 | 35 | /** 36 | * Fetch all results from an api call. 37 | * 38 | * @throws \Http\Client\Exception 39 | */ 40 | public function fetchAll(AbstractApi $api, string $method, array $parameters = []): array; 41 | 42 | /** 43 | * Lazily fetch all results from an api call. 44 | * 45 | * @throws \Http\Client\Exception 46 | */ 47 | public function fetchAllLazy(AbstractApi $api, string $method, array $parameters = []): Generator; 48 | 49 | /** 50 | * Check to determine the availability of a next page. 51 | */ 52 | public function hasNext(): bool; 53 | 54 | /** 55 | * Fetch the next page. 56 | * 57 | * @throws \Http\Client\Exception 58 | */ 59 | public function fetchNext(): array; 60 | 61 | /** 62 | * Check to determine the availability of a previous page. 63 | */ 64 | public function hasPrevious(): bool; 65 | 66 | /** 67 | * Fetch the previous page. 68 | * 69 | * @throws \Http\Client\Exception 70 | */ 71 | public function fetchPrevious(): array; 72 | } 73 | --------------------------------------------------------------------------------