Skip to content

Commit c4da415

Browse files
committed
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 <[email protected]>
1 parent 1469088 commit c4da415

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

src/Github/Api/V3/CreatePullRequestThroughApiCall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __invoke(
4848
)
4949
->withAddedHeader('Content-Type', 'application/json')
5050
->withAddedHeader('User-Agent', 'Ocramius\'s minimal API V3 client')
51-
->withAddedHeader('Authorization', 'bearer ' . $this->apiToken);
51+
->withAddedHeader('Authorization', 'token ' . $this->apiToken);
5252

5353
$request
5454
->getBody()

src/Github/Api/V3/CreateReleaseThroughApiCall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __invoke(
4949
)
5050
->withAddedHeader('Content-Type', 'application/json')
5151
->withAddedHeader('User-Agent', 'Ocramius\'s minimal API V3 client')
52-
->withAddedHeader('Authorization', 'bearer ' . $this->apiToken);
52+
->withAddedHeader('Authorization', 'token ' . $this->apiToken);
5353

5454
$request
5555
->getBody()

src/Github/Api/V3/SetDefaultBranchThroughApiCall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __invoke(
4545
)
4646
->withAddedHeader('Content-Type', 'application/json')
4747
->withAddedHeader('User-Agent', 'Ocramius\'s minimal API V3 client')
48-
->withAddedHeader('Authorization', 'bearer ' . $this->apiToken);
48+
->withAddedHeader('Authorization', 'token ' . $this->apiToken);
4949

5050
$request
5151
->getBody()

test/unit/Github/Api/V3/CreatePullRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testSuccessfulRequest(): void
7676
'Host' => ['the-domain.com'],
7777
'Content-Type' => ['application/json'],
7878
'User-Agent' => ['Ocramius\'s minimal API V3 client'],
79-
'Authorization' => ['bearer ' . $this->apiToken],
79+
'Authorization' => ['token ' . $this->apiToken],
8080
],
8181
$request->getHeaders()
8282
);

test/unit/Github/Api/V3/CreateReleaseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testSuccessfulRequest(): void
7474
'Host' => ['the-domain.com'],
7575
'Content-Type' => ['application/json'],
7676
'User-Agent' => ['Ocramius\'s minimal API V3 client'],
77-
'Authorization' => ['bearer ' . $this->apiToken],
77+
'Authorization' => ['token ' . $this->apiToken],
7878
],
7979
$request->getHeaders()
8080
);

test/unit/Github/Api/V3/SetDefaultBranchThroughApiCallTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testSuccessfulRequest(): void
7272
'Host' => ['the-domain.com'],
7373
'Content-Type' => ['application/json'],
7474
'User-Agent' => ['Ocramius\'s minimal API V3 client'],
75-
'Authorization' => ['bearer ' . $this->apiToken],
75+
'Authorization' => ['token ' . $this->apiToken],
7676
],
7777
$request->getHeaders()
7878
);
@@ -117,7 +117,7 @@ public function testRequestFailedToSwitchBranch(): void
117117
'Host' => ['the-domain.com'],
118118
'Content-Type' => ['application/json'],
119119
'User-Agent' => ['Ocramius\'s minimal API V3 client'],
120-
'Authorization' => ['bearer ' . $this->apiToken],
120+
'Authorization' => ['token ' . $this->apiToken],
121121
],
122122
$request->getHeaders()
123123
);

0 commit comments

Comments
 (0)