Add GitHub support
This commit is contained in:
45
internal/remotes/github/github.go
Normal file
45
internal/remotes/github/github.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user