mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
After a full check, a skill whose remote did not answer shows "Check failed". The only ways to look at it again were to check everything once more, which with many skills takes a while and re-runs the ones that already answered, or to update it without knowing whether an update exists (#963). Ticking rows on the Skills Updates tab now offers "Check N selected". It checks those tracked repos and skills only, and every other row keeps the result it had. GET /api/check/stream takes the names to limit the check to, as GET /api/update/stream already does. The action is not offered for agents: the dashboard check does not cover them, so it would report each one as failed. Closes #963 Release-As: 0.30.13
124 lines
3.9 KiB
Go
124 lines
3.9 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"skillshare/internal/check"
|
|
"skillshare/internal/install"
|
|
"skillshare/internal/sourcewalk"
|
|
)
|
|
|
|
type repoCheckResult struct {
|
|
Name string `json:"name"`
|
|
Status string `json:"status"`
|
|
Behind int `json:"behind"`
|
|
Message string `json:"message,omitempty"`
|
|
}
|
|
|
|
type skillCheckResult struct {
|
|
Name string `json:"name"`
|
|
Source string `json:"source"`
|
|
Version string `json:"version"`
|
|
Status string `json:"status"`
|
|
InstalledAt string `json:"installed_at,omitempty"`
|
|
Kind string `json:"kind,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
}
|
|
|
|
// checkNames reads the names query param (comma-separated): the tracked repos
|
|
// and skills a check is limited to. Without it, nil: everything is checked.
|
|
func checkNames(r *http.Request) map[string]bool {
|
|
param := r.URL.Query().Get("names")
|
|
if param == "" {
|
|
return nil
|
|
}
|
|
only := map[string]bool{}
|
|
for name := range strings.SplitSeq(param, ",") {
|
|
if name = strings.TrimSpace(name); name != "" {
|
|
only[name] = true
|
|
}
|
|
}
|
|
return only
|
|
}
|
|
|
|
// planSkillCheck plans the update check of every installed skill outside a
|
|
// followed checkout, or of those in only when it is not nil. It takes
|
|
// s.mu.RLock, so the caller must not hold s.mu.
|
|
func (s *Server) planSkillCheck(sourceDir, projectRoot string, walk sourcewalk.Options, only map[string]bool) *check.Resolution {
|
|
names, _ := install.GetUpdatableSkills(sourceDir)
|
|
var skills []check.Skill
|
|
for _, name := range names {
|
|
if only != nil && !only[name] {
|
|
continue
|
|
}
|
|
if followedCheckout(filepath.Join(sourceDir, name), walk.Follow) != "" {
|
|
continue
|
|
}
|
|
skills = append(skills, check.Skill{Name: name, Entry: s.skillEntry(name), Dir: filepath.Join(sourceDir, name), Follow: walk.Follow})
|
|
}
|
|
return check.Plan(skills, projectRoot)
|
|
}
|
|
|
|
// dashboardSkillResults converts resolved statuses to the dashboard payload,
|
|
// which is narrower than the CLI's: a skill without a remote carries only its
|
|
// name, status and message.
|
|
func dashboardSkillResults(results []check.SkillResult) []skillCheckResult {
|
|
out := make([]skillCheckResult, 0, len(results))
|
|
for _, r := range results {
|
|
if r.Local {
|
|
out = append(out, skillCheckResult{Name: r.Name, Status: r.Status, Message: r.Message})
|
|
continue
|
|
}
|
|
out = append(out, skillCheckResult{
|
|
Name: r.Name,
|
|
Source: r.Source,
|
|
Version: r.Version,
|
|
Status: r.Status,
|
|
InstalledAt: r.InstalledAt,
|
|
Message: r.Message,
|
|
})
|
|
}
|
|
return out
|
|
}
|
|
|
|
// checkTrackedRepo checks one tracked repo with the same logic as the CLI:
|
|
// auth-aware fetch and a reported dirty-check error.
|
|
func checkTrackedRepo(name, repoPath string, parseOpts install.ParseOptions) repoCheckResult {
|
|
out := check.ParallelCheckRepos([]check.RepoCheckInput{{Name: name, RepoPath: repoPath, ParseOptions: parseOpts}}, nil)[0]
|
|
return repoCheckResult{Name: out.Name, Status: out.Status, Behind: out.Behind, Message: out.Message}
|
|
}
|
|
|
|
func (s *Server) handleCheck(w http.ResponseWriter, r *http.Request) {
|
|
// Snapshot config under RLock, then release before I/O.
|
|
s.mu.RLock()
|
|
sourceDir := s.skillsSource()
|
|
projectRoot := s.projectRoot
|
|
walk := s.skillsWalk()
|
|
parseOpts := s.parseOpts()
|
|
s.mu.RUnlock()
|
|
|
|
repos, linked := dashboardRepos(sourceDir, walk)
|
|
plan := s.planSkillCheck(sourceDir, projectRoot, walk, nil)
|
|
|
|
var repoResults []repoCheckResult
|
|
for _, repo := range repos {
|
|
repoResults = append(repoResults, checkTrackedRepo(repo, filepath.Join(sourceDir, repo), parseOpts))
|
|
}
|
|
|
|
// Without a context the check runs to completion, so the error is always nil.
|
|
resolved, _ := plan.Run(context.Background(), check.Options{ParseOptions: parseOpts})
|
|
skillResults := dashboardSkillResults(resolved)
|
|
|
|
if repoResults == nil {
|
|
repoResults = []repoCheckResult{}
|
|
}
|
|
writeJSON(w, map[string]any{
|
|
"tracked_repos": repoResults,
|
|
"linked_repos": linked,
|
|
"skills": skillResults,
|
|
})
|
|
}
|