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

Function InjectGitHubMetadata

internal/skills/frontmatter/frontmatter.go:72–105  ·  view source on GitHub ↗

InjectGitHubMetadata adds GitHub tracking metadata to the spec-defined "metadata" map in frontmatter. Keys are prefixed with "github-" to avoid collisions with other tools' metadata. repoID is the repository's immutable GitHub ID; 0 means unknown. pinnedRef is the user's explicit --pin value; empty

(content string, host, owner, repo string, repoID int64, ref, treeSHA, pinnedRef, skillPath string)

Source from the content-addressed store, hash-verified

70// pinnedRef is the user's explicit --pin value; empty string means unpinned.
71// skillPath is the skill's source path in the repo (e.g. "skills/author/my-skill").
72func InjectGitHubMetadata(content string, host, owner, repo string, repoID int64, ref, treeSHA, pinnedRef, skillPath string) (string, error) {
73 result, err := Parse(content)
74 if err != nil {
75 return "", err
76 }
77
78 if result.RawYAML == nil {
79 result.RawYAML = make(map[string]any)
80 }
81
82 meta, _ := result.RawYAML["metadata"].(map[string]any)
83 if meta == nil {
84 meta = make(map[string]any)
85 }
86 delete(meta, "github-owner")
87 meta["github-repo"] = source.BuildRepoURL(host, owner, repo)
88 if repoID != 0 {
89 meta["github-repo-id"] = strconv.FormatInt(repoID, 10)
90 } else {
91 delete(meta, "github-repo-id")
92 }
93 meta["github-ref"] = ref
94 delete(meta, "github-sha")
95 meta["github-tree-sha"] = treeSHA
96 meta["github-path"] = skillPath
97 if pinnedRef != "" {
98 meta["github-pinned"] = pinnedRef
99 } else {
100 delete(meta, "github-pinned")
101 }
102 result.RawYAML["metadata"] = meta
103
104 return Serialize(result.RawYAML, result.Body)
105}
106
107// InjectLocalMetadata adds local-source tracking metadata to frontmatter.
108// sourcePath is the absolute path to the source skill directory.

Callers 2

installSkillFunction · 0.92
TestInjectGitHubMetadataFunction · 0.85

Calls 3

BuildRepoURLFunction · 0.92
ParseFunction · 0.85
SerializeFunction · 0.85

Tested by 1

TestInjectGitHubMetadataFunction · 0.68