Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oauth token is optional #250

Merged
merged 1 commit into from
Nov 24, 2021
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
31 changes: 15 additions & 16 deletions cmd/app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,24 +247,23 @@ func gatherCredentials(flags *cmdFlags, config *configuration.Config) []*Credent
}
}

if len(flags.ghOAuthToken) > 0 {
var username string
token := flags.ghOAuthToken
if _, ok := credentialsByHost["github.com"]; ok {
klog.Warning("github.com token is overridden by the provided token with `--github-oauth-token flag` ")
}
usernameAndToken := strings.Split(flags.ghOAuthToken, ":")
if len(usernameAndToken) == 2 {
username = usernameAndToken[0]
token = usernameAndToken[1]
}
var username string
token := flags.ghOAuthToken
if _, ok := credentialsByHost["github.com"]; ok {
klog.Warning("github.com token is overridden by the provided token with `--github-oauth-token flag` ")
}
usernameAndToken := strings.Split(flags.ghOAuthToken, ":")
if len(usernameAndToken) == 2 {
username = usernameAndToken[0]
token = usernameAndToken[1]
}

credentialsByHost["github.com"] = &Credentials{
Host: "github.com",
Username: &username,
OAuthToken: token,
}
credentialsByHost["github.com"] = &Credentials{
Host: "github.com",
Username: &username,
OAuthToken: token,
}

return getCredentialsSlice(credentialsByHost)
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/app/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ func buildClient(ctx context.Context, accessToken string, withClientThrottling b

var client *github.Client
if host == "https://github.com" {
client = github.NewClient(oauthClient)
if accessToken != "" {
dimitar-kostadinov marked this conversation as resolved.
Show resolved Hide resolved
client = github.NewClient(oauthClient)
} else {
client = github.NewClient(nil)
}
return client, oauthClient, nil
}
client, err = github.NewEnterpriseClient(host, "", oauthClient)
Expand Down