Skip to content

Commit

Permalink
Add support for deleting an org (#2728)
Browse files Browse the repository at this point in the history
Fixes: #2726.
  • Loading branch information
tjcorr committed Mar 31, 2023
1 parent a29e30c commit 388d921
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions github/orgs.go
Expand Up @@ -262,6 +262,19 @@ func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organ
return o, resp, nil
}

// Delete an organization by name.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/orgs#delete-an-organization
func (s *OrganizationsService) Delete(ctx context.Context, org string) (*Response, error) {
u := fmt.Sprintf("orgs/%v", org)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}

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

// ListInstallations lists installations for an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/orgs#list-app-installations-for-an-organization
Expand Down
25 changes: 25 additions & 0 deletions github/orgs_test.go
Expand Up @@ -315,6 +315,31 @@ func TestOrganizationsService_Edit_invalidOrg(t *testing.T) {
testURLParseError(t, err)
}

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

mux.HandleFunc("/orgs/o", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})

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

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

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Organizations.Delete(ctx, "o")
})
}

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

0 comments on commit 388d921

Please sign in to comment.