@@ -54,6 +54,11 @@ type InstallationsService interface {
54
54
// It returns an InstallationNotFound error if no installation exists for
55
55
// the owner.
56
56
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 )
57
62
}
58
63
59
64
type defaultInstallationsService struct {
@@ -123,6 +128,19 @@ func (i defaultInstallationsService) GetByOwner(ctx context.Context, owner strin
123
128
return Installation {}, errors .Wrapf (err , "failed to get installation for owner %q" , owner )
124
129
}
125
130
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
+
126
144
// InstallationNotFound is returned when no installation exists for a
127
145
// specific owner or repository.
128
146
type InstallationNotFound string
0 commit comments