Skip to content

Commit

Permalink
Remove custom Accept header for hide comment preview API
Browse files Browse the repository at this point in the history
This is not part of the main API. This is to help test runatlantis#1009 For some reason API calls come back with '406 Not Acceptable Body' on Github Enterprise, despite the GE stating the custom Accept headers are required.

Maybe it's no longer required like on github.com and GH simply forgot to update the docs?
  • Loading branch information
Sam Park committed May 5, 2020
1 parent 541d25d commit aefdc32
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
15 changes: 2 additions & 13 deletions server/events/vcs/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/events/vcs/common"

"github.com/Laisky/graphql"
"github.com/google/go-github/v28/github"
"github.com/pkg/errors"
"github.com/shurcooL/githubv4"
"github.com/shurcooL/graphql"
)

// maxCommentLength is the maximum number of chars allowed in a single comment
Expand Down Expand Up @@ -66,18 +66,7 @@ func NewGithubClient(hostname string, user string, pass string) (*GithubClient,
}
}

// shurcooL's githubv4 library has a client ctor, but it doesn't support schema
// previews, which need custom Accept headers (https://developer.github.com/v4/previews)
// So for now use the graphql client, since the githubv4 library was basically
// a simple wrapper around it. And instead of using shurcooL's graphql lib, use
// Laisky's, since shurcooL's doesn't support custom headers.
// Once the Minimize Comment schema is official, this can revert back to using
// shurcooL's libraries completely.
v4MutateClient := graphql.NewClient(
graphqlURL,
tp.Client(),
graphql.WithHeader("Accept", "application/vnd.github.queen-beryl-preview+json"),
)
v4MutateClient := graphql.NewClient(graphqlURL, tp.Client())

return &GithubClient{
user: user,
Expand Down
5 changes: 0 additions & 5 deletions server/events/vcs/github_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,6 @@ func TestGithubClient_HideOldComments(t *testing.T) {
w.Write([]byte(issueResp)) // nolint: errcheck
return
case "POST /graphql":
if accept, has := r.Header["Accept"]; !has || accept[0] != "application/vnd.github.queen-beryl-preview+json" {
t.Error("missing preview header")
http.Error(w, "bad request", http.StatusBadRequest)
return
}
defer r.Body.Close() // nolint: errcheck
body, err := ioutil.ReadAll(r.Body)
if err != nil {
Expand Down

0 comments on commit aefdc32

Please sign in to comment.