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

46 lines
944 B
Go
Raw Normal View History

2024-01-18 16:09:54 +00:00
package githubremote
import (
"fmt"
"github.com/google/go-github/v58/github"
2024-12-19 19:55:49 +00:00
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/info"
2024-01-18 16:09:54 +00:00
)
type GithubRemote struct {
user *github.User
info *info.RemoteInfo
api *github.Client
}
func (r *GithubRemote) GetInfo() *info.RemoteInfo {
return r.info
}
func (r *GithubRemote) GetType() string {
return r.info.Type.String()
}
func (r *GithubRemote) String() string {
return fmt.Sprintf("Github %s (%s), clone proto %s",
r.GetInfo().Name, r.GetInfo().Host, r.GetInfo().CloneProto)
}
func NewGithubRemote(remoteInfo *info.RemoteInfo) (*GithubRemote, error) {
client := github.NewClient(nil).
WithAuthToken(remoteInfo.Token)
githubRemote := &GithubRemote{
info: remoteInfo,
api: client,
}
user, _, err := githubRemote.api.Users.Get(remoteInfo.Context(), "")
if err != nil {
return nil, err
}
githubRemote.user = user
return githubRemote, nil
}