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

45 lines
866 B
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/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) GetInfo() *info.RemoteInfo {
2024-01-16 18:23:38 +00:00
return r.info
}
func (r *GiteaRemote) GetType() string {
2024-01-17 21:56:41 +00:00
return r.info.Type.String()
}
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,
2024-01-17 21:56:41 +00:00
gitea.SetContext(remoteInfo.Context()),
2024-01-16 19:26:56 +00:00
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
}