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

55 lines
1.5 KiB
Go
Raw Normal View History

2024-01-15 19:57:15 +00:00
package remotes
2023-12-05 21:56:47 +00:00
2023-12-07 17:08:56 +00:00
import (
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/load"
2024-01-15 20:39:35 +00:00
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/projects"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
2023-12-07 17:08:56 +00:00
)
2023-12-29 20:02:17 +00:00
// Will determine number of total projects,
// then based on projectsPerPage (request) and
// projectsPerGoroutine, will spin off goroutines
// with offsets
const (
projectsPerPage = 20
projectsPerGoroutine = 200
)
2023-12-05 21:56:47 +00:00
type Remotes []remote.Remote
2023-12-29 20:02:17 +00:00
func (r *Remotes) AddRemote(remote remote.Remote) {
*r = append(*r, remote)
2023-12-07 17:08:56 +00:00
}
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
}