package gitearemote 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" ) type GiteaRemote struct { info *info.RemoteInfo 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 } func (r *GiteaRemote) GetType() string { return r.info.Type } func (r *GiteaRemote) String() string { return fmt.Sprintf("Gitea %s (%s), clone proto %s", r.GetInfo().Name, r.GetInfo().Host, r.GetInfo().CloneProto) } func NewGiteaRemote(remoteInfo *info.RemoteInfo) (*GiteaRemote, error) { client, err := gitea.NewClient(remoteInfo.Host, gitea.SetContext(remoteInfo.Ctx), gitea.SetToken(remoteInfo.Token), ) if err != nil { return nil, err } giteaRemote := &GiteaRemote{ info: remoteInfo, api: client, } return giteaRemote, nil }