Skip to content

Commit c8d6f6a

Browse files
committed
fix repository fetch
1 parent 2e00335 commit c8d6f6a

File tree

8 files changed

+26
-15
lines changed

8 files changed

+26
-15
lines changed

cache/cache.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cache
22

33
import (
44
"context"
5+
"log/slog"
56
"sync"
67
"time"
78

@@ -10,6 +11,7 @@ import (
1011

1112
type Cache struct {
1213
backend types.GitForge
14+
logger *slog.Logger
1315

1416
rootContentLock sync.RWMutex
1517
cachedRootContent map[string]types.GroupSource
@@ -18,9 +20,10 @@ type Cache struct {
1820
cachedContent map[string]CachedContent
1921
}
2022

21-
func NewForgeCache(backend types.GitForge) types.GitForge {
23+
func NewForgeCache(backend types.GitForge, logger *slog.Logger) types.GitForge {
2224
return &Cache{
2325
backend: backend,
26+
logger: logger,
2427

2528
cachedContent: map[string]CachedContent{},
2629
}
@@ -43,6 +46,7 @@ func (c *Cache) FetchRootGroupContent(ctx context.Context) (map[string]types.Gro
4346
// check to make sure the data is still not there,
4447
// since RWMutex is not upgradeable and another thread may have grabbed the lock in the meantime
4548
if c.cachedRootContent == nil {
49+
c.logger.Info("Fetching root content from backend")
4650
content, err := c.backend.FetchRootGroupContent(ctx)
4751
if err != nil {
4852
return nil, err
@@ -56,10 +60,14 @@ func (c *Cache) FetchRootGroupContent(ctx context.Context) (map[string]types.Gro
5660
}
5761

5862
func (c *Cache) FetchGroupContent(ctx context.Context, source types.GroupSource) (types.GroupContent, error) {
63+
logger := c.logger.With("groupID", source.GetGroupID()).With("groupPath", source.GetGroupPath())
64+
5965
c.contentLock.RLock()
6066
if cachedContent, found := c.cachedContent[source.GetGroupPath()]; !found {
6167
c.contentLock.RUnlock()
6268

69+
logger.Debug("Cache miss")
70+
6371
// acquire write lock
6472
c.contentLock.Lock()
6573
defer c.contentLock.Unlock()
@@ -70,6 +78,7 @@ func (c *Cache) FetchGroupContent(ctx context.Context, source types.GroupSource)
7078
}
7179

7280
// fetch content from backend and cache it
81+
logger.Info("Fetching content from backend")
7382
content, err := c.backend.FetchGroupContent(ctx, source)
7483
if err != nil {
7584
return types.GroupContent{}, err
@@ -81,6 +90,7 @@ func (c *Cache) FetchGroupContent(ctx context.Context, source types.GroupSource)
8190
return content, nil
8291
} else {
8392
c.contentLock.RUnlock()
93+
logger.Debug("Cache hit")
8494
return cachedContent.GroupContent, nil
8595
}
8696
}

config/loader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type (
3939
URL string `yaml:"url,omitempty"`
4040
Token string `yaml:"token,omitempty"`
4141

42-
GroupIDs []uint64 `yaml:"group_ids,omitempty"`
42+
GroupIDs []int `yaml:"group_ids,omitempty"`
4343
UserNames []string `yaml:"user_names,omitempty"`
4444

4545
ArchivedProjectHandling string `yaml:"archived_project_handling,omitempty"`
@@ -97,7 +97,7 @@ func LoadConfig(configPath string) (*Config, error) {
9797
URL: "https://gitlab.com",
9898
Token: "",
9999
PullMethod: "http",
100-
GroupIDs: []uint64{9970},
100+
GroupIDs: []int{9970},
101101
UserNames: []string{},
102102
ArchivedProjectHandling: "hide",
103103
IncludeCurrentUser: true,

config/loader_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestLoadConfig(t *testing.T) {
2424
URL: "https://example.com",
2525
Token: "12345",
2626
PullMethod: "ssh",
27-
GroupIDs: []uint64{123},
27+
GroupIDs: []int{123},
2828
UserNames: []string{"test-user"},
2929
ArchivedProjectHandling: "hide",
3030
IncludeCurrentUser: true,
@@ -147,7 +147,7 @@ func TestMakeGitlabConfig(t *testing.T) {
147147
URL: "https://gitlab.com",
148148
PullMethod: "http",
149149
Token: "",
150-
GroupIDs: []uint64{9970},
150+
GroupIDs: []int{9970},
151151
UserNames: []string{},
152152
ArchivedProjectHandling: "hide",
153153
IncludeCurrentUser: true,
@@ -157,7 +157,7 @@ func TestMakeGitlabConfig(t *testing.T) {
157157
URL: "https://gitlab.com",
158158
PullMethod: "http",
159159
Token: "",
160-
GroupIDs: []uint64{9970},
160+
GroupIDs: []int{9970},
161161
UserNames: []string{},
162162
ArchivedProjectHandling: "hide",
163163
IncludeCurrentUser: true,
@@ -172,7 +172,7 @@ func TestMakeGitlabConfig(t *testing.T) {
172172
URL: "https://gitlab.com",
173173
PullMethod: "invalid",
174174
Token: "",
175-
GroupIDs: []uint64{9970},
175+
GroupIDs: []int{9970},
176176
UserNames: []string{},
177177
ArchivedProjectHandling: "hide",
178178
IncludeCurrentUser: true,
@@ -186,7 +186,7 @@ func TestMakeGitlabConfig(t *testing.T) {
186186
URL: "https://gitlab.com",
187187
PullMethod: "http",
188188
Token: "",
189-
GroupIDs: []uint64{9970},
189+
GroupIDs: []int{9970},
190190
UserNames: []string{},
191191
IncludeCurrentUser: true,
192192
ArchivedProjectHandling: "invalid",

forges/gitlab/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func (c *gitlabClient) FetchRootGroupContent(ctx context.Context) (map[string]ty
8383

8484
func (c *gitlabClient) FetchGroupContent(ctx context.Context, source types.GroupSource) (types.GroupContent, error) {
8585
if _, found := c.users[source.GetGroupPath()]; found {
86-
return c.fetchUserContent(ctx, source.GetGroupID())
86+
return c.fetchUserContent(ctx, int(source.GetGroupID()))
8787
} else {
88-
return c.fetchGroupContent(ctx, source.GetGroupID())
88+
return c.fetchGroupContent(ctx, int(source.GetGroupID()))
8989
}
9090
}

forges/gitlab/group.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (c *gitlabClient) newGroupFromGitlabGroup(gitlabGroup *gitlab.Group) *Group
3434
}
3535
}
3636

37-
func (c *gitlabClient) fetchGroup(ctx context.Context, gid uint64) (*Group, error) {
37+
func (c *gitlabClient) fetchGroup(ctx context.Context, gid int) (*Group, error) {
3838
gitlabGroup, _, err := c.client.Groups.GetGroup(gid, &gitlab.GetGroupOptions{})
3939
if err != nil {
4040
return nil, fmt.Errorf("failed to fetch group with id %v: %v", gid, err)
@@ -43,7 +43,7 @@ func (c *gitlabClient) fetchGroup(ctx context.Context, gid uint64) (*Group, erro
4343
return c.newGroupFromGitlabGroup(gitlabGroup), nil
4444
}
4545

46-
func (c *gitlabClient) fetchGroupContent(ctx context.Context, gid uint64) (types.GroupContent, error) {
46+
func (c *gitlabClient) fetchGroupContent(ctx context.Context, gid int) (types.GroupContent, error) {
4747
childGroups := make(map[string]types.GroupSource)
4848
childProjects := make(map[string]types.RepositorySource)
4949

forges/gitlab/project.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func (c *gitlabClient) newProjectFromGitlabProject(project *gitlab.Project) *Pro
3838
}
3939
p := Project{
4040
ID: project.ID,
41-
Path: project.Path,
41+
Name: project.Name,
42+
Path: project.PathWithNamespace,
4243
DefaultBranch: project.DefaultBranch,
4344
}
4445
if p.DefaultBranch == "" {

forges/gitlab/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (c *gitlabClient) fetchUser(ctx context.Context, uid int) (*User, error) {
3232
}, nil
3333
}
3434

35-
func (c *gitlabClient) fetchUserContent(ctx context.Context, uid uint64) (types.GroupContent, error) {
35+
func (c *gitlabClient) fetchUserContent(ctx context.Context, uid int) (types.GroupContent, error) {
3636
childProjects := make(map[string]types.RepositorySource)
3737

3838
// Fetch the user repositories

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func main() {
105105
}
106106

107107
// setup cache
108-
cache := cache.NewForgeCache(gitForgeClient)
108+
cache := cache.NewForgeCache(gitForgeClient, logger)
109109

110110
// Start the filesystem
111111
err = fstree.Start(

0 commit comments

Comments
 (0)