From 35abceb5b3def166fe7517a6edb696fff56bf3db Mon Sep 17 00:00:00 2001 From: "T.J. Corrigan" Date: Thu, 30 Mar 2023 18:19:56 +0000 Subject: [PATCH] add support for deleting an org, 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 487405778f1..837dda89e0e 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 b30c48f1bce..1205ad00046 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()