diff --git a/github/apps.go b/github/apps.go index 66a1afbbe95..c930c587b81 100644 --- a/github/apps.go +++ b/github/apps.go @@ -8,6 +8,7 @@ package github import ( "context" "fmt" + "net/http" ) // AppsService provides access to the installation related functions @@ -388,7 +389,11 @@ func (s *AppsService) DeleteInstallation(ctx context.Context, id int64) (*Respon return nil, err } - return s.client.Do(req, nil) + resp, err := s.client.Do(req, nil) + if err != nil && (resp == nil || resp.StatusCode != http.StatusAccepted) { + return resp, err + } + return resp, nil } // CreateInstallationToken creates a new installation token. diff --git a/github/apps_test.go b/github/apps_test.go index 1c1e00b3f71..ac195d5ee35 100644 --- a/github/apps_test.go +++ b/github/apps_test.go @@ -377,7 +377,7 @@ func TestAppsService_DeleteInstallation(t *testing.T) { mux.HandleFunc("/app/installations/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") - w.WriteHeader(http.StatusNoContent) + w.WriteHeader(http.StatusAccepted) }) ctx := t.Context() @@ -397,6 +397,22 @@ func TestAppsService_DeleteInstallation(t *testing.T) { }) } +func TestAppsService_DeleteInstallationNoContent(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/app/installations/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + + ctx := t.Context() + _, err := client.Apps.DeleteInstallation(ctx, 1) + if err != nil { + t.Errorf("Apps.DeleteInstallation returned error: %v", err) + } +} + func TestAppsService_CreateInstallationToken(t *testing.T) { t.Parallel() client, mux, _ := setup(t)