Skip to content

Commit

Permalink
Add support for Draft Pull Requests Preview API
Browse files Browse the repository at this point in the history
This change implements support for a preview of a new Draft Pull
Requests API, announced at
https://developer.github.com/changes/2019-02-14-draft-pull-requests/.

• Add new media type constant.
• Use that media type in "list pull requests" and "get pull request"
  endpoints.
• Add Draft struct field to the PullRequest struct.

The "create pull request" and "update pull request" endpoints don't set
the new media type yet, but that can be dealt with in a future change.

Fixes google#1120.
  • Loading branch information
joshuabezaleel authored and dmitshur committed Feb 15, 2019
1 parent 5fccd9e commit 6d8a511
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 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.

3 changes: 3 additions & 0 deletions github/github.go
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions github/pulls.go
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions github/pulls_test.go
Expand Up @@ -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, ", "))
Expand Down Expand Up @@ -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, ", "))
Expand Down

0 comments on commit 6d8a511

Please sign in to comment.