Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ $ gopass insert cogito/test_oauth_token

```console
$ gopass insert cogito/github_app_client_id
$ gopass insert gopass show cogito/github_app_installation_id
$ gopass insert cogito/github_app_installation_id
$ gopass insert --multiline cogito/github_app_private_key
```

Expand Down
14 changes: 13 additions & 1 deletion github/commitstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (cs CommitStatus) Add(ctx context.Context, sha, state, targetURL, descripti
remaining := resp.Header.Get("X-RateLimit-Remaining")
limit := resp.Header.Get("X-RateLimit-Limit")
reset := resp.Header.Get("X-RateLimit-Reset")
contentType := resp.Header.Get("Content-Type")
cs.log.Debug(
"http-request",
"method", req.Method,
Expand All @@ -161,7 +162,18 @@ func (cs CommitStatus) Add(ctx context.Context, sha, state, targetURL, descripti
}

body, _ := io.ReadAll(resp.Body)
return NewGitHubError(resp, errors.New(strings.TrimSpace(string(body))))
buffer := body
if strings.Contains(strings.ToLower(contentType), "application/json") {
var foo map[string]any
if err := json.Unmarshal(body, &foo); err != nil {
return fmt.Errorf("normalizing JSON: unmarshal: %s", err)
}
buffer, err = json.Marshal(foo)
if err != nil {
return fmt.Errorf("normalizing JSON: marshal: %s", err)
}
}
return NewGitHubError(resp, errors.New(strings.TrimSpace(string(buffer))))
}

if err := cs.target.Retry.Do(Backoff, Classifier, workFn); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions github/commitstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func TestGitHubStatusFailureIntegration(t *testing.T) {
name: "bad token: Unauthorized",
token: "bad-token",
wantErr: `failed to add state "success" for commit 751affd: 401 Unauthorized
Body: {"message":"Bad credentials","documentation_url":"https://docs.github.com/rest","status":"401"}
Body: {"documentation_url":"https://docs.github.com/rest","message":"Bad credentials","status":"401"}
Hint: Either wrong credentials or PAT expired (check your email for expiration notice)
Action: POST https://api.github.com/repos/pix4d/cogito-test-read-write/statuses/751affd155db7a00d936ee6e9f483deee69c5922
OAuth: X-Accepted-Oauth-Scopes: , X-Oauth-Scopes: `,
Expand All @@ -428,7 +428,7 @@ OAuth: X-Accepted-Oauth-Scopes: , X-Oauth-Scopes: `,
name: "non existing repo: Not Found",
repo: "non-existing-really",
wantErr: `failed to add state "success" for commit 751affd: 404 Not Found
Body: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/commits/statuses#create-a-commit-status","status":"404"}
Body: {"documentation_url":"https://docs.github.com/rest/commits/statuses#create-a-commit-status","message":"Not Found","status":"404"}
Hint: one of the following happened:
1. The repo https://github.com/pix4d/non-existing-really doesn't exist
2. The user who issued the token doesn't have write access to the repo
Expand All @@ -441,7 +441,7 @@ OAuth: X-Accepted-Oauth-Scopes: repo, X-Oauth-Scopes: repo:status`,
name: "non existing SHA: Unprocessable Entity",
sha: "e576e3aa7aaaa048b396e2f34fa24c9cf4d1e822",
wantErr: `failed to add state "success" for commit e576e3a: 422 Unprocessable Entity
Body: {"message":"No commit found for SHA: e576e3aa7aaaa048b396e2f34fa24c9cf4d1e822","documentation_url":"https://docs.github.com/rest/commits/statuses#create-a-commit-status","status":"422"}
Body: {"documentation_url":"https://docs.github.com/rest/commits/statuses#create-a-commit-status","message":"No commit found for SHA: e576e3aa7aaaa048b396e2f34fa24c9cf4d1e822","status":"422"}
Hint: none
Action: POST https://api.github.com/repos/pix4d/cogito-test-read-write/statuses/e576e3aa7aaaa048b396e2f34fa24c9cf4d1e822
OAuth: X-Accepted-Oauth-Scopes: , X-Oauth-Scopes: repo:status`,
Expand Down
Loading