Skip to content

Commit

Permalink
Add DeleteDeployment for Repositories (#1555)
Browse files Browse the repository at this point in the history
Fixes: #1554.
  • Loading branch information
Pablo Pérez Schröder authored Jun 17, 2020
1 parent ecafd12 commit 3312662
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions github/repos_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo
return d, resp, nil
}

// DeleteDeployment deletes an existing deployment for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#delete-a-deployment
func (s *RepositoriesService) DeleteDeployment(ctx context.Context, owner, repo string, deploymentID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v", owner, repo, deploymentID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}

// DeploymentStatus represents the status of a
// particular deployment.
type DeploymentStatus struct {
Expand Down
26 changes: 26 additions & 0 deletions github/repos_deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ func TestRepositoriesService_CreateDeployment(t *testing.T) {
}
}

func TestRepositoriesService_DeleteDeployment(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/deployments/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNoContent)
})

resp, err := client.Repositories.DeleteDeployment(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.DeleteDeployment returned error: %v", err)
}
if resp.StatusCode != http.StatusNoContent {
t.Error("Repositories.DeleteDeployment should return a 204 status")
}

resp, err = client.Repositories.DeleteDeployment(context.Background(), "o", "r", 2)
if err == nil {
t.Error("Repositories.DeleteDeployment should return an error")
}
if resp.StatusCode != http.StatusNotFound {
t.Error("Repositories.DeleteDeployment should return a 404 status")
}
}

func TestRepositoriesService_ListDeploymentStatuses(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down

0 comments on commit 3312662

Please sign in to comment.