Skip to content

Commit 5a0cfdd

Browse files
committed
fix: retrieve user if token provided
1 parent ff5783a commit 5a0cfdd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

internal/mirroring/instance.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,22 @@ func NewGitlabInstance(initArgs *GitlabInstanceOpts) (*GitlabInstance, error) {
7272
return nil, err
7373
}
7474

75-
// Get the current user ID
76-
user, _, err := gitlabClient.Users.CurrentUser()
77-
if err != nil {
78-
return nil, fmt.Errorf("failed to get current user: %w", err)
79-
}
80-
8175
gitlabInstance := &GitlabInstance{
8276
Gitlab: gitlabClient,
8377
Projects: make(map[string]*gitlab.Project),
8478
Groups: make(map[string]*gitlab.Group),
8579
Role: initArgs.Role,
8680
InstanceSize: initArgs.InstanceSize,
8781
GitAuth: helpers.BuildHTTPAuth("", initArgs.GitlabToken),
88-
UserID: user.ID,
82+
}
83+
84+
if initArgs.GitlabToken != "" {
85+
// Get the current user ID
86+
user, _, err := gitlabClient.Users.CurrentUser()
87+
if err != nil {
88+
return nil, fmt.Errorf("failed to get current user: %w", err)
89+
}
90+
gitlabInstance.UserID = user.ID
8991
}
9092

9193
return gitlabInstance, nil

0 commit comments

Comments
 (0)