Skip to content

Commit 38abc2b

Browse files
committed
Clarify that we cannot test Checks API locally
1 parent f9938af commit 38abc2b

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.idea
33
bin/
44
*.json
5+
.envrc

cmd/checks/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ Usage of bin/checks:
2525

2626
## Running locally
2727

28+
> This is just here to show the ideal developer experience. The reality is that you can't test `checks` locally.
29+
>
30+
> That's due to limitations in GitHub.
31+
> As Checks API requires a GitHub App installation token(not bearer token you're probably familiar with) to access
32+
> and there's currently no way to obtain an installation token locally,
33+
> you can't test this locally.
34+
2835
Capture actual webhook payloads for `pull_request`, `check_suite`, `check_run` events by running `cat /github/workflow/event.json` on GitHub Actions.
2936

3037
Install this workflow onto your test repository:
@@ -60,11 +67,11 @@ Then build and run `checks` against json files containing captured events:
6067
$ make build/checks
6168
6269
# Typically this is run on Actions with `on: pull_requqest`
63-
$ GITHUB_EVENT_PATH=$(pwd)/pull_request_event.json bin/checks
70+
$ GITHUB_TOKEN_TYPE=bearer GITHUB_EVENT_PATH=$(pwd)/pull_request_event.json GITHUB_EVENT_NAME=pull_request bin/checks
6471
6572
# `on: check_suite`
66-
$ GITHUB_EVENT_PATH=$(pwd)/check_suite_event.json bin/checks -create-run foo -create-run bar
73+
$ GITHUB_TOKEN_TYPE=bearer GITHUB_EVENT_PATH=$(pwd)/check_suite_event.json bin/checks -create-run foo -create-run bar
6774
6875
# `on: check_run`
69-
$ GITHUB_EVENT_PATH=$(pwd)/check_run_event.json bin/checks -run foo -- actions pullvet ...
76+
$ GITHUB_TOKEN_TYPE=bearer GITHUB_EVENT_PATH=$(pwd)/check_run_event.json bin/checks -run foo -- actions pullvet ...
7077
```

pkg/checks/checks.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ func (c *Command) instTokenClient() (*github.Client, error) {
233233
// instTokenClient uses an installation token to authenticate to the Github API.
234234
func instTokenClient(instToken, baseURL, uploadURL string) (*github.Client, error) {
235235
// For installation tokens, Github uses a different token type ("token" instead of "bearer")
236-
t := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: instToken, TokenType: "token"})
236+
tokenType := "token"
237+
if os.Getenv("GITHUB_TOKEN_TYPE") != "" {
238+
tokenType = os.Getenv("GITHUB_TOKEN_TYPE")
239+
}
240+
t := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: instToken, TokenType: tokenType})
237241
c := context.Background()
238242
tc := oauth2.NewClient(c, t)
239243
if baseURL != "" {

0 commit comments

Comments
 (0)