@@ -2,6 +2,7 @@ package grpc
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
6
7
"github.com/google/uuid"
7
8
"github.com/nais/api/internal/database"
@@ -15,7 +16,7 @@ import (
15
16
16
17
type repo interface {
17
18
database.TeamRepo
18
- database.ReconcilerResourceRepo
19
+ database.ReconcilerStateRepo
19
20
database.RepositoryAuthorizationRepo
20
21
}
21
22
@@ -153,33 +154,37 @@ func (t *TeamsServer) ListAuthorizedRepositories(ctx context.Context, req *proto
153
154
teamSlug := slug .Slug (req .Slug )
154
155
155
156
// 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
- })
157
+ res , err := t .db .GetReconcilerStateForTeam (ctx , "github:team" , teamSlug )
161
158
if err != nil {
162
159
return nil , status .Errorf (codes .Internal , "fetching github repositories for team: %s" , err )
163
160
}
164
161
162
+ var state struct {
163
+ Repos []struct {
164
+ Name string `json:"name"`
165
+ } `json:"repositories"`
166
+ }
167
+
168
+ err = json .Unmarshal (res .Value , & state )
169
+ if err != nil {
170
+ return nil , err
171
+ }
172
+
165
173
// filter out repositories without authorizations
166
174
filtered := make ([]string , 0 )
167
- for _ , r := range res {
168
- repoName := string (r .Value )
169
-
170
- authorizations , err := t .db .GetRepositoryAuthorizations (ctx , teamSlug , repoName )
175
+ for _ , repo := range state .Repos {
176
+ authorizations , err := t .db .GetRepositoryAuthorizations (ctx , teamSlug , repo .Name )
171
177
if err != nil {
172
178
return nil , status .Errorf (codes .Internal , "fetching authorization for repository: %s" , err )
173
179
}
174
180
175
181
if len (authorizations ) > 0 {
176
- filtered = append (filtered , repoName )
182
+ filtered = append (filtered , repo . Name )
177
183
}
178
184
}
179
185
180
186
return & protoapi.ListAuthorizedRepositoriesResponse {
181
187
GithubRepositories : filtered ,
182
- PageInfo : pageInfo (req , total ),
183
188
}, nil
184
189
}
185
190
0 commit comments