Move from --gitlab flags to global --remote flags
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/info"
|
||||
)
|
||||
|
||||
@ -12,6 +13,30 @@ type GiteaRemote struct {
|
||||
api *gitea.Client
|
||||
}
|
||||
|
||||
func (r *GiteaRemote) GetInfos(conf config.Config) []info.RemoteInfo {
|
||||
// Prepare infos
|
||||
infos := make([]info.RemoteInfo, len(conf.Giteas))
|
||||
for i, g := range conf.Giteas {
|
||||
// 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: "gitea",
|
||||
Token: g.Token,
|
||||
CloneProto: proto,
|
||||
}
|
||||
}
|
||||
return infos
|
||||
}
|
||||
|
||||
func (r *GiteaRemote) GetInfo() *info.RemoteInfo {
|
||||
return r.info
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ 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"
|
||||
)
|
||||
|
||||
@ -12,6 +13,40 @@ type GitlabRemote struct {
|
||||
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
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/info"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/load"
|
||||
)
|
||||
@ -17,6 +18,9 @@ const defNetDialTimeoutSecs = 3
|
||||
// stream all projects along with updates to channels
|
||||
// provided by *load.ProgressInfo
|
||||
type Remote interface {
|
||||
// Helper to process configs.
|
||||
// Realistically, conf.Gitlabs and conf.Giteas should be conf.Remotes
|
||||
GetInfos(config.Config) []info.RemoteInfo
|
||||
String() string // String info for remote
|
||||
GetInfo() *info.RemoteInfo // Returns basic RemoteInfo struct
|
||||
GetType() string // Returns the remote type (e.g. GitLab, Gitea)
|
||||
|
Reference in New Issue
Block a user