Skip to content

Commit 58d0ffc

Browse files
tronghnReasonable-Solutions
authored andcommitted
teams: resources -> state
1 parent c1b0f44 commit 58d0ffc

File tree

4 files changed

+251
-220
lines changed

4 files changed

+251
-220
lines changed

internal/grpc/teams.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package grpc
22

33
import (
44
"context"
5+
"encoding/json"
56

67
"github.com/google/uuid"
78
"github.com/nais/api/internal/database"
@@ -15,7 +16,7 @@ import (
1516

1617
type repo interface {
1718
database.TeamRepo
18-
database.ReconcilerResourceRepo
19+
database.ReconcilerStateRepo
1920
database.RepositoryAuthorizationRepo
2021
}
2122

@@ -153,33 +154,37 @@ func (t *TeamsServer) ListAuthorizedRepositories(ctx context.Context, req *proto
153154
teamSlug := slug.Slug(req.Slug)
154155

155156
// 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)
161158
if err != nil {
162159
return nil, status.Errorf(codes.Internal, "fetching github repositories for team: %s", err)
163160
}
164161

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+
165173
// filter out repositories without authorizations
166174
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)
171177
if err != nil {
172178
return nil, status.Errorf(codes.Internal, "fetching authorization for repository: %s", err)
173179
}
174180

175181
if len(authorizations) > 0 {
176-
filtered = append(filtered, repoName)
182+
filtered = append(filtered, repo.Name)
177183
}
178184
}
179185

180186
return &protoapi.ListAuthorizedRepositoriesResponse{
181187
GithubRepositories: filtered,
182-
PageInfo: pageInfo(req, total),
183188
}, nil
184189
}
185190

pkg/protoapi/mock_teams_server.go

+59
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/protoapi/schema/teams.proto

-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ message Team {
1717

1818
message ListAuthorizedRepositoriesRequest {
1919
string slug = 1;
20-
int64 limit = 2;
21-
int64 offset = 3;
2220
}
2321

2422
message ListAuthorizedRepositoriesResponse {
2523
repeated string github_repositories = 1;
26-
PageInfo page_info = 2;
2724
}
2825

2926
service Teams {

0 commit comments

Comments
 (0)