Browse Source

add support for Deployment and DeploymentStatus API enhancements

Fixes #328.

Change-Id: I2f93fb89eb46e9d341e9a9aada8de1b3339d1ffd
Glenn Lewis 10 years ago
parent
commit
b5479d6bf2
3 changed files with 57 additions and 12 deletions
  1. +3
    -0
      github/github.go
  2. +22
    -11
      github/repos_deployments.go
  3. +32
    -1
      github/repos_deployments_test.go

+ 3
- 0
github/github.go View File

@ -65,6 +65,9 @@ const (
// https://help.github.com/enterprise/2.4/admin/guides/migrations/exporting-the-github-com-organization-s-repositories/
mediaTypeMigrationsPreview = "application/vnd.github.wyandotte-preview+json"
// https://developer.github.com/changes/2016-04-06-deployment-and-deployment-status-enhancements/
mediaTypeDeploymentStatusPreview = "application/vnd.github.ant-man-preview+json"
)
// A Client manages communication with the GitHub API.


+ 22
- 11
github/repos_deployments.go View File

@ -29,13 +29,15 @@ type Deployment struct {
// DeploymentRequest represents a deployment request
type DeploymentRequest struct {
Ref *string `json:"ref,omitempty"`
Task *string `json:"task,omitempty"`
AutoMerge *bool `json:"auto_merge,omitempty"`
RequiredContexts *[]string `json:"required_contexts,omitempty"`
Payload *string `json:"payload,omitempty"`
Environment *string `json:"environment,omitempty"`
Description *string `json:"description,omitempty"`
Ref *string `json:"ref,omitempty"`
Task *string `json:"task,omitempty"`
AutoMerge *bool `json:"auto_merge,omitempty"`
RequiredContexts *[]string `json:"required_contexts,omitempty"`
Payload *string `json:"payload,omitempty"`
Environment *string `json:"environment,omitempty"`
Description *string `json:"description,omitempty"`
TransientEnvironment *bool `json:"transient_environment,omitempty"`
ProductionEnvironment *bool `json:"production_environment,omitempty"`
}
// DeploymentsListOptions specifies the optional parameters to the
@ -91,6 +93,9 @@ func (s *RepositoriesService) CreateDeployment(owner, repo string, request *Depl
return nil, nil, err
}
// TODO: remove custom Accept header when deployment support fully launches
req.Header.Set("Accept", mediaTypeDeploymentStatusPreview)
d := new(Deployment)
resp, err := s.client.Do(req, d)
if err != nil {
@ -105,7 +110,7 @@ func (s *RepositoriesService) CreateDeployment(owner, repo string, request *Depl
type DeploymentStatus struct {
ID *int `json:"id,omitempty"`
// State is the deployment state.
// Possible values are: "pending", "success", "failure", "error".
// Possible values are: "pending", "success", "failure", "error", "inactive".
State *string `json:"state,omitempty"`
Creator *User `json:"creator,omitempty"`
Description *string `json:"description,omitempty"`
@ -118,9 +123,12 @@ type DeploymentStatus struct {
// DeploymentStatusRequest represents a deployment request
type DeploymentStatusRequest struct {
State *string `json:"state,omitempty"`
TargetURL *string `json:"target_url,omitempty"`
Description *string `json:"description,omitempty"`
State *string `json:"state,omitempty"`
TargetURL *string `json:"target_url,omitempty"` // Deprecated. Use LogURL instead.
LogURL *string `json:"log_url,omitempty"`
Description *string `json:"description,omitempty"`
EnvironmentURL *string `json:"environment_url,omitempty"`
AutoInactive *bool `json:"auto_inactive,omitempty"`
}
// ListDeploymentStatuses lists the statuses of a given deployment of a repository.
@ -158,6 +166,9 @@ func (s *RepositoriesService) CreateDeploymentStatus(owner, repo string, deploym
return nil, nil, err
}
// TODO: remove custom Accept header when deployment support fully launches
req.Header.Set("Accept", mediaTypeDeploymentStatusPreview)
d := new(DeploymentStatus)
resp, err := s.client.Do(req, d)
if err != nil {


+ 32
- 1
github/repos_deployments_test.go View File

@ -39,13 +39,14 @@ func TestRepositoriesService_CreateDeployment(t *testing.T) {
setup()
defer teardown()
input := &DeploymentRequest{Ref: String("1111"), Task: String("deploy")}
input := &DeploymentRequest{Ref: String("1111"), Task: String("deploy"), TransientEnvironment: Bool(true)}
mux.HandleFunc("/repos/o/r/deployments", func(w http.ResponseWriter, r *http.Request) {
v := new(DeploymentRequest)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
@ -85,3 +86,33 @@ func TestRepositoriesService_ListDeploymentStatuses(t *testing.T) {
t.Errorf("Repositories.ListDeploymentStatuses returned %+v, want %+v", statutses, want)
}
}
func TestRepositoriesService_CreateDeploymentStatus(t *testing.T) {
setup()
defer teardown()
input := &DeploymentStatusRequest{State: String("inactive"), Description: String("deploy"), AutoInactive: Bool(false)}
mux.HandleFunc("/repos/o/r/deployments/1/statuses", func(w http.ResponseWriter, r *http.Request) {
v := new(DeploymentStatusRequest)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
testHeader(t, r, "Accept", mediaTypeDeploymentStatusPreview)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"state": "inactive", "description": "deploy"}`)
})
deploymentStatus, _, err := client.Repositories.CreateDeploymentStatus("o", "r", 1, input)
if err != nil {
t.Errorf("Repositories.CreateDeploymentStatus returned error: %v", err)
}
want := &DeploymentStatus{State: String("inactive"), Description: String("deploy")}
if !reflect.DeepEqual(deploymentStatus, want) {
t.Errorf("Repositories.CreateDeploymentStatus returned %+v, want %+v", deploymentStatus, want)
}
}

Loading…
Cancel
Save