Repository: google/go-github
Pull request #1121 (2019-02-15 03:54:34)

Support draft pull requests api public beta
Fixes: #1120 

* Adding new media type (`application/vnd.github.shadow-cat-preview+json`) must be added to `github.go`,
* Adding the type to the header of listPRs and get single PR endpoint call,
* Adding new Draft boolean field to the [`PullRequest`](https://godoc.org/github.com/google/go-github/github#PullRequest) struct.



dmitshur: Thanks, this is a great start!

It looks like this PR currently includes commit 31ef9b1 that shouldn't be here. It's removing some code and isn't related to issue #1120.

You should also update the PR to include text such as "Fixes #1120." That way, when we merge this PR, it will automatically close the associated issue. GitHub has documentation on this at https://help.github.com/articles/closing-issues-using-keywords/.
dmitshur: Another step that needs to be done is to re-generate one of the files in this Go package by running the `go generate github.com/google/go-github/github` command. This is mentioned in step 5 of [CONTRIBUTING.md#submitting-a-patch](https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch).
googlebot: So there's good news and bad news.

:thumbsup: The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so.  Everything is all good there.

:confused: The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter.  We need to confirm that all authors are ok with their commits being contributed to this project.  Please have them confirm that here in the pull request.

*Note to project maintainer: This is a terminal state, meaning the `cla/google` commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the `cla` label to `yes` (if enabled on your project), and then merge this pull request when appropriate.*

Googlers can find more info about SignCLA and this PR by [following this link](go/prinfo/https%3A%2F%2Fgithub.com%2Fgoogle%2Fgo-github%2Fpull%2F1121).

<!-- need_author_consent -->
googlebot: CLAs look good, thanks!

Googlers can find more info about SignCLA and this PR by [following this link](go/prinfo/https%3A%2F%2Fgithub.com%2Fgoogle%2Fgo-github%2Fpull%2F1121).

<!-- ok -->
joshuabezaleel: Hi @dmitshur , I've made some changes. Looking forward to your review.
Also, I ran the commands that was written in the contributing guidelines and got this result. Is this the way they should work? 
![image](https://user-images.githubusercontent.com/7043511/52843937-0ac21f80-3136-11e9-9dc5-743d9722bc50.png)


Thank you very much!
gmlewis: No, it looks like your generate didn't work since `github-accessors.go` was not updated with the new field.
It looks like maybe `GO111MODULE=on` might be set.  Could you please try `go generate ./...` from that same directory and see if that works?

Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index cb2f0284..b9deb7e1 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -7196,6 +7196,14 @@ func (p *PullRequest) GetDiffURL() string {
 	return *p.DiffURL
 }
 
+// GetDraft returns the Draft field if it's non-nil, zero value otherwise.
+func (p *PullRequest) GetDraft() bool {
+	if p == nil || p.Draft == nil {
+		return false
+	}
+	return *p.Draft
+}
+
 // GetHead returns the Head field.
 func (p *PullRequest) GetHead() *PullRequestBranch {
 	if p == nil {
diff --git a/github/github.go b/github/github.go
index 36ee5acb..4d86d76b 100644
--- a/github/github.go
+++ b/github/github.go
@@ -128,6 +128,9 @@ const (
 
 	// https://developer.github.com/changes/2018-12-18-interactions-preview/
 	mediaTypeInteractionRestrictionsPreview = "application/vnd.github.sombra-preview+json"
+
+	// https://developer.github.com/changes/2019-02-14-draft-pull-requests/
+	mediaTypeDraftPreview = "application/vnd.github.shadow-cat-preview+json"
 )
 
 // A Client manages communication with the GitHub API.
diff --git a/github/pulls.go b/github/pulls.go
index b3479dfe..067e362b 100644
--- a/github/pulls.go
+++ b/github/pulls.go
@@ -32,6 +32,7 @@ type PullRequest struct {
 	MergedAt            *time.Time `json:"merged_at,omitempty"`
 	Labels              []*Label   `json:"labels,omitempty"`
 	User                *User      `json:"user,omitempty"`
+	Draft               *bool      `json:"draft,omitempty"`
 	Merged              *bool      `json:"merged,omitempty"`
 	Mergeable           *bool      `json:"mergeable,omitempty"`
 	MergeableState      *string    `json:"mergeable_state,omitempty"`
@@ -146,7 +147,7 @@ func (s *PullRequestsService) List(ctx context.Context, owner string, repo strin
 	}
 
 	// TODO: remove custom Accept header when this API fully launches.
-	acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview}
+	acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview, mediaTypeDraftPreview}
 	req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
 
 	var pulls []*PullRequest
@@ -169,7 +170,7 @@ func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string
 	}
 
 	// TODO: remove custom Accept header when this API fully launches.
-	acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview}
+	acceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview, mediaTypeDraftPreview}
 	req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
 
 	pull := new(PullRequest)


Test patch:
diff --git a/github/pulls_test.go b/github/pulls_test.go
index f8533828..602f03be 100644
--- a/github/pulls_test.go
+++ b/github/pulls_test.go
@@ -20,7 +20,7 @@ func TestPullRequestsService_List(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
 
-	wantAcceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview}
+	wantAcceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview, mediaTypeDraftPreview}
 	mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
@@ -59,7 +59,7 @@ func TestPullRequestsService_Get(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
 
-	wantAcceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview}
+	wantAcceptHeaders := []string{mediaTypeLabelDescriptionSearchPreview, mediaTypeLockReasonPreview, mediaTypeDraftPreview}
 	mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))