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

Use proper http client for github v4 api #2479

Merged
merged 2 commits into from
Sep 7, 2022
Merged
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
19 changes: 1 addition & 18 deletions server/events/vcs/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ 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 Down Expand Up @@ -95,16 +94,8 @@ func NewGithubClient(hostname string, credentials GithubCredentials, config Gith
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.NewEnterpriseClient(graphqlURL, httpClient)
v4QueryClient := githubv4.NewEnterpriseClient(graphqlURL, transport)

user, err := credentials.GetUser()
logger.Debug("GH User: %s", user)
Expand Down Expand Up @@ -344,28 +335,22 @@ func (g *GithubClient) GetCombinedStatusMinusApply(repo models.Repo, pull *githu
//iterate over check completed check suites - return false if we find one that doesnt have conclusion = "success"
for _, c := range checksuites.CheckSuites {
if *c.Status == "completed" {
fmt.Printf("Looking at suite %v\n", *c.ID)
//iterate over the runs inside the suite
suite, _, err := g.client.Checks.ListCheckRunsCheckSuite(context.Background(), repo.Owner, repo.Name, *c.ID, nil)
if err != nil {
return false, errors.Wrap(err, "getting check runs for check suite")
}

for _, r := range suite.CheckRuns {
fmt.Printf("Looking at check run %s\n", *r.Name)
//check to see if the check is required
if isRequiredCheck(*r.Name, required.RequiredStatusChecks.Contexts) {
fmt.Println("Check is required")
if *c.Conclusion == "success" {
fmt.Println("Check is successful")
continue
} else {
fmt.Println("Check is failed")
return false, nil
}
} else {
//ignore checks that arent required
fmt.Println("Check is not required")
continue
}

Expand Down Expand Up @@ -432,8 +417,6 @@ func (g *GithubClient) PullIsMergeable(repo models.Repo, pull models.PullRequest
return false, errors.Wrap(err, "getting pull request status")
}

fmt.Printf("Status was %v\n", status)

//check to see if pr is approved using reviewDecision
approved, err := g.GetPullReviewDecision(repo, pull)
if err != nil {
Expand Down