From 7762aaa52ecaa2c29e3b94b65d62baeb1b0c1be7 Mon Sep 17 00:00:00 2001 From: Jasper Zonneveld Date: Tue, 11 Feb 2025 10:02:43 +0100 Subject: [PATCH] feat: add support for new "list workspace pull requests for a user" endpoint --- src/Api/PullRequests.php | 2 ++ src/Api/Workspaces.php | 6 +++++ src/Api/Workspaces/PullRequests.php | 42 +++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/Api/Workspaces/PullRequests.php diff --git a/src/Api/PullRequests.php b/src/Api/PullRequests.php index 61293cc..9b37715 100644 --- a/src/Api/PullRequests.php +++ b/src/Api/PullRequests.php @@ -24,6 +24,8 @@ class PullRequests extends AbstractApi { /** * @throws \Http\Client\Exception + * + * @deprecated use the workspaces pull requests instead */ public function list(string $username, array $params = []): array { diff --git a/src/Api/Workspaces.php b/src/Api/Workspaces.php index 2c993b8..2c59dab 100644 --- a/src/Api/Workspaces.php +++ b/src/Api/Workspaces.php @@ -18,6 +18,7 @@ use Bitbucket\Api\Workspaces\Permissions; use Bitbucket\Api\Workspaces\PipelinesConfig; use Bitbucket\Api\Workspaces\Projects; +use Bitbucket\Api\Workspaces\PullRequests as WorkspacesPullRequests; use Bitbucket\Client; use Bitbucket\HttpClient\Util\UriBuilder; @@ -81,6 +82,11 @@ public function projects(): Projects return new Projects($this->getClient(), $this->workspace); } + public function pullRequests(): WorkspacesPullRequests + { + return new WorkspacesPullRequests($this->getClient(), $this->workspace); + } + /** * Build the workspaces URI from the given parts. */ diff --git a/src/Api/Workspaces/PullRequests.php b/src/Api/Workspaces/PullRequests.php new file mode 100644 index 0000000..38534fe --- /dev/null +++ b/src/Api/Workspaces/PullRequests.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Bitbucket\Api\Workspaces; + +use Bitbucket\HttpClient\Util\UriBuilder; + +/** + * The pull requests API class. + * + * @author Graham Campbell + */ +class PullRequests extends AbstractWorkspacesApi +{ + /** + * @throws \Http\Client\Exception + */ + public function list(string $username, array $params = []): array + { + $uri = $this->buildPullRequestsUri($username); + + return $this->get($uri, $params); + } + + /** + * Build the pull requests URI from the given parts. + */ + protected function buildPullRequestsUri(string ...$parts): string + { + return UriBuilder::build('workspaces', $this->workspace, 'pullrequests', ...$parts); + } +}