74 lines
1.6 KiB
Go
74 lines
1.6 KiB
Go
package gitlabremote
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/xanzy/go-gitlab"
|
|
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
|
|
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/info"
|
|
)
|
|
|
|
type GitlabRemote struct {
|
|
info *info.RemoteInfo
|
|
api *gitlab.Client
|
|
}
|
|
|
|
func (r *GitlabRemote) GetInfos(conf config.Config) []info.RemoteInfo {
|
|
// Support legacy fields
|
|
if conf.GitlabHost != "" && conf.GitlabToken != "" {
|
|
conf.Gitlabs = append(conf.Gitlabs, config.GitlabConfig{
|
|
Host: conf.GitlabHost,
|
|
Name: conf.GitlabHost,
|
|
Token: conf.GitlabToken,
|
|
CloneProto: info.CloneProtoSSH,
|
|
})
|
|
}
|
|
|
|
// Prepare infos
|
|
infos := make([]info.RemoteInfo, len(conf.Gitlabs))
|
|
for i, g := range conf.Gitlabs {
|
|
// Set Defaults
|
|
proto := info.CloneProtoSSH
|
|
if g.CloneProto == info.CloneProtoHTTP {
|
|
proto = info.CloneProtoHTTP
|
|
}
|
|
if g.Name == "" {
|
|
g.Name = g.Host
|
|
}
|
|
|
|
infos[i] = info.RemoteInfo{
|
|
Host: g.Host,
|
|
Name: g.Name,
|
|
Type: "gitlab",
|
|
Token: g.Token,
|
|
CloneProto: proto,
|
|
}
|
|
}
|
|
return infos
|
|
}
|
|
|
|
func (r *GitlabRemote) GetInfo() *info.RemoteInfo {
|
|
return r.info
|
|
}
|
|
|
|
func (r *GitlabRemote) GetType() string {
|
|
return r.info.Type
|
|
}
|
|
|
|
func (r *GitlabRemote) String() string {
|
|
return fmt.Sprintf("GitLab %s (%s), clone proto %s",
|
|
r.GetInfo().Name, r.GetInfo().Host, r.GetInfo().CloneProto)
|
|
}
|
|
|
|
func NewGitlabRemote(remoteInfo *info.RemoteInfo) (*GitlabRemote, error) {
|
|
api, err := NewGitlabApi(remoteInfo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
gl := &GitlabRemote{
|
|
info: remoteInfo,
|
|
api: api,
|
|
}
|
|
return gl, nil
|
|
}
|