Skip to content

Commit

Permalink
Use proper http client for github v4 api (#2479)
Browse files Browse the repository at this point in the history
* Use proper http client for github v4 api

* Remove extra print lines

Co-authored-by: Ray Terrill <[email protected]>
  • Loading branch information
ysoldak and rayterrill authored Sep 7, 2022
1 parent 08fa651 commit a4a49bf
Showing 1 changed file with 1 addition and 18 deletions.
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

0 comments on commit a4a49bf

Please sign in to comment.