Skip to content

Commit 01a88ae

Browse files
unbleegmlewis
authored andcommitted
Support expand Deployment Statuses API (#1036)
Fixes #1035.
1 parent e645909 commit 01a88ae

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

github/github-accessors.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ const (
5454
// https://developer.github.com/changes/2016-04-06-deployment-and-deployment-status-enhancements/
5555
mediaTypeDeploymentStatusPreview = "application/vnd.github.ant-man-preview+json"
5656

57+
// https://developer.github.com/changes/2018-10-16-deployments-environments-states-and-auto-inactive-updates/
58+
mediaTypeExpandDeploymentStatusPreview = "application/vnd.github.flash-preview+json"
59+
5760
// https://developer.github.com/changes/2016-02-19-source-import-preview-api/
5861
mediaTypeImportPreview = "application/vnd.github.barred-rock-preview"
5962

github/repos_deployments.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"encoding/json"
1111
"fmt"
12+
"strings"
1213
)
1314

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

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

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

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

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

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

217222
d := new(DeploymentStatus)
218223
resp, err := s.client.Do(ctx, req, d)

github/repos_deployments_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"net/http"
1313
"reflect"
14+
"strings"
1415
"testing"
1516
)
1617

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

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

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

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

143146
testMethod(t, r, "POST")
144-
testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview)
147+
acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview}
148+
testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", "))
145149
if !reflect.DeepEqual(v, input) {
146150
t.Errorf("Request body = %+v, want %+v", v, input)
147151
}

0 commit comments

Comments
 (0)