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