Skip to content

Commit 84cf4a1

Browse files
authored
[git] improved logging in GitHub token verification (#4479)
see #4478
1 parent a6c5481 commit 84cf4a1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

components/gitpod-cli/cmd/git-token-validator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,19 @@ var gitTokenValidator = &cobra.Command{
8888
User: gitTokenValidatorOpts.User,
8989
},
9090
}
91+
log.WithField("host", gitTokenValidatorOpts.Host).
92+
WithField("repoURL", gitTokenValidatorOpts.RepoURL).
93+
WithField("command", gitTokenValidatorOpts.GitCommand).
94+
WithField("user", gitTokenValidatorOpts.User).
95+
WithField("tokenScopes", gitTokenValidatorOpts.TokenScopes).
96+
Info("guessing required token scopes")
9197
guessedTokenScopes, err := client.GuessGitTokenScopes(ctx, params)
9298
if err != nil {
9399
log.WithError(err).Fatal("error guessing token scopes on server")
94100
}
95101
if guessedTokenScopes.Message != "" {
96102
message := fmt.Sprintf("%s Please grant the necessary permissions.", guessedTokenScopes.Message)
103+
log.WithField("guessedTokenScopes", guessedTokenScopes.Scopes).Info("insufficient permissions")
97104
result, err := supervisor.NewNotificationServiceClient(supervisorConn).Notify(ctx,
98105
&supervisor.NotifyRequest{
99106
Level: supervisor.NotifyRequest_INFO,

components/server/src/github/github-token-validator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { inject, injectable } from "inversify";
88
import { CheckWriteAccessResult, IGitTokenValidator, IGitTokenValidatorParams } from "../workspace/git-token-validator";
99
import { GitHubApiError, GitHubGraphQlEndpoint, GitHubRestApi, GitHubResult } from "./api";
10+
import { log } from '@gitpod/gitpod-protocol/lib/util/logging';
1011

1112
@injectable()
1213
export class GitHubTokenValidator implements IGitTokenValidator {
@@ -28,6 +29,7 @@ export class GitHubTokenValidator implements IGitTokenValidator {
2829
if (GitHubApiError.is(error) && error.response?.status === 404) {
2930
return { found: false };
3031
}
32+
log.error('Error getting repo information from GitHub', error, { repoFullName, parsedRepoName })
3133
return { found: false, error };
3234
}
3335

@@ -61,6 +63,7 @@ export class GitHubTokenValidator implements IGitTokenValidator {
6163
if (errors && errors[0] && (errors[0] as any)["type"] === "FORBIDDEN") {
6264
writeAccessToRepo = false;
6365
} else {
66+
log.error('Error getting organization information from GitHub', error, { org: parsedRepoName.owner })
6467
throw error;
6568
}
6669
}

0 commit comments

Comments
 (0)