Skip to content

Commit 43b1593

Browse files
github: add enterprise app installation lookup
1 parent b0245f1 commit 43b1593

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

github/apps.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,15 @@ func (s *AppsService) FindOrganizationInstallation(ctx context.Context, org stri
457457
return s.getInstallation(ctx, fmt.Sprintf("orgs/%v/installation", org))
458458
}
459459

460+
// FindEnterpriseInstallation finds the enterprise's installation information.
461+
//
462+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/apps/apps#get-an-enterprise-installation-for-the-authenticated-app
463+
//
464+
//meta:operation GET /enterprises/{enterprise}/installation
465+
func (s *AppsService) FindEnterpriseInstallation(ctx context.Context, enterprise string) (*Installation, *Response, error) {
466+
return s.getInstallation(ctx, fmt.Sprintf("enterprises/%v/installation", enterprise))
467+
}
468+
460469
// FindRepositoryInstallation finds the repository's installation information.
461470
//
462471
// GitHub API docs: https://docs.github.com/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app

github/apps_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,41 @@ func TestAppsService_FindOrganizationInstallation(t *testing.T) {
604604
})
605605
}
606606

607+
func TestAppsService_FindEnterpriseInstallation(t *testing.T) {
608+
t.Parallel()
609+
client, mux, _ := setup(t)
610+
611+
mux.HandleFunc("/enterprises/e/installation", func(w http.ResponseWriter, r *http.Request) {
612+
testMethod(t, r, "GET")
613+
fmt.Fprint(w, `{"id":1, "app_id":1, "target_id":1, "target_type": "Enterprise"}`)
614+
})
615+
616+
ctx := t.Context()
617+
installation, _, err := client.Apps.FindEnterpriseInstallation(ctx, "e")
618+
if err != nil {
619+
t.Errorf("Apps.FindEnterpriseInstallation returned error: %v", err)
620+
}
621+
622+
want := &Installation{ID: Ptr(int64(1)), AppID: Ptr(int64(1)), TargetID: Ptr(int64(1)), TargetType: Ptr("Enterprise")}
623+
if !cmp.Equal(installation, want) {
624+
t.Errorf("Apps.FindEnterpriseInstallation returned %+v, want %+v", installation, want)
625+
}
626+
627+
const methodName = "FindEnterpriseInstallation"
628+
testBadOptions(t, methodName, func() (err error) {
629+
_, _, err = client.Apps.FindEnterpriseInstallation(ctx, "\n")
630+
return err
631+
})
632+
633+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
634+
got, resp, err := client.Apps.FindEnterpriseInstallation(ctx, "e")
635+
if got != nil {
636+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
637+
}
638+
return resp, err
639+
})
640+
}
641+
607642
func TestAppsService_FindRepositoryInstallation(t *testing.T) {
608643
t.Parallel()
609644
client, mux, _ := setup(t)

0 commit comments

Comments
 (0)