Skip to content

Commit

Permalink
Add NodeID for grapqhl preview to PullRequest (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
joho authored and gmlewis committed Jan 22, 2018
1 parent 922ceac commit 7cbc150
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions github/pulls.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type PullRequest struct {
Milestone *Milestone `json:"milestone,omitempty"`
MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"`
AuthorAssociation *string `json:"author_association,omitempty"`
NodeID *string `json:"node_id,omitempty"`

Head *PullRequestBranch `json:"head,omitempty"`
Base *PullRequestBranch `json:"base,omitempty"`
Expand Down Expand Up @@ -112,6 +113,9 @@ func (s *PullRequestsService) List(ctx context.Context, owner string, repo strin
return nil, nil, err
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)

var pulls []*PullRequest
resp, err := s.client.Do(ctx, req, &pulls)
if err != nil {
Expand All @@ -131,6 +135,9 @@ func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string
return nil, nil, err
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)

pull := new(PullRequest)
resp, err := s.client.Do(ctx, req, pull)
if err != nil {
Expand Down Expand Up @@ -186,6 +193,9 @@ func (s *PullRequestsService) Create(ctx context.Context, owner string, repo str
return nil, nil, err
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)

p := new(PullRequest)
resp, err := s.client.Do(ctx, req, p)
if err != nil {
Expand Down Expand Up @@ -232,6 +242,9 @@ func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo strin
return nil, nil, err
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)

p := new(PullRequest)
resp, err := s.client.Do(ctx, req, p)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions github/pulls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestPullRequestsService_List(t *testing.T) {

mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
testFormValues(t, r, values{
"state": "closed",
"head": "h",
Expand Down Expand Up @@ -59,6 +60,7 @@ func TestPullRequestsService_Get(t *testing.T) {

mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
fmt.Fprint(w, `{"number":1}`)
})

Expand Down Expand Up @@ -218,6 +220,7 @@ func TestPullRequestsService_Create(t *testing.T) {
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
Expand Down Expand Up @@ -277,6 +280,7 @@ func TestPullRequestsService_Edit(t *testing.T) {
madeRequest := false
mux.HandleFunc(fmt.Sprintf("/repos/o/r/pulls/%v", i), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview)
testBody(t, r, tt.wantUpdate+"\n")
io.WriteString(w, tt.sendResponse)
madeRequest = true
Expand Down

0 comments on commit 7cbc150

Please sign in to comment.