-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Modify graphql token logic to include refresh #2475
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package vcs | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/shurcooL/githubv4" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
type GithubGraphQLClient struct { | ||
credentials GithubCredentials | ||
graphqlURL string | ||
} | ||
|
||
func (gcl GithubGraphQLClient) Query(ctx context.Context, q interface{}, variables map[string]interface{}) error { | ||
token, err := gcl.credentials.GetToken() | ||
if err != nil { | ||
return 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.NewEnterpriseClient(gcl.graphqlURL, httpClient) | ||
|
||
err = v4QueryClient.Query(ctx, q, variables) | ||
if err != nil { | ||
return errors.Wrap(err, "making graphql query") | ||
} | ||
|
||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code will crash if no required checks are configured for the repo. While feature flag kind of implies that at least one required check should be set -
atlantis/apply
- it's completely plausible to have 1 or 2 repos in organization misconfigured or deliberately configured in a different way. If there are no required checks it means that we don't even need to go through CheckRuns.I understand it's out of scope of this PR, but feels like the best place to point it out :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean @stasostrovskyi - I just tested this again with no required checks configured and it works fine? It should just pass right through that section if none of the checks are required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what we got when running without required checks
I haven't debugged it but it's either
required
orRequiredStatusChecks
arenil
in the case when there are no required checks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub probably returns
nil
("null" in JSON) instead of an empty list as the code expects.