Files
skillshare/internal/install/context.go
T
Willie e3af6274fc feat(install): install config entries from the dashboard and name repos by owner
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.
2026-10-08 12:01:42 +08:00

85 lines
2.6 KiB
Go

package install
import "strings"
// SkillEntryDTO is a dependency-free copy of config.SkillEntry, used to avoid
// a circular import between install and config. The cmd layer converts
// config.SkillEntry → SkillEntryDTO before passing data through InstallContext.
type SkillEntryDTO struct {
Name string
Source string
Tracked bool
Group string
Branch string
}
// FullName returns the full relative path for the skill entry.
// If Group is set, returns "group/name"; otherwise returns Name.
func (s SkillEntryDTO) FullName() string {
if s.Group != "" {
return s.Group + "/" + s.Name
}
return s.Name
}
// EffectiveParts returns the effective (group, bareName) for this entry.
// If Group is set, returns (Group, Name).
// For backward compat, if Name contains "/" and Group is empty,
// splits at the last "/" to derive group and bare name.
func (s SkillEntryDTO) EffectiveParts() (group, name string) {
if s.Group != "" {
return s.Group, s.Name
}
if idx := strings.LastIndex(s.Name, "/"); idx >= 0 {
return s.Name[:idx], s.Name[idx+1:]
}
return "", s.Name
}
// InstallContext abstracts the behavioral differences between global and
// project install modes so that InstallFromConfig can be written once.
type InstallContext interface {
// SourcePath returns the skills directory
// (e.g. ~/.config/skillshare/skills or .skillshare/skills).
SourcePath() string
// ConfigSkills returns the remote skill entries from the config file.
ConfigSkills() []SkillEntryDTO
// Reconcile performs post-install config reconciliation
// (e.g. ReconcileGlobalSkills or ReconcileProjectSkills).
Reconcile() error
// PostInstallSkill is a per-skill hook called after a successful install.
// For example, project mode uses this to update .skillshare/.gitignore.
PostInstallSkill(displayName string) error
// Mode returns "global" or "project".
Mode() string
// GitLabHosts returns extra hostnames to treat as GitLab instances.
GitLabHosts() []string
// AzureHosts returns extra hostnames to treat as Azure DevOps on-premises instances.
AzureHosts() []string
// CNBHosts returns extra hostnames to treat as CNB instances.
CNBHosts() []string
// GiteaHosts returns extra hostnames to treat as Gitea instances.
GiteaHosts() []string
}
// ConfigInstallResult summarises the outcome of InstallFromConfig.
type ConfigInstallResult struct {
Installed int
Skipped int
// Tracked repos counted within Installed/Skipped, so the summary can tell
// a whole repo apart from a single skill.
InstalledRepos int
InstalledRepoSkills int // skills inside InstalledRepos
SkippedRepos int
InstalledSkills []string
FailedSkills []string
}