mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
Backend for Filter Studio feature: - ClassifySkillForTarget() in internal/sync/classify.go — determines skill sync status per target (synced/excluded/not_included/ skill_target_mismatch) with reason strings - firstMatchingPattern() helper in filter.go for exclude reason reporting - GET /api/sync-matrix — returns full skill×target classification matrix - POST /api/sync-matrix/preview — what-if preview with draft patterns - 8 classify unit tests + 7 handler tests (empty, filters, query param, preview, invalid pattern, missing target)
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package sync
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"skillshare/internal/config"
|
|
)
|
|
|
|
// ClassifySkillForTarget determines whether a skill should sync to a target,
|
|
// returning a status string and an optional reason.
|
|
//
|
|
// Statuses:
|
|
// - "synced": skill will be synced to this target
|
|
// - "excluded": skill matched an exclude pattern (reason = the pattern)
|
|
// - "not_included": include patterns exist but skill matched none
|
|
// - "skill_target_mismatch": SKILL.md targets field excludes this target (reason = declared targets)
|
|
func ClassifySkillForTarget(flatName string, skillTargets []string, targetName string, include, exclude []string) (status, reason string) {
|
|
// 1. Check SKILL.md targets field first
|
|
if skillTargets != nil {
|
|
matched := false
|
|
for _, t := range skillTargets {
|
|
if config.MatchesTargetName(t, targetName) {
|
|
matched = true
|
|
break
|
|
}
|
|
}
|
|
if !matched {
|
|
return "skill_target_mismatch", strings.Join(skillTargets, ", ")
|
|
}
|
|
}
|
|
|
|
// Normalize patterns (trim whitespace, validate syntax) — same path as shouldSyncFlatName
|
|
incNorm, excNorm, _ := normalizedFilterPatterns(include, exclude)
|
|
|
|
// 2. Check include first (matches shouldSyncFlatName precedence)
|
|
if len(incNorm) > 0 && !matchesAnyPattern(flatName, incNorm) {
|
|
return "not_included", ""
|
|
}
|
|
|
|
// 3. Check exclude
|
|
if pattern, matched := firstMatchingPattern(flatName, excNorm); matched {
|
|
return "excluded", pattern
|
|
}
|
|
|
|
return "synced", ""
|
|
}
|