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

fix: fix unmarshall error in graphql call #2128

Merged
merged 3 commits into from
Mar 9, 2022
Merged
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion server/events/vcs/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/runatlantis/atlantis/server/events/vcs/common"
"github.com/runatlantis/atlantis/server/logging"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
)

// maxCommentLength is the maximum number of chars allowed in a single comment
Expand All @@ -40,6 +41,7 @@ type GithubClient struct {
user string
client *github.Client
v4MutateClient *graphql.Client
v4QueryClient *githubv4.Client
ctx context.Context
logger logging.SimpleLogging
}
Expand Down Expand Up @@ -91,6 +93,16 @@ func NewGithubClient(hostname string, credentials GithubCredentials, logger logg
transport,
graphql.WithHeader("Accept", "application/vnd.github.queen-beryl-preview+json"),
)
token, err := credentials.GetToken()
if err != nil {
return nil, errors.Wrap(err, "Failed to get GitHub token")
}
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
httpClient := oauth2.NewClient(context.Background(), src)
// Use the client from shurcooL's githubv4 library for queries.
v4QueryClient := githubv4.NewClient(httpClient)

user, err := credentials.GetUser()
logger.Debug("GH User: %s", user)
Expand All @@ -102,6 +114,7 @@ func NewGithubClient(hostname string, credentials GithubCredentials, logger logg
user: user,
client: client,
v4MutateClient: v4MutateClient,
v4QueryClient: v4QueryClient,
ctx: context.Background(),
logger: logger,
}, nil
Expand Down Expand Up @@ -461,7 +474,7 @@ func (g *GithubClient) GetTeamNamesForUser(repo models.Repo, user models.User) (
var teamNames []string
ctx := context.Background()
for {
err := g.v4MutateClient.Query(ctx, &q, variables)
err := g.v4QueryClient.Query(ctx, &q, variables)
if err != nil {
return nil, err
}
Expand Down