git-project-manager/internal/remotes/gitea/gitea.go

70 lines
1.4 KiB
Go
Raw Normal View History

2024-01-16 18:23:38 +00:00
package gitearemote
import (
2024-01-16 19:26:56 +00:00
"fmt"
2024-01-16 18:23:38 +00:00
"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"
2024-01-16 18:23:38 +00:00
)
type GiteaRemote struct {
info *info.RemoteInfo
2024-01-16 18:23:38 +00:00
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 {
2024-01-16 18:23:38 +00:00
return r.info
}
func (r *GiteaRemote) GetType() string {
return r.info.Type
}
2024-01-16 19:26:56 +00:00
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) {
2024-01-16 19:26:56 +00:00
client, err := gitea.NewClient(remoteInfo.Host,
gitea.SetContext(remoteInfo.Ctx),
gitea.SetToken(remoteInfo.Token),
)
2024-01-16 18:23:38 +00:00
if err != nil {
return nil, err
}
giteaRemote := &GiteaRemote{
info: remoteInfo,
api: client,
}
return giteaRemote, nil
}