@@ -32,17 +32,23 @@ import (
3232
3333//go:generate go run go.uber.org/mock/mockgen -package mock_$GOPACKAGE -destination=./mock/$GOFILE -source=./$GOFILE
3434
35+ // GitHubProviderFacet encapsulates the created db.Provider and additional GitHub specific properties
36+ type GitHubProviderFacet struct {
37+ Provider * db.Provider
38+ InstallationOwner string
39+ }
40+
3541// GitHubProviderService encapsulates methods for creating and updating providers
3642type GitHubProviderService interface {
3743 // CreateGitHubAppProvider creates a GitHub App provider with an installation ID in a known project
3844 CreateGitHubAppProvider (ctx context.Context , token oauth2.Token , stateData db.GetProjectIDBySessionStateRow ,
39- installationID int64 , state string ) (* db. Provider , error )
45+ installationID int64 , state string ) (* GitHubProviderFacet , error )
4046 // CreateGitHubAppWithoutInvitation either creates a new project for the selected app, or stores
4147 // the installation in preparation for creating a new project when the authorizing user logs in.
4248 //
4349 // Note that this function may return nil, nil if the installation user is not known to Minder.
4450 CreateGitHubAppWithoutInvitation (ctx context.Context , qtx db.ExtendQuerier , userID int64 ,
45- installationID int64 ) (* db.Project , * db. Provider , error )
51+ installationID int64 ) (* db.Project , * GitHubProviderFacet , error )
4652 // ValidateGitHubInstallationId checks if the supplied GitHub token has access to the installation ID
4753 ValidateGitHubInstallationId (ctx context.Context , token * oauth2.Token , installationID int64 ) error
4854 // DeleteGitHubAppInstallation deletes the GitHub App installation and provider from the database.
@@ -106,13 +112,13 @@ func (p *ghProviderService) CreateGitHubAppProvider(
106112 stateData db.GetProjectIDBySessionStateRow ,
107113 installationID int64 ,
108114 state string ,
109- ) (* db. Provider , error ) {
115+ ) (* GitHubProviderFacet , error ) {
110116 installationOwner , err := p .getInstallationOwner (ctx , installationID )
111117 if err != nil {
112118 return nil , err
113119 }
114120
115- return db .WithTransaction (p .store , func (qtx db.ExtendQuerier ) (* db. Provider , error ) {
121+ return db .WithTransaction (p .store , func (qtx db.ExtendQuerier ) (* GitHubProviderFacet , error ) {
116122 validateOwnership := func (ctx context.Context ) error {
117123 // Older enrollments may not have a RemoteUser stored; these should age out fairly quickly.
118124 p .mt .AddTokenOpCount (ctx , "check" , stateData .RemoteUser .Valid )
@@ -157,7 +163,10 @@ func (p *ghProviderService) CreateGitHubAppProvider(
157163 },
158164 )
159165
160- return & provider , err
166+ return & GitHubProviderFacet {
167+ Provider : & provider ,
168+ InstallationOwner : installationOwner .GetLogin (),
169+ }, err
161170 })
162171}
163172
@@ -170,7 +179,7 @@ func (p *ghProviderService) CreateGitHubAppWithoutInvitation(
170179 qtx db.ExtendQuerier ,
171180 userID int64 ,
172181 installationID int64 ,
173- ) (* db.Project , * db. Provider , error ) {
182+ ) (* db.Project , * GitHubProviderFacet , error ) {
174183 installationOwner , err := p .getInstallationOwner (ctx , installationID )
175184 if err != nil {
176185 return nil , nil , err
@@ -213,7 +222,10 @@ func (p *ghProviderService) CreateGitHubAppWithoutInvitation(
213222
214223 }
215224
216- return project , & provider , err
225+ return project , & GitHubProviderFacet {
226+ Provider : & provider ,
227+ InstallationOwner : installationOwner .GetLogin (),
228+ }, err
217229}
218230
219231// Internal shared implementation between CreateGitHubAppProvider and CreateGitHubAppWithoutInvitation.
0 commit comments