correctly honor include_current_user config option
This commit is contained in:
parent
bfdb1f0946
commit
7afde6a9eb
|
@ -21,7 +21,8 @@ type Refresher interface {
|
|||
}
|
||||
|
||||
type GitlabClientParam struct {
|
||||
PullMethod string
|
||||
PullMethod string
|
||||
IncludeCurrentUser bool
|
||||
}
|
||||
|
||||
type gitlabClient struct {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package gitlab
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
|
@ -50,12 +51,16 @@ func (c *gitlabClient) FetchUser(uid int) (*User, error) {
|
|||
}
|
||||
|
||||
func (c *gitlabClient) FetchCurrentUser() (*User, error) {
|
||||
gitlabUser, _, err := c.client.Users.CurrentUser()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch current user: %v", err)
|
||||
if c.IncludeCurrentUser {
|
||||
gitlabUser, _, err := c.client.Users.CurrentUser()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch current user: %v", err)
|
||||
}
|
||||
user := NewUserFromGitlabUser(gitlabUser)
|
||||
return &user, nil
|
||||
}
|
||||
user := NewUserFromGitlabUser(gitlabUser)
|
||||
return &user, nil
|
||||
// no current user to fetch, return nil
|
||||
return nil, errors.New("current user fetch is disabled")
|
||||
}
|
||||
|
||||
func (c *gitlabClient) FetchUserContent(user *User) (*UserContent, error) {
|
||||
|
|
3
main.go
3
main.go
|
@ -99,7 +99,8 @@ func makeGitlabConfig(config *Config) (*gitlab.GitlabClientParam, error) {
|
|||
}
|
||||
|
||||
return &gitlab.GitlabClientParam{
|
||||
PullMethod: config.Git.PullMethod,
|
||||
PullMethod: config.Git.PullMethod,
|
||||
IncludeCurrentUser: config.Gitlab.IncludeCurrentUser && config.Gitlab.Token != "",
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue