From 3a969e2aeb9ccf1d09fa544e57c88ef35dd3ffb4 Mon Sep 17 00:00:00 2001 From: unblee Date: Thu, 25 Oct 2018 15:38:23 +0900 Subject: [PATCH] Support expand Deployment Statuses API --- github/github-accessors.go | 8 ++++++++ github/github.go | 3 +++ github/repos_deployments.go | 11 ++++++++--- github/repos_deployments_test.go | 10 +++++++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 3ec79c2ca33..62573892958 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2292,6 +2292,14 @@ func (d *DeploymentStatusRequest) GetDescription() string { return *d.Description } +// GetEnvironment returns the Environment field if it's non-nil, zero value otherwise. +func (d *DeploymentStatusRequest) GetEnvironment() string { + if d == nil || d.Environment == nil { + return "" + } + return *d.Environment +} + // GetEnvironmentURL returns the EnvironmentURL field if it's non-nil, zero value otherwise. func (d *DeploymentStatusRequest) GetEnvironmentURL() string { if d == nil || d.EnvironmentURL == nil { diff --git a/github/github.go b/github/github.go index 320b8104b67..893ddefb4cc 100644 --- a/github/github.go +++ b/github/github.go @@ -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" diff --git a/github/repos_deployments.go b/github/repos_deployments.go index 794c3232ed9..604632e91b6 100644 --- a/github/repos_deployments.go +++ b/github/repos_deployments.go @@ -9,6 +9,7 @@ import ( "context" "encoding/json" "fmt" + "strings" ) // Deployment represents a deployment in a repo @@ -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) @@ -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"` } @@ -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) @@ -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) diff --git a/github/repos_deployments_test.go b/github/repos_deployments_test.go index f6f333aa25f..3396cf44de9 100644 --- a/github/repos_deployments_test.go +++ b/github/repos_deployments_test.go @@ -11,6 +11,7 @@ import ( "fmt" "net/http" "reflect" + "strings" "testing" ) @@ -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) } @@ -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}`) }) @@ -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) }