fix deprecated github base url compatibility

This commit is contained in:
lxowalle 2026-04-10 10:50:50 +08:00
parent 1885ac7eca
commit 91d445987a
2 changed files with 37 additions and 1 deletions

View file

@ -2,6 +2,8 @@ package skills
import "github.com/sipeed/picoclaw/pkg/config" import "github.com/sipeed/picoclaw/pkg/config"
const defaultGitHubRegistryBaseURL = "https://github.com"
func effectiveRegistryConfigsFromToolsConfig(cfg config.SkillsToolsConfig) []config.SkillRegistryConfig { func effectiveRegistryConfigsFromToolsConfig(cfg config.SkillsToolsConfig) []config.SkillRegistryConfig {
effective := make([]config.SkillRegistryConfig, 0, len(cfg.Registries)+1) effective := make([]config.SkillRegistryConfig, 0, len(cfg.Registries)+1)
seen := map[string]struct{}{} seen := map[string]struct{}{}
@ -44,7 +46,10 @@ func applyLegacyGithubRegistryCompatibility(
if registryCfg.Param == nil { if registryCfg.Param == nil {
registryCfg.Param = map[string]any{} registryCfg.Param = map[string]any{}
} }
if registryCfg.BaseURL == "" { if registryCfg.BaseURL == "" ||
(registryCfg.BaseURL == defaultGitHubRegistryBaseURL &&
cfg.Github.BaseURL != "" &&
cfg.Github.BaseURL != defaultGitHubRegistryBaseURL) {
registryCfg.BaseURL = cfg.Github.BaseURL registryCfg.BaseURL = cfg.Github.BaseURL
} }
if registryCfg.AuthToken.String() == "" { if registryCfg.AuthToken.String() == "" {

View file

@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/sipeed/picoclaw/pkg/config"
"github.com/sipeed/picoclaw/pkg/utils" "github.com/sipeed/picoclaw/pkg/utils"
) )
@ -207,3 +208,33 @@ func TestIsSafeSlug(t *testing.T) {
assert.Error(t, utils.ValidateSkillIdentifier("path/traversal")) assert.Error(t, utils.ValidateSkillIdentifier("path/traversal"))
assert.Error(t, utils.ValidateSkillIdentifier("path\\traversal")) assert.Error(t, utils.ValidateSkillIdentifier("path\\traversal"))
} }
func TestLegacyGithubBaseURLOverridesDefaultRegistryBaseURL(t *testing.T) {
cfg := config.DefaultConfig().Tools.Skills
cfg.Github.BaseURL = "https://ghe.example.com/git"
registry := LookupRegistryFromToolsConfig(cfg, "github")
assert.NotNil(t, registry)
ghRegistry, ok := registry.(*GitHubRegistry)
assert.True(t, ok)
assert.Equal(t, "https://ghe.example.com/git", ghRegistry.webBase)
}
func TestExplicitGithubRegistryBaseURLBeatsLegacyCompat(t *testing.T) {
cfg := config.DefaultConfig().Tools.Skills
cfg.Github.BaseURL = "https://ghe-legacy.example.com/git"
cfg.Registries.Set("github", config.SkillRegistryConfig{
Name: "github",
Enabled: true,
BaseURL: "https://ghe-explicit.example.com/scm",
Param: map[string]any{},
})
registry := LookupRegistryFromToolsConfig(cfg, "github")
assert.NotNil(t, registry)
ghRegistry, ok := registry.(*GitHubRegistry)
assert.True(t, ok)
assert.Equal(t, "https://ghe-explicit.example.com/scm", ghRegistry.webBase)
}