46 lines
944 B
Go
46 lines
944 B
Go
package githubremote
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/google/go-github/v58/github"
|
|
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/info"
|
|
)
|
|
|
|
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
|
|
}
|