From 7cbc1505685d6ce57a82b50ee4968ee41dec5b2b Mon Sep 17 00:00:00 2001 From: John Barton Date: Tue, 23 Jan 2018 04:57:02 +1100 Subject: [PATCH] Add NodeID for grapqhl preview to PullRequest (#833) --- github/github-accessors.go | 8 ++++++++ github/pulls.go | 13 +++++++++++++ github/pulls_test.go | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index 516b0405cf5..b4484226ce0 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -5812,6 +5812,14 @@ func (p *PullRequest) GetMilestone() *Milestone { return p.Milestone } +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (p *PullRequest) GetNodeID() string { + if p == nil || p.NodeID == nil { + return "" + } + return *p.NodeID +} + // GetNumber returns the Number field if it's non-nil, zero value otherwise. func (p *PullRequest) GetNumber() int { if p == nil || p.Number == nil { diff --git a/github/pulls.go b/github/pulls.go index c10e2feb915..0ce649ce9e2 100644 --- a/github/pulls.go +++ b/github/pulls.go @@ -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"` @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/github/pulls_test.go b/github/pulls_test.go index fabc7110511..61e5d962cd0 100644 --- a/github/pulls_test.go +++ b/github/pulls_test.go @@ -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", @@ -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}`) }) @@ -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) } @@ -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