Add GitHub support
This commit is contained in:
62
internal/remotes/github/github_stream.go
Normal file
62
internal/remotes/github/github_stream.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package githubremote
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/google/go-github/v58/github"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/load"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
|
||||
)
|
||||
|
||||
const githubReposPerPage = 20
|
||||
|
||||
func (r *GithubRemote) StreamProjects(pi *load.ProgressInfo, opts *remote.RemoteQueryOpts) {
|
||||
defer close(pi.ProgressChan)
|
||||
defer close(pi.ProjectsChan)
|
||||
|
||||
// Get projects. TODO support concurrency
|
||||
githubListOpts := github.ListOptions{
|
||||
Page: 1,
|
||||
PerPage: githubReposPerPage,
|
||||
}
|
||||
var githubRepoType string
|
||||
if opts.OwnerOnly {
|
||||
githubRepoType = "owner"
|
||||
} else {
|
||||
githubRepoType = "all"
|
||||
}
|
||||
for {
|
||||
repos, resp, err := r.api.Repositories.ListByAuthenticatedUser(
|
||||
r.info.Context(),
|
||||
&github.RepositoryListByAuthenticatedUserOptions{
|
||||
Type: githubRepoType,
|
||||
ListOptions: githubListOpts,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
pi.ErrorChan <- err
|
||||
break
|
||||
} else if len(repos) < 1 {
|
||||
pi.ErrorChan <- errors.New("No github repos found")
|
||||
break
|
||||
}
|
||||
|
||||
// Write updates to channels
|
||||
pi.ProjectsChan <- r.ReposToProjects(repos)
|
||||
pi.ProgressChan <- load.Progress{
|
||||
Page: githubListOpts.Page,
|
||||
Pages: resp.LastPage,
|
||||
Projects: len(repos),
|
||||
TotalProjects: pi.NumProjects,
|
||||
}
|
||||
|
||||
if resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
githubListOpts.Page = resp.NextPage
|
||||
}
|
||||
|
||||
pi.DoneChan <- nil
|
||||
}
|
||||
Reference in New Issue
Block a user