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

41 lines
795 B
Go

package gitearemote
import (
"fmt"
"code.gitea.io/sdk/gitea"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
)
type GiteaRemote struct {
info *remote.RemoteInfo
api *gitea.Client
}
func (r *GiteaRemote) GetInfo() *remote.RemoteInfo {
return r.info
}
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 *remote.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
}