Skip to content

Add RemoveRequiredStatusChecks API and tests #1776

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 1 commit into from
Jan 18, 2021
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
13 changes: 13 additions & 0 deletions github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,19 @@ func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, ow
return sc, resp, nil
}

// RemoveRequiredStatusChecks removes the required status checks for a given protected branch.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#remove-status-check-protection
func (s *RepositoriesService) RemoveRequiredStatusChecks(ctx context.Context, owner, repo, branch string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, branch)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}

return s.client.Do(ctx, req, nil)
}

// License gets the contents of a repository's license if one is detected.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/licenses/#get-the-license-for-a-repository
Expand Down
27 changes: 27 additions & 0 deletions github/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,33 @@ func TestRepositoriesService_UpdateRequiredStatusChecks(t *testing.T) {
})
}

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

mux.HandleFunc("/repos/o/r/branches/b/protection/required_status_checks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testHeader(t, r, "Accept", mediaTypeV3)
w.WriteHeader(http.StatusNoContent)
})

ctx := context.Background()
_, err := client.Repositories.RemoveRequiredStatusChecks(ctx, "o", "r", "b")
if err != nil {
t.Errorf("Repositories.RemoveRequiredStatusChecks returned error: %v", err)
}

const methodName = "RemoveRequiredStatusChecks"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Repositories.RemoveRequiredStatusChecks(ctx, "\n", "\n", "\n")
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Repositories.RemoveRequiredStatusChecks(ctx, "o", "r", "b")
})
}

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