Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const (
// https://developer.github.com/changes/2016-04-06-deployment-and-deployment-status-enhancements/
mediaTypeDeploymentStatusPreview = "application/vnd.github.ant-man-preview+json"

// https://developer.github.com/changes/2018-10-16-deployments-environments-states-and-auto-inactive-updates/
mediaTypeExpandDeploymentStatusPreview = "application/vnd.github.flash-preview+json"

// https://developer.github.com/changes/2016-02-19-source-import-preview-api/
mediaTypeImportPreview = "application/vnd.github.barred-rock-preview"

Expand Down
11 changes: 8 additions & 3 deletions github/repos_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
)

// Deployment represents a deployment in a repo
Expand Down Expand Up @@ -116,7 +117,8 @@ func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo
}

// TODO: remove custom Accept headers when APIs fully launch.
req.Header.Set("Accept", mediaTypeDeploymentStatusPreview)
acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))

d := new(Deployment)
resp, err := s.client.Do(ctx, req, d)
Expand Down Expand Up @@ -149,6 +151,7 @@ type DeploymentStatusRequest struct {
State *string `json:"state,omitempty"`
LogURL *string `json:"log_url,omitempty"`
Description *string `json:"description,omitempty"`
Environment *string `json:"environment,omitempty"`
EnvironmentURL *string `json:"environment_url,omitempty"`
AutoInactive *bool `json:"auto_inactive,omitempty"`
}
Expand Down Expand Up @@ -189,7 +192,8 @@ func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, re
}

// TODO: remove custom Accept headers when APIs fully launch.
req.Header.Set("Accept", mediaTypeDeploymentStatusPreview)
acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))

d := new(DeploymentStatus)
resp, err := s.client.Do(ctx, req, d)
Expand All @@ -212,7 +216,8 @@ func (s *RepositoriesService) CreateDeploymentStatus(ctx context.Context, owner,
}

// TODO: remove custom Accept headers when APIs fully launch.
req.Header.Set("Accept", mediaTypeDeploymentStatusPreview)
acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview}
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))

d := new(DeploymentStatus)
resp, err := s.client.Do(ctx, req, d)
Expand Down
10 changes: 7 additions & 3 deletions github/repos_deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"net/http"
"reflect"
"strings"
"testing"
)

Expand Down Expand Up @@ -68,7 +69,8 @@ func TestRepositoriesService_CreateDeployment(t *testing.T) {
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview)
acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview}
testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", "))
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
Expand Down Expand Up @@ -113,9 +115,10 @@ func TestRepositoriesService_GetDeploymentStatus(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview}
mux.HandleFunc("/repos/o/r/deployments/3/statuses/4", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview)
testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", "))
fmt.Fprint(w, `{"id":4}`)
})

Expand All @@ -141,7 +144,8 @@ func TestRepositoriesService_CreateDeploymentStatus(t *testing.T) {
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview)
acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview}
testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", "))
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
Expand Down