MCPcopy Create free account
hub / github.com/cli/cli / parseInstalledSkill

Function parseInstalledSkill

pkg/cmd/skills/list/list.go:391–439  ·  view source on GitHub ↗
(data []byte, name, dir string, agentHostIDs []string, scope string)

Source from the content-addressed store, hash-verified

389}
390
391func parseInstalledSkill(data []byte, name, dir string, agentHostIDs []string, scope string) (listedSkill, bool) {
392 s := listedSkill{
393 skillName: name,
394 agentHostIDs: agentHostIDs,
395 scope: scope,
396 path: dir,
397 }
398
399 result, err := frontmatter.Parse(string(data))
400 if err != nil {
401 return s, false
402 }
403
404 meta := result.Metadata.Meta
405 if meta == nil {
406 return s, false
407 }
408 installMetadata := hasInstallMetadata(meta)
409
410 if sourcePath, _ := meta["github-path"].(string); sourcePath != "" {
411 if skillName := skillNameFromSourcePath(sourcePath); skillName != "" {
412 s.skillName = skillName
413 }
414 }
415
416 if repoURL, _ := meta["github-repo"].(string); repoURL != "" {
417 s.sourceURL = repoURL
418 s.source = repoURL
419 if repo, parseErr := source.ParseRepoURL(repoURL); parseErr == nil {
420 s.source = ghrepo.FullName(repo)
421 s.sourceURL = source.BuildRepoURL(repo.RepoHost(), repo.RepoOwner(), repo.RepoName())
422 }
423 } else if localPath, _ := meta["local-path"].(string); localPath != "" {
424 s.sourceURL = localPath
425 s.source = localPath
426 }
427
428 if ref, _ := meta["github-ref"].(string); ref != "" {
429 s.version = discovery.ShortRef(ref)
430 }
431 if pinnedRef, _ := meta["github-pinned"].(string); pinnedRef != "" {
432 s.pinned = true
433 if s.version == "" {
434 s.version = pinnedRef
435 }
436 }
437
438 return s, installMetadata
439}
440
441func hasInstallMetadata(meta map[string]any) bool {
442 for _, key := range []string{"github-repo", "github-ref", "github-tree-sha", "github-path", "github-pinned", "local-path"} {

Callers 1

scanInstalledSkillsFunction · 0.70

Calls 10

ParseFunction · 0.92
ParseRepoURLFunction · 0.92
FullNameFunction · 0.92
BuildRepoURLFunction · 0.92
ShortRefFunction · 0.92
hasInstallMetadataFunction · 0.85
skillNameFromSourcePathFunction · 0.85
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65

Tested by

no test coverage detected