fix github blob skill install directory resolution
This commit is contained in:
parent
4dae95d870
commit
087e4f9e7e
3 changed files with 41 additions and 0 deletions
|
|
@ -197,4 +197,16 @@ func TestGitHubRegistryResolveInstallDirNameSupportsFullURLs(t *testing.T) {
|
||||||
dirName, err = registry.ResolveInstallDirName("https://github.com/org/repo/tree/main/skills/release-checklist")
|
dirName, err = registry.ResolveInstallDirName("https://github.com/org/repo/tree/main/skills/release-checklist")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "release-checklist", dirName)
|
assert.Equal(t, "release-checklist", dirName)
|
||||||
|
|
||||||
|
dirName, err = registry.ResolveInstallDirName(
|
||||||
|
"https://ghe.example.com/git/org/repo/blob/dev/skills/pr-review/SKILL.md",
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "pr-review", dirName)
|
||||||
|
|
||||||
|
dirName, err = registry.ResolveInstallDirName(
|
||||||
|
"https://ghe.example.com/git/org/repo/blob/dev/SKILL.md",
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "repo", dirName)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -363,6 +363,13 @@ func githubInstallDirNameWithBaseURL(repo, githubBaseURL string) (string, error)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if ref.SubPath != "" {
|
if ref.SubPath != "" {
|
||||||
|
if isSkillMarkdownPath(ref.SubPath) {
|
||||||
|
skillDir := path.Dir(strings.Trim(ref.SubPath, "/"))
|
||||||
|
if skillDir == "." || skillDir == "" {
|
||||||
|
return ref.RepoName, nil
|
||||||
|
}
|
||||||
|
return path.Base(skillDir), nil
|
||||||
|
}
|
||||||
return filepath.Base(ref.SubPath), nil
|
return filepath.Base(ref.SubPath), nil
|
||||||
}
|
}
|
||||||
return ref.RepoName, nil
|
return ref.RepoName, nil
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,28 @@ func TestParseGitHubRefWithBaseURL(t *testing.T) {
|
||||||
t.Fatalf("dirName = %q, want test", dirName)
|
t.Fatalf("dirName = %q, want test", dirName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dirName, err = githubInstallDirNameWithBaseURL(
|
||||||
|
"https://ghe.example.com/git/org/repo/blob/dev/skills/test/SKILL.md",
|
||||||
|
"https://ghe.example.com/git",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("githubInstallDirNameWithBaseURL() unexpected error for blob skill url = %v", err)
|
||||||
|
}
|
||||||
|
if dirName != "test" {
|
||||||
|
t.Fatalf("dirName for nested blob skill = %q, want test", dirName)
|
||||||
|
}
|
||||||
|
|
||||||
|
dirName, err = githubInstallDirNameWithBaseURL(
|
||||||
|
"https://ghe.example.com/git/org/repo/blob/dev/SKILL.md",
|
||||||
|
"https://ghe.example.com/git",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("githubInstallDirNameWithBaseURL() unexpected error for repo root blob skill = %v", err)
|
||||||
|
}
|
||||||
|
if dirName != "repo" {
|
||||||
|
t.Fatalf("dirName for repo root blob skill = %q, want repo", dirName)
|
||||||
|
}
|
||||||
|
|
||||||
ref, err = parseGitHubRefWithBaseURL("https://ghe.example.com/git/org/repo", "https://ghe.example.com/git", "")
|
ref, err = parseGitHubRefWithBaseURL("https://ghe.example.com/git/org/repo", "https://ghe.example.com/git", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("parseGitHubRefWithBaseURL() unexpected error = %v", err)
|
t.Fatalf("parseGitHubRefWithBaseURL() unexpected error = %v", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue