diff --git a/github/apps.go b/github/apps.go index 91774865c80..f9d80b96515 100644 --- a/github/apps.go +++ b/github/apps.go @@ -457,6 +457,15 @@ func (s *AppsService) FindOrganizationInstallation(ctx context.Context, org stri return s.getInstallation(ctx, fmt.Sprintf("orgs/%v/installation", org)) } +// FindEnterpriseInstallation finds the enterprise's installation information. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/apps/apps#get-an-enterprise-installation-for-the-authenticated-app +// +//meta:operation GET /enterprises/{enterprise}/installation +func (s *AppsService) FindEnterpriseInstallation(ctx context.Context, enterprise string) (*Installation, *Response, error) { + return s.getInstallation(ctx, fmt.Sprintf("enterprises/%v/installation", enterprise)) +} + // FindRepositoryInstallation finds the repository's installation information. // // GitHub API docs: https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app diff --git a/github/apps_test.go b/github/apps_test.go index 7c874ed941a..5a2866d4cf4 100644 --- a/github/apps_test.go +++ b/github/apps_test.go @@ -604,6 +604,41 @@ func TestAppsService_FindOrganizationInstallation(t *testing.T) { }) } +func TestAppsService_FindEnterpriseInstallation(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/installation", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"id":1, "app_id":1, "target_id":1, "target_type": "Enterprise"}`) + }) + + ctx := t.Context() + installation, _, err := client.Apps.FindEnterpriseInstallation(ctx, "e") + if err != nil { + t.Errorf("Apps.FindEnterpriseInstallation returned error: %v", err) + } + + want := &Installation{ID: Ptr(int64(1)), AppID: Ptr(int64(1)), TargetID: Ptr(int64(1)), TargetType: Ptr("Enterprise")} + if !cmp.Equal(installation, want) { + t.Errorf("Apps.FindEnterpriseInstallation returned %+v, want %+v", installation, want) + } + + const methodName = "FindEnterpriseInstallation" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Apps.FindEnterpriseInstallation(ctx, "\n") + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Apps.FindEnterpriseInstallation(ctx, "e") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + func TestAppsService_FindRepositoryInstallation(t *testing.T) { t.Parallel() client, mux, _ := setup(t)