gitforgefs/gitlab/client.go

47 lines
751 B
Go
Raw Permalink Normal View History

2020-12-27 03:30:19 +00:00
package gitlab
import (
"fmt"
"github.com/xanzy/go-gitlab"
)
2020-12-30 23:00:37 +00:00
const (
PullMethodHTTP = "http"
PullMethodSSH = "ssh"
)
2020-12-30 00:49:11 +00:00
type GitlabFetcher interface {
GroupFetcher
UserFetcher
2020-12-27 03:30:19 +00:00
}
2020-12-31 20:00:10 +00:00
type Refresher interface {
InvalidateCache()
}
2020-12-29 02:37:18 +00:00
type GitlabClientParam struct {
2020-12-30 23:00:37 +00:00
PullMethod string
2020-12-27 03:30:19 +00:00
}
2020-12-29 02:37:18 +00:00
type gitlabClient struct {
GitlabClientParam
client *gitlab.Client
}
func NewClient(gitlabUrl string, gitlabToken string, p GitlabClientParam) (*gitlabClient, error) {
2020-12-27 03:30:19 +00:00
client, err := gitlab.NewClient(
gitlabToken,
gitlab.WithBaseURL(gitlabUrl),
)
if err != nil {
2020-12-29 02:37:18 +00:00
return nil, fmt.Errorf("failed to create gitlab client: %v", err)
2020-12-27 03:30:19 +00:00
}
2020-12-29 02:37:18 +00:00
gitlabClient := &gitlabClient{
2020-12-30 23:00:37 +00:00
GitlabClientParam: p,
client: client,
2020-12-27 03:30:19 +00:00
}
return gitlabClient, nil
}