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

55 lines
1.5 KiB
Go

package remotes
import (
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/load"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/projects"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
)
// Will determine number of total projects,
// then based on projectsPerPage (request) and
// projectsPerGoroutine, will spin off goroutines
// with offsets
const (
projectsPerPage = 20
projectsPerGoroutine = 200
)
type Remotes []remote.Remote
func (r *Remotes) AddRemote(remote remote.Remote) {
*r = append(*r, remote)
}
func (r *Remotes) GetRemoteByHost(host string) remote.Remote {
for _, remote := range *r {
if remote.GetInfo().Host == host {
return remote
}
}
return nil
}
// Launches project streamsers for all remotes in goroutines
// returns slice of load.ProgressInfo
func (r *Remotes) StreamRemotes(opts *remote.RemoteQueryOpts) []*load.ProgressInfo {
progressInfos := make([]*load.ProgressInfo, len(*r))
for i, remoteInstance := range *r {
progressInfos[i] = &load.ProgressInfo{
ProgressChan: make(chan load.Progress),
ProjectsChan: make(chan []*projects.Project),
ErrorChan: make(chan error),
DoneChan: make(chan interface{}),
NumProjects: remoteInstance.GetNumProjects(opts),
}
go remoteInstance.StreamProjects(progressInfos[i], opts)
}
return progressInfos
}
func NewRemotes() *Remotes {
var remotes Remotes
remotes = make([]remote.Remote, 0)
return &remotes
}