@@ -13,8 +13,15 @@ import (
13
13
"k8s.io/utils/ptr"
14
14
)
15
15
16
+ type repo interface {
17
+ database.TeamRepo
18
+ database.ReconcilerResourceRepo
19
+ database.RepositoryAuthorizationRepo
20
+ }
21
+
16
22
type TeamsServer struct {
17
- db database.TeamRepo
23
+ db repo
24
+
18
25
protoapi.UnimplementedTeamsServer
19
26
}
20
27
@@ -142,6 +149,40 @@ func (t *TeamsServer) Environments(ctx context.Context, req *protoapi.ListTeamEn
142
149
return resp , nil
143
150
}
144
151
152
+ func (t * TeamsServer ) ListAuthorizedRepositories (ctx context.Context , req * protoapi.ListAuthorizedRepositoriesRequest ) (* protoapi.ListAuthorizedRepositoriesResponse , error ) {
153
+ teamSlug := slug .Slug (req .Slug )
154
+
155
+ // get all repositories for team
156
+ limit , offset := pagination (req )
157
+ res , total , err := t .db .GetReconcilerResourcesByKey (ctx , "github:team" , teamSlug , "repo" , database.Page {
158
+ Limit : limit ,
159
+ Offset : offset ,
160
+ })
161
+ if err != nil {
162
+ return nil , status .Errorf (codes .Internal , "fetching github repositories for team: %s" , err )
163
+ }
164
+
165
+ // filter out repositories without authorizations
166
+ filtered := make ([]string , 0 )
167
+ for _ , r := range res {
168
+ repoName := string (r .Value )
169
+
170
+ authorizations , err := t .db .GetRepositoryAuthorizations (ctx , teamSlug , repoName )
171
+ if err != nil {
172
+ return nil , status .Errorf (codes .Internal , "fetching authorization for repository: %s" , err )
173
+ }
174
+
175
+ if len (authorizations ) > 0 {
176
+ filtered = append (filtered , repoName )
177
+ }
178
+ }
179
+
180
+ return & protoapi.ListAuthorizedRepositoriesResponse {
181
+ GithubRepositories : filtered ,
182
+ PageInfo : pageInfo (req , total ),
183
+ }, nil
184
+ }
185
+
145
186
func toProtoTeam (team * database.Team ) * protoapi.Team {
146
187
var aID * string
147
188
if team .AzureGroupID != nil {
0 commit comments