From 76ae861ddd9d9ff60238f7d48711772ef3f01e2c Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 13 Aug 2020 10:25:42 -0500 Subject: [PATCH] fix: when using the REST API, send "token" authorization instead of "bearer" Since our GITHUB_TOKEN is a personal access token, it can be used as either an OAuth (bearer) or PAT (token) type for purposes of authorization. However, OAuth requests from actions do not trigger workflow events (see https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token). This patch updates the three different API calls we currently perform (create release, set default branch, create pull request) to use the "token" type for authorization. Signed-off-by: Matthew Weier O'Phinney --- src/Github/Api/V3/CreatePullRequestThroughApiCall.php | 2 +- src/Github/Api/V3/CreateReleaseThroughApiCall.php | 2 +- src/Github/Api/V3/SetDefaultBranchThroughApiCall.php | 2 +- test/unit/Github/Api/V3/CreatePullRequestTest.php | 2 +- test/unit/Github/Api/V3/CreateReleaseTest.php | 2 +- .../unit/Github/Api/V3/SetDefaultBranchThroughApiCallTest.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Github/Api/V3/CreatePullRequestThroughApiCall.php b/src/Github/Api/V3/CreatePullRequestThroughApiCall.php index a3249370..ced40152 100644 --- a/src/Github/Api/V3/CreatePullRequestThroughApiCall.php +++ b/src/Github/Api/V3/CreatePullRequestThroughApiCall.php @@ -48,7 +48,7 @@ public function __invoke( ) ->withAddedHeader('Content-Type', 'application/json') ->withAddedHeader('User-Agent', 'Ocramius\'s minimal API V3 client') - ->withAddedHeader('Authorization', 'bearer ' . $this->apiToken); + ->withAddedHeader('Authorization', 'token ' . $this->apiToken); $request ->getBody() diff --git a/src/Github/Api/V3/CreateReleaseThroughApiCall.php b/src/Github/Api/V3/CreateReleaseThroughApiCall.php index a43abb8a..071da577 100644 --- a/src/Github/Api/V3/CreateReleaseThroughApiCall.php +++ b/src/Github/Api/V3/CreateReleaseThroughApiCall.php @@ -49,7 +49,7 @@ public function __invoke( ) ->withAddedHeader('Content-Type', 'application/json') ->withAddedHeader('User-Agent', 'Ocramius\'s minimal API V3 client') - ->withAddedHeader('Authorization', 'bearer ' . $this->apiToken); + ->withAddedHeader('Authorization', 'token ' . $this->apiToken); $request ->getBody() diff --git a/src/Github/Api/V3/SetDefaultBranchThroughApiCall.php b/src/Github/Api/V3/SetDefaultBranchThroughApiCall.php index 63937a6e..97255dff 100644 --- a/src/Github/Api/V3/SetDefaultBranchThroughApiCall.php +++ b/src/Github/Api/V3/SetDefaultBranchThroughApiCall.php @@ -45,7 +45,7 @@ public function __invoke( ) ->withAddedHeader('Content-Type', 'application/json') ->withAddedHeader('User-Agent', 'Ocramius\'s minimal API V3 client') - ->withAddedHeader('Authorization', 'bearer ' . $this->apiToken); + ->withAddedHeader('Authorization', 'token ' . $this->apiToken); $request ->getBody() diff --git a/test/unit/Github/Api/V3/CreatePullRequestTest.php b/test/unit/Github/Api/V3/CreatePullRequestTest.php index a52451f3..138b6ad6 100644 --- a/test/unit/Github/Api/V3/CreatePullRequestTest.php +++ b/test/unit/Github/Api/V3/CreatePullRequestTest.php @@ -76,7 +76,7 @@ public function testSuccessfulRequest(): void 'Host' => ['the-domain.com'], 'Content-Type' => ['application/json'], 'User-Agent' => ['Ocramius\'s minimal API V3 client'], - 'Authorization' => ['bearer ' . $this->apiToken], + 'Authorization' => ['token ' . $this->apiToken], ], $request->getHeaders() ); diff --git a/test/unit/Github/Api/V3/CreateReleaseTest.php b/test/unit/Github/Api/V3/CreateReleaseTest.php index 0c636b92..f3f60d9d 100644 --- a/test/unit/Github/Api/V3/CreateReleaseTest.php +++ b/test/unit/Github/Api/V3/CreateReleaseTest.php @@ -74,7 +74,7 @@ public function testSuccessfulRequest(): void 'Host' => ['the-domain.com'], 'Content-Type' => ['application/json'], 'User-Agent' => ['Ocramius\'s minimal API V3 client'], - 'Authorization' => ['bearer ' . $this->apiToken], + 'Authorization' => ['token ' . $this->apiToken], ], $request->getHeaders() ); diff --git a/test/unit/Github/Api/V3/SetDefaultBranchThroughApiCallTest.php b/test/unit/Github/Api/V3/SetDefaultBranchThroughApiCallTest.php index 5d0247d0..e5a79950 100644 --- a/test/unit/Github/Api/V3/SetDefaultBranchThroughApiCallTest.php +++ b/test/unit/Github/Api/V3/SetDefaultBranchThroughApiCallTest.php @@ -72,7 +72,7 @@ public function testSuccessfulRequest(): void 'Host' => ['the-domain.com'], 'Content-Type' => ['application/json'], 'User-Agent' => ['Ocramius\'s minimal API V3 client'], - 'Authorization' => ['bearer ' . $this->apiToken], + 'Authorization' => ['token ' . $this->apiToken], ], $request->getHeaders() ); @@ -117,7 +117,7 @@ public function testRequestFailedToSwitchBranch(): void 'Host' => ['the-domain.com'], 'Content-Type' => ['application/json'], 'User-Agent' => ['Ocramius\'s minimal API V3 client'], - 'Authorization' => ['bearer ' . $this->apiToken], + 'Authorization' => ['token ' . $this->apiToken], ], $request->getHeaders() );