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
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)
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

		testMethod(t, r, "DELETE")
		w.WriteHeader(http.StatusNoContent)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll add a test for that status


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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the API docs, it looks like it should return 204 No Content on a successful request?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @nightlark.
@nomonamo - once you add the line above, then this can be changed to http.StatusNoContent and the 404 can be changed to 204.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I was just adding a test for a non-existent deployment (id: 2), in an attempt to increase test coverage.

}
}

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