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"
|
2024-01-17 13:13:58 +00:00
|
|
|
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/info"
|
2024-01-16 18:23:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type GiteaRemote struct {
|
2024-01-17 13:13:58 +00:00
|
|
|
info *info.RemoteInfo
|
2024-01-16 18:23:38 +00:00
|
|
|
api *gitea.Client
|
|
|
|
}
|
|
|
|
|
2024-01-17 13:13:58 +00:00
|
|
|
func (r *GiteaRemote) GetInfo() *info.RemoteInfo {
|
2024-01-16 18:23:38 +00:00
|
|
|
return r.info
|
|
|
|
}
|
|
|
|
|
2024-01-17 13:13:58 +00:00
|
|
|
func (r *GiteaRemote) GetType() string {
|
2024-01-17 21:56:41 +00:00
|
|
|
return r.info.Type.String()
|
2024-01-17 13:13:58 +00:00
|
|
|
}
|
|
|
|
|
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-17 13:13:58 +00:00
|
|
|
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
|
|
|
|
}
|