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 (
|
2024-01-16 16:15:52 +00:00
|
|
|
"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"
|
2024-01-16 16:15:52 +00:00
|
|
|
"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
|
|
|
|
2024-01-16 16:15:52 +00:00
|
|
|
type Remotes []remote.Remote
|
2023-12-29 20:02:17 +00:00
|
|
|
|
2024-01-16 16:15:52 +00:00
|
|
|
func (r *Remotes) AddRemote(remote remote.Remote) {
|
|
|
|
*r = append(*r, remote)
|
2023-12-07 17:08:56 +00:00
|
|
|
}
|
|
|
|
|
2024-01-16 16:24:06 +00:00
|
|
|
func (r *Remotes) GetRemoteByHost(host string) remote.Remote {
|
|
|
|
for _, remote := range *r {
|
|
|
|
if remote.GetInfo().Host == host {
|
|
|
|
return remote
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-16 16:15:52 +00:00
|
|
|
// 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),
|
2023-12-29 15:24:12 +00:00
|
|
|
}
|
2024-01-16 16:15:52 +00:00
|
|
|
go remoteInstance.StreamProjects(progressInfos[i], opts)
|
2023-12-29 15:24:12 +00:00
|
|
|
}
|
2024-01-16 16:15:52 +00:00
|
|
|
return progressInfos
|
|
|
|
}
|
2023-12-29 15:24:12 +00:00
|
|
|
|
2024-01-16 16:15:52 +00:00
|
|
|
func NewRemotes() *Remotes {
|
|
|
|
var remotes Remotes
|
|
|
|
remotes = make([]remote.Remote, 0)
|
|
|
|
return &remotes
|
2023-12-29 15:24:12 +00:00
|
|
|
}
|