From 60c74c9e84d363864ebe271326ce23cbf6b80f22 Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Wed, 15 Nov 2023 11:31:35 +0000 Subject: [PATCH] Deprecation: avoid passing json encoded strings to post|put calls --- lib/Bitbucket/API/Repositories/BranchRestrictions.php | 4 ++-- lib/Bitbucket/API/Repositories/Commits/BuildStatuses.php | 4 ++-- lib/Bitbucket/API/Repositories/Hooks.php | 4 ++-- lib/Bitbucket/API/Repositories/Pipelines.php | 2 +- lib/Bitbucket/API/Repositories/PullRequests.php | 8 ++++---- lib/Bitbucket/API/Repositories/PullRequests/Comments.php | 4 ++-- lib/Bitbucket/API/Repositories/Refs/Tags.php | 4 +--- lib/Bitbucket/API/Repositories/Repository.php | 6 +----- lib/Bitbucket/API/Teams/Hooks.php | 4 ++-- lib/Bitbucket/API/Workspaces/Hooks.php | 4 ++-- 10 files changed, 19 insertions(+), 25 deletions(-) diff --git a/lib/Bitbucket/API/Repositories/BranchRestrictions.php b/lib/Bitbucket/API/Repositories/BranchRestrictions.php index eca3226..09ce03f 100644 --- a/lib/Bitbucket/API/Repositories/BranchRestrictions.php +++ b/lib/Bitbucket/API/Repositories/BranchRestrictions.php @@ -86,7 +86,7 @@ public function create($account, $repo, $params = array()) return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/branch-restrictions', $account, $repo), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } @@ -135,7 +135,7 @@ public function update($account, $repo, $id, $params = array()) return $this->getClient()->setApiVersion('2.0')->put( sprintf('/repositories/%s/%s/branch-restrictions/%d', $account, $repo, $id), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } diff --git a/lib/Bitbucket/API/Repositories/Commits/BuildStatuses.php b/lib/Bitbucket/API/Repositories/Commits/BuildStatuses.php index ac9ce5b..35bc712 100644 --- a/lib/Bitbucket/API/Repositories/Commits/BuildStatuses.php +++ b/lib/Bitbucket/API/Repositories/Commits/BuildStatuses.php @@ -53,7 +53,7 @@ public function create($account, $repository, $revision, $params) { return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/commit/%s/statuses/build', $account, $repository, $revision), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } @@ -74,7 +74,7 @@ public function update($account, $repository, $revision, $key, $params) { return $this->getClient()->setApiVersion('2.0')->put( sprintf('/repositories/%s/%s/commit/%s/statuses/build/%s', $account, $repository, $revision, $key), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } diff --git a/lib/Bitbucket/API/Repositories/Hooks.php b/lib/Bitbucket/API/Repositories/Hooks.php index aa1d701..86b7315 100644 --- a/lib/Bitbucket/API/Repositories/Hooks.php +++ b/lib/Bitbucket/API/Repositories/Hooks.php @@ -48,7 +48,7 @@ public function create($account, $repo, array $params = array()) return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/hooks', $account, $repo), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } @@ -83,7 +83,7 @@ public function update($account, $repo, $uuid, array $params = array()) return $this->getClient()->setApiVersion('2.0')->put( sprintf('/repositories/%s/%s/hooks/%s', $account, $repo, $uuid), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } diff --git a/lib/Bitbucket/API/Repositories/Pipelines.php b/lib/Bitbucket/API/Repositories/Pipelines.php index a2f5afd..f93bf22 100644 --- a/lib/Bitbucket/API/Repositories/Pipelines.php +++ b/lib/Bitbucket/API/Repositories/Pipelines.php @@ -59,7 +59,7 @@ public function create($account, $repo, $params = array()) return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/pipelines/', $account, $repo), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } diff --git a/lib/Bitbucket/API/Repositories/PullRequests.php b/lib/Bitbucket/API/Repositories/PullRequests.php index 20206d5..ab43794 100644 --- a/lib/Bitbucket/API/Repositories/PullRequests.php +++ b/lib/Bitbucket/API/Repositories/PullRequests.php @@ -118,7 +118,7 @@ public function create($account, $repo, $params = array()) return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/pullrequests', $account, $repo), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } @@ -168,7 +168,7 @@ public function update($account, $repo, $id, $params = array()) return $this->getClient()->setApiVersion('2.0')->put( sprintf('/repositories/%s/%s/pullrequests/%d', $account, $repo, $id), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } @@ -302,7 +302,7 @@ public function accept($account, $repo, $id, $params = array()) { return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/pullrequests/%d/merge', $account, $repo, $id), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } @@ -324,7 +324,7 @@ public function decline($account, $repo, $id, $params = array()) return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/pullrequests/%d/decline', $account, $repo, $id), - json_encode($params), + $params, array('Content-Type' => 'application/json') ); } diff --git a/lib/Bitbucket/API/Repositories/PullRequests/Comments.php b/lib/Bitbucket/API/Repositories/PullRequests/Comments.php index 4655918..0d1ff65 100644 --- a/lib/Bitbucket/API/Repositories/PullRequests/Comments.php +++ b/lib/Bitbucket/API/Repositories/PullRequests/Comments.php @@ -65,7 +65,7 @@ public function create($account, $repo, $requestID, $content) { return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/pullrequests/%d/comments', $account, $repo, $requestID), - json_encode(array('content' => array('raw' => $content))), + array('content' => array('raw' => $content)), array('Content-Type' => 'application/json') ); } @@ -84,7 +84,7 @@ public function update($account, $repo, $requestID, $commentID, $content) { return $this->getClient()->setApiVersion('2.0')->put( sprintf('/repositories/%s/%s/pullrequests/%d/comments/%d', $account, $repo, $requestID, $commentID), - json_encode(array('content' => array('raw' => $content))), + array('content' => array('raw' => $content)), array('Content-Type' => 'application/json') ); } diff --git a/lib/Bitbucket/API/Repositories/Refs/Tags.php b/lib/Bitbucket/API/Repositories/Refs/Tags.php index ccd3c57..23e0076 100644 --- a/lib/Bitbucket/API/Repositories/Refs/Tags.php +++ b/lib/Bitbucket/API/Repositories/Refs/Tags.php @@ -72,11 +72,9 @@ public function create($account, $repo, $name, $hash) ], ]; - $data = json_encode($params); - return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/refs/tags', $account, $repo), - $data, + $params, array('Content-Type' => 'application/json') ); } diff --git a/lib/Bitbucket/API/Repositories/Repository.php b/lib/Bitbucket/API/Repositories/Repository.php index e4cb9db..49721b4 100644 --- a/lib/Bitbucket/API/Repositories/Repository.php +++ b/lib/Bitbucket/API/Repositories/Repository.php @@ -71,11 +71,9 @@ public function create($account, $repo, $params = array()) $params = $this->decodeJSON($params); } - $params = json_encode(array_merge($defaults, $params)); - return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s', $account, $repo), - $params, + array_merge($defaults, $params), array('Content-Type' => 'application/json') ); } @@ -155,8 +153,6 @@ public function fork($account, $repo, $name, array $params = array()) { $params['name'] = $name; - $params = json_encode($params); - return $this->getClient()->setApiVersion('2.0')->post( sprintf('/repositories/%s/%s/forks', $account, $repo), $params, diff --git a/lib/Bitbucket/API/Teams/Hooks.php b/lib/Bitbucket/API/Teams/Hooks.php index 25b3935..63e695e 100644 --- a/lib/Bitbucket/API/Teams/Hooks.php +++ b/lib/Bitbucket/API/Teams/Hooks.php @@ -33,7 +33,7 @@ public function create($team, array $hookConfiguration) return $this->getClient()->setApiVersion('2.0')->post( sprintf('/teams/%s/hooks', $team), - json_encode($hookConfiguration), + $hookConfiguration, ['Content-Type' => 'application/json'] ); } @@ -65,7 +65,7 @@ public function update($team, $uuid, array $hookConfiguration) return $this->getClient()->setApiVersion('2.0')->put( sprintf('/teams/%s/hooks/%s', $team, $uuid), - json_encode($hookConfiguration), + $hookConfiguration, ['Content-Type' => 'application/json'] ); } diff --git a/lib/Bitbucket/API/Workspaces/Hooks.php b/lib/Bitbucket/API/Workspaces/Hooks.php index 5c3f8ba..9fd3f20 100644 --- a/lib/Bitbucket/API/Workspaces/Hooks.php +++ b/lib/Bitbucket/API/Workspaces/Hooks.php @@ -33,7 +33,7 @@ public function create($workspace, array $hookConfiguration) return $this->getClient()->setApiVersion('2.0')->post( sprintf('/workspaces/%s/hooks', $workspace), - json_encode($hookConfiguration), + $hookConfiguration, ['Content-Type' => 'application/json'] ); } @@ -65,7 +65,7 @@ public function update($workspace, $uuid, array $hookConfiguration) return $this->getClient()->setApiVersion('2.0')->put( sprintf('/workspaces/%s/hooks/%s', $workspace, $uuid), - json_encode($hookConfiguration), + $hookConfiguration, ['Content-Type' => 'application/json'] ); }