Skip to content

Commit 002ed1f

Browse files
authored
Add GetByRepository for InstallationsService (#61)
1 parent 95e3422 commit 002ed1f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

githubapp/installations.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ type InstallationsService interface {
5454
// It returns an InstallationNotFound error if no installation exists for
5555
// the owner.
5656
GetByOwner(ctx context.Context, owner string) (Installation, error)
57+
58+
// GetByRepository returns the installation for a repository.
59+
// It returns an InstallationNotFound error if no installation exists for
60+
// the repository.
61+
GetByRepository(ctx context.Context, owner string, repo string) (Installation, error)
5762
}
5863

5964
type defaultInstallationsService struct {
@@ -123,6 +128,19 @@ func (i defaultInstallationsService) GetByOwner(ctx context.Context, owner strin
123128
return Installation{}, errors.Wrapf(err, "failed to get installation for owner %q", owner)
124129
}
125130

131+
func (i defaultInstallationsService) GetByRepository(ctx context.Context, owner, repo string) (Installation, error) {
132+
installation, _, err := i.Apps.FindRepositoryInstallation(ctx, owner, repo)
133+
if err == nil {
134+
return toInstallation(installation), nil
135+
}
136+
137+
ownerRepo := fmt.Sprintf("%s/%s", owner, repo)
138+
if isNotFound(err) {
139+
return Installation{}, InstallationNotFound(ownerRepo)
140+
}
141+
return Installation{}, errors.Wrapf(err, "failed to get installation for repository %q", ownerRepo)
142+
}
143+
126144
// InstallationNotFound is returned when no installation exists for a
127145
// specific owner or repository.
128146
type InstallationNotFound string

0 commit comments

Comments
 (0)