Skip to content

Commit 9c17d51

Browse files
authored
Add RemoveRequiredStatusChecks API and tests (#1776)
Fixes #1770.
1 parent e3dedb4 commit 9c17d51

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

github/repos.go

+13
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,19 @@ func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, ow
11371137
return sc, resp, nil
11381138
}
11391139

1140+
// RemoveRequiredStatusChecks removes the required status checks for a given protected branch.
1141+
//
1142+
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#remove-status-check-protection
1143+
func (s *RepositoriesService) RemoveRequiredStatusChecks(ctx context.Context, owner, repo, branch string) (*Response, error) {
1144+
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, branch)
1145+
req, err := s.client.NewRequest("DELETE", u, nil)
1146+
if err != nil {
1147+
return nil, err
1148+
}
1149+
1150+
return s.client.Do(ctx, req, nil)
1151+
}
1152+
11401153
// License gets the contents of a repository's license if one is detected.
11411154
//
11421155
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/licenses/#get-the-license-for-a-repository

github/repos_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,33 @@ func TestRepositoriesService_UpdateRequiredStatusChecks(t *testing.T) {
13781378
})
13791379
}
13801380

1381+
func TestRepositoriesService_RemoveRequiredStatusChecks(t *testing.T) {
1382+
client, mux, _, teardown := setup()
1383+
defer teardown()
1384+
1385+
mux.HandleFunc("/repos/o/r/branches/b/protection/required_status_checks", func(w http.ResponseWriter, r *http.Request) {
1386+
testMethod(t, r, "DELETE")
1387+
testHeader(t, r, "Accept", mediaTypeV3)
1388+
w.WriteHeader(http.StatusNoContent)
1389+
})
1390+
1391+
ctx := context.Background()
1392+
_, err := client.Repositories.RemoveRequiredStatusChecks(ctx, "o", "r", "b")
1393+
if err != nil {
1394+
t.Errorf("Repositories.RemoveRequiredStatusChecks returned error: %v", err)
1395+
}
1396+
1397+
const methodName = "RemoveRequiredStatusChecks"
1398+
testBadOptions(t, methodName, func() (err error) {
1399+
_, err = client.Repositories.RemoveRequiredStatusChecks(ctx, "\n", "\n", "\n")
1400+
return err
1401+
})
1402+
1403+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
1404+
return client.Repositories.RemoveRequiredStatusChecks(ctx, "o", "r", "b")
1405+
})
1406+
}
1407+
13811408
func TestRepositoriesService_ListRequiredStatusChecksContexts(t *testing.T) {
13821409
client, mux, _, teardown := setup()
13831410
defer teardown()

0 commit comments

Comments
 (0)