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 19:26:56 +00:00
|
|
|
"errors"
|
|
|
|
|
2024-12-19 19:55:49 +00:00
|
|
|
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/load"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/projects"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/git-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 17:48:42 +00:00
|
|
|
func (r *Remotes) AddRemotes(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
|
2024-01-16 17:48:42 +00:00
|
|
|
// returns slice of load.ProgressInfo, does not block, streamer is
|
|
|
|
// launched in goroutine
|
2024-01-16 19:26:56 +00:00
|
|
|
func StreamRemote(r remote.Remote, opts *remote.RemoteQueryOpts) (*load.ProgressInfo, error) {
|
2024-01-16 17:48:42 +00:00
|
|
|
progressInfo := &load.ProgressInfo{
|
|
|
|
ProgressChan: make(chan load.Progress),
|
|
|
|
ProjectsChan: make(chan []*projects.Project),
|
|
|
|
ErrorChan: make(chan error),
|
|
|
|
DoneChan: make(chan interface{}),
|
|
|
|
NumProjects: r.GetNumProjects(opts),
|
2023-12-29 15:24:12 +00:00
|
|
|
}
|
2024-01-16 19:26:56 +00:00
|
|
|
if progressInfo.NumProjects < 1 {
|
|
|
|
return nil, errors.New("Failed to fetch project count from remote, won't load")
|
|
|
|
}
|
2024-01-16 17:48:42 +00:00
|
|
|
go r.StreamProjects(progressInfo, opts)
|
2024-01-16 19:26:56 +00:00
|
|
|
return progressInfo, nil
|
2024-01-16 16:15:52 +00:00
|
|
|
}
|
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
|
|
|
}
|