Add GitHub support

This commit is contained in:
2024-01-18 11:09:54 -05:00
parent 4b2b251136
commit 9f66001a66
7 changed files with 189 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
package githubremote
import (
"fmt"
"github.com/google/go-github/v58/github"
"gitlab.sweetwater.com/it/devops/tools/gitlab-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
}