From 388d921556cf438dde967f0e86658b8a7af9c53b Mon Sep 17 00:00:00 2001 From: "T.J. Corrigan" Date: Fri, 31 Mar 2023 08:41:01 -0500 Subject: [PATCH] Add support for deleting an org (#2728) Fixes: #2726. --- github/orgs.go | 13 +++++++++++++ github/orgs_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/github/orgs.go b/github/orgs.go index 487405778f..837dda89e0 100644 --- a/github/orgs.go +++ b/github/orgs.go @@ -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 diff --git a/github/orgs_test.go b/github/orgs_test.go index b30c48f1bc..1205ad0004 100644 --- a/github/orgs_test.go +++ b/github/orgs_test.go @@ -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()