+
Skip to content

Add DeleteDeployment for Repositories #1555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 17, 2020
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
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载