mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
Bind provider credentials to canonical or explicitly configured HTTPS origins and preserve that policy across remote consumers. Reject cross-site credentialed reads, linked fallback directories, and discovered-agent writes outside the source; audit staged content before rooted atomic publication. Add boundary regressions, private Git update coverage, stable cross-platform fixtures, and aligned documentation. Verified the integrated main baseline with all executed CI checks passing.
142 lines
3.0 KiB
Go
142 lines
3.0 KiB
Go
package check
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"skillshare/internal/git"
|
|
"skillshare/internal/install"
|
|
)
|
|
|
|
const maxWorkers = 8
|
|
|
|
// RepoCheckInput describes a tracked repo to check.
|
|
type RepoCheckInput struct {
|
|
Name string
|
|
RepoPath string
|
|
ParseOptions install.ParseOptions
|
|
}
|
|
|
|
// RepoCheckOutput holds the result of checking a single repo.
|
|
type RepoCheckOutput struct {
|
|
Name string
|
|
Status string // "up_to_date", "behind", "dirty", "error"
|
|
Behind int
|
|
Branch string
|
|
Message string
|
|
}
|
|
|
|
// URLCheckInput describes a remote URL to probe.
|
|
type URLCheckInput struct {
|
|
RepoURL string
|
|
Branch string
|
|
ParseOptions install.ParseOptions
|
|
}
|
|
|
|
// URLCheckOutput holds the result of probing a remote URL.
|
|
type URLCheckOutput struct {
|
|
RepoURL string
|
|
RemoteHash string
|
|
Branch string
|
|
Err error
|
|
}
|
|
|
|
// ParallelCheckRepos checks multiple repos concurrently using a bounded
|
|
// semaphore of maxWorkers goroutines. onDone (if non-nil) is called after
|
|
// each repo finishes, useful for progress updates.
|
|
func ParallelCheckRepos(repos []RepoCheckInput, onDone func()) []RepoCheckOutput {
|
|
outputs := make([]RepoCheckOutput, len(repos))
|
|
if len(repos) == 0 {
|
|
return outputs
|
|
}
|
|
|
|
sem := make(chan struct{}, maxWorkers)
|
|
var wg sync.WaitGroup
|
|
|
|
for i, repo := range repos {
|
|
wg.Add(1)
|
|
sem <- struct{}{}
|
|
go func(idx int, r RepoCheckInput) {
|
|
defer wg.Done()
|
|
defer func() { <-sem }()
|
|
|
|
outputs[idx] = checkOneRepo(r)
|
|
if onDone != nil {
|
|
onDone()
|
|
}
|
|
}(i, repo)
|
|
}
|
|
wg.Wait()
|
|
|
|
return outputs
|
|
}
|
|
|
|
func checkOneRepo(r RepoCheckInput) RepoCheckOutput {
|
|
out := RepoCheckOutput{Name: r.Name}
|
|
if branch, err := git.GetCurrentBranch(r.RepoPath); err == nil {
|
|
out.Branch = branch
|
|
}
|
|
|
|
isDirty, err := git.IsDirty(r.RepoPath)
|
|
if err != nil {
|
|
out.Status = "error"
|
|
out.Message = err.Error()
|
|
return out
|
|
}
|
|
if isDirty {
|
|
out.Status = "dirty"
|
|
out.Message = "has uncommitted changes"
|
|
return out
|
|
}
|
|
|
|
behind, err := git.GetBehindCountWithAuth(r.RepoPath, r.ParseOptions)
|
|
if err != nil {
|
|
out.Status = "error"
|
|
out.Message = err.Error()
|
|
return out
|
|
}
|
|
|
|
if behind == 0 {
|
|
out.Status = "up_to_date"
|
|
} else {
|
|
out.Status = "behind"
|
|
out.Behind = behind
|
|
}
|
|
return out
|
|
}
|
|
|
|
// ParallelCheckURLs checks unique repo URLs concurrently with bounded workers.
|
|
// onDone is called after each URL completes (may be nil).
|
|
// Returns []URLCheckOutput aligned by index with the input slice.
|
|
func ParallelCheckURLs(urls []URLCheckInput, onDone func()) []URLCheckOutput {
|
|
outputs := make([]URLCheckOutput, len(urls))
|
|
if len(urls) == 0 {
|
|
return outputs
|
|
}
|
|
|
|
sem := make(chan struct{}, maxWorkers)
|
|
var wg sync.WaitGroup
|
|
|
|
for i, u := range urls {
|
|
wg.Add(1)
|
|
sem <- struct{}{}
|
|
go func(idx int, input URLCheckInput) {
|
|
defer wg.Done()
|
|
defer func() { <-sem }()
|
|
|
|
hash, err := (GitRemote{ParseOptions: input.ParseOptions}).Hash(input.RepoURL, input.Branch)
|
|
outputs[idx] = URLCheckOutput{
|
|
RepoURL: input.RepoURL,
|
|
RemoteHash: hash,
|
|
Branch: input.Branch,
|
|
Err: err,
|
|
}
|
|
if onDone != nil {
|
|
onDone()
|
|
}
|
|
}(i, u)
|
|
}
|
|
wg.Wait()
|
|
|
|
return outputs
|
|
}
|