Compare commits
2 Commits
3d8ad75476
...
d7fda7c901
Author | SHA1 | Date |
---|---|---|
Massaki Archambault | d7fda7c901 | |
Massaki Archambault | c5df43b3e7 |
|
@ -28,8 +28,8 @@ gitlab:
|
|||
group_ids:
|
||||
- 9970 # gitlab-org
|
||||
|
||||
# A list of the user ids to expose their personal projects in the filesystem.
|
||||
user_ids: []
|
||||
# A list of the name of the user to expose their repositories un the filesystem
|
||||
user_names: []
|
||||
|
||||
# Set how archived projects are handled.
|
||||
# If set to "show", it will add them to the filesystem and treat them like any other project
|
||||
|
|
|
@ -9,8 +9,8 @@ gitlab:
|
|||
pull_method: ssh
|
||||
group_ids:
|
||||
- 123
|
||||
user_ids:
|
||||
- 456
|
||||
user_names:
|
||||
- test-user
|
||||
archived_project_handling: hide
|
||||
include_current_user: true
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ type (
|
|||
Token string `yaml:"token,omitempty"`
|
||||
|
||||
GroupIDs []int `yaml:"group_ids,omitempty"`
|
||||
UserIDs []int `yaml:"user_ids,omitempty"`
|
||||
UserNames []string `yaml:"user_ids,omitempty"`
|
||||
|
||||
ArchivedProjectHandling string `yaml:"archived_project_handling,omitempty"`
|
||||
IncludeCurrentUser bool `yaml:"include_current_user,omitempty"`
|
||||
|
@ -96,7 +96,7 @@ func LoadConfig(configPath string) (*Config, error) {
|
|||
Token: "",
|
||||
PullMethod: "http",
|
||||
GroupIDs: []int{9970},
|
||||
UserIDs: []int{},
|
||||
UserNames: []string{},
|
||||
ArchivedProjectHandling: "hide",
|
||||
IncludeCurrentUser: true,
|
||||
},
|
||||
|
|
|
@ -25,7 +25,7 @@ func TestLoadConfig(t *testing.T) {
|
|||
Token: "12345",
|
||||
PullMethod: "ssh",
|
||||
GroupIDs: []int{123},
|
||||
UserIDs: []int{456},
|
||||
UserNames: []int{456},
|
||||
ArchivedProjectHandling: "hide",
|
||||
IncludeCurrentUser: true,
|
||||
},
|
||||
|
@ -148,7 +148,7 @@ func TestMakeGitlabConfig(t *testing.T) {
|
|||
PullMethod: "http",
|
||||
Token: "",
|
||||
GroupIDs: []int{9970},
|
||||
UserIDs: []int{},
|
||||
UserNames: []int{},
|
||||
ArchivedProjectHandling: "hide",
|
||||
IncludeCurrentUser: true,
|
||||
},
|
||||
|
@ -158,7 +158,7 @@ func TestMakeGitlabConfig(t *testing.T) {
|
|||
PullMethod: "http",
|
||||
Token: "",
|
||||
GroupIDs: []int{9970},
|
||||
UserIDs: []int{},
|
||||
UserNames: []int{},
|
||||
ArchivedProjectHandling: "hide",
|
||||
IncludeCurrentUser: true,
|
||||
},
|
||||
|
@ -173,7 +173,7 @@ func TestMakeGitlabConfig(t *testing.T) {
|
|||
PullMethod: "invalid",
|
||||
Token: "",
|
||||
GroupIDs: []int{9970},
|
||||
UserIDs: []int{},
|
||||
UserNames: []int{},
|
||||
ArchivedProjectHandling: "hide",
|
||||
IncludeCurrentUser: true,
|
||||
},
|
||||
|
@ -187,7 +187,7 @@ func TestMakeGitlabConfig(t *testing.T) {
|
|||
PullMethod: "http",
|
||||
Token: "",
|
||||
GroupIDs: []int{9970},
|
||||
UserIDs: []int{},
|
||||
UserNames: []int{},
|
||||
IncludeCurrentUser: true,
|
||||
ArchivedProjectHandling: "invalid",
|
||||
},
|
||||
|
|
|
@ -19,6 +19,8 @@ type gitlabClient struct {
|
|||
|
||||
rootContent map[string]fstree.GroupSource
|
||||
|
||||
userIDs []int
|
||||
|
||||
// API response cache
|
||||
groupCacheMux sync.RWMutex
|
||||
groupCache map[int]*Group
|
||||
|
@ -43,6 +45,8 @@ func NewClient(logger *slog.Logger, config config.GitlabClientConfig) (*gitlabCl
|
|||
|
||||
rootContent: nil,
|
||||
|
||||
userIDs: []int{},
|
||||
|
||||
groupCache: map[int]*Group{},
|
||||
userCache: map[int]*User{},
|
||||
}
|
||||
|
@ -52,7 +56,17 @@ func NewClient(logger *slog.Logger, config config.GitlabClientConfig) (*gitlabCl
|
|||
if err != nil {
|
||||
logger.Warn("failed to fetch the current user:", "error", err.Error())
|
||||
} else {
|
||||
gitlabClient.UserIDs = append(gitlabClient.UserIDs, currentUser.ID)
|
||||
gitlabClient.userIDs = append(gitlabClient.userIDs, currentUser.ID)
|
||||
}
|
||||
|
||||
// Fetch the configured users and add them to the list
|
||||
for _, userName := range config.UserNames {
|
||||
user, _, err := client.Users.ListUsers(&gitlab.ListUsersOptions{Username: &userName})
|
||||
if err != nil || len(user) != 1 {
|
||||
logger.Warn("failed to fetch the user", "userName", userName, "error", err.Error())
|
||||
} else {
|
||||
gitlabClient.userIDs = append(gitlabClient.userIDs, user[0].ID)
|
||||
}
|
||||
}
|
||||
|
||||
return gitlabClient, nil
|
||||
|
@ -72,7 +86,7 @@ func (c *gitlabClient) FetchRootGroupContent() (map[string]fstree.GroupSource, e
|
|||
rootGroupCache[group.Name] = group
|
||||
}
|
||||
// fetch users
|
||||
for _, uid := range c.UserIDs {
|
||||
for _, uid := range c.userIDs {
|
||||
user, err := c.fetchUser(uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -86,7 +100,7 @@ func (c *gitlabClient) FetchRootGroupContent() (map[string]fstree.GroupSource, e
|
|||
}
|
||||
|
||||
func (c *gitlabClient) FetchGroupContent(gid uint64) (map[string]fstree.GroupSource, map[string]fstree.RepositorySource, error) {
|
||||
if slices.Contains[[]int, int](c.UserIDs, int(gid)) {
|
||||
if slices.Contains[[]int, int](c.userIDs, int(gid)) {
|
||||
// gid is a user
|
||||
user, err := c.fetchUser(int(gid))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue