Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions github/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitHub API docs call this "Get an enterprise installation for the authenticated app" so instead of "FindEnterpriseInstallation", can we use "GetEnterpriseInstallation"?

Wow... I see all the other ones in this file are called "Find*"... I'm not sure how I let that one slide by in code reviews. 😞

OK, let's take this to a vote from our dedicated team of reviewers... which do you like best?

  • Option A: Just name this one endpoint "GetEnterpriseInstallation"
  • Option B: Leave this one endpoint "FindEnterpriseInstallation"
  • Option C: Rename (breaking API change) ALL methods whose documentation URL starts with "get-" to "Get*" instead of "Find*" in this file
  • Option D: Something else?

cc: @stevehipwell - @alexandear - @zyfy29 - @Not-Dhananjay-Mishra - @munlicode

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for Option C.
Because in my opinion, method needs to be consistent with GitHub API docs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree Option C would be the cleanest long-term naming direction if the API is ever revisited more broadly.

For this PR, I used FindEnterpriseInstallation to stay consistent with the existing installation lookup methods in this file and avoid making a breaking API change as part of a small endpoint addition.

Let's wait for the other maintainers' votes as well.

//
// 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
Expand Down
35 changes: 35 additions & 0 deletions github/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading