mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Bare `skillshare install` already restores everything .metadata.json records but the disk lacks, yet the dashboard could only re-clone missing tracked repos through a separate rehydrate path. Expose the CLI's install-from-config flow instead (GET /api/install/missing, POST /api/install/from-config) so both surfaces share one detection and one installer, and drop the old missingTrackedRepos plumbing from update responses. The install summary now counts tracked repos and their skills apart from standalone skills, since "Installed 1 skill" hid a whole repo. New tracked repos are named `_<owner>-<repo>` so two `skills` repos no longer collide; existing installs keep their names. `check` passes the stale status through so the dashboard can offer to prune skills deleted upstream.
101 lines
3.1 KiB
Go
101 lines
3.1 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"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"`
|
|
}
|
|
|
|
// planSkillCheck plans the update check of every installed skill outside a
|
|
// followed checkout. It takes s.mu.RLock, so the caller must not hold s.mu.
|
|
func (s *Server) planSkillCheck(sourceDir, projectRoot string, walk sourcewalk.Options) *check.Resolution {
|
|
names, _ := install.GetUpdatableSkills(sourceDir)
|
|
var skills []check.Skill
|
|
for _, name := range names {
|
|
if followedCheckout(filepath.Join(sourceDir, name), walk.Follow) != "" {
|
|
continue
|
|
}
|
|
skills = append(skills, check.Skill{Name: name, Entry: s.skillEntry(name)})
|
|
}
|
|
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,
|
|
})
|
|
}
|
|
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) repoCheckResult {
|
|
out := check.ParallelCheckRepos([]check.RepoCheckInput{{Name: name, RepoPath: repoPath}}, 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()
|
|
s.mu.RUnlock()
|
|
|
|
repos, linked := dashboardRepos(sourceDir, walk)
|
|
plan := s.planSkillCheck(sourceDir, projectRoot, walk)
|
|
|
|
var repoResults []repoCheckResult
|
|
for _, repo := range repos {
|
|
repoResults = append(repoResults, checkTrackedRepo(repo, filepath.Join(sourceDir, repo)))
|
|
}
|
|
|
|
// Without a context the check runs to completion, so the error is always nil.
|
|
resolved, _ := plan.Run(context.Background(), check.Options{})
|
|
skillResults := dashboardSkillResults(resolved)
|
|
|
|
if repoResults == nil {
|
|
repoResults = []repoCheckResult{}
|
|
}
|
|
writeJSON(w, map[string]any{
|
|
"tracked_repos": repoResults,
|
|
"linked_repos": linked,
|
|
"skills": skillResults,
|
|
})
|
|
}
|