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

41 lines
795 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/remote"
)
type GiteaRemote struct {
info *remote.RemoteInfo
api *gitea.Client
}
func (r *GiteaRemote) GetInfo() *remote.RemoteInfo {
return r.info
}
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)
}
2024-01-16 18:23:38 +00:00
func NewGiteaRemote(remoteInfo *remote.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
}