(project: string)
| 192 | // TODO(deprecate-skills-phase-2): Remove direct GitHub Skill Hub fallback when |
| 193 | // deprecated `ctx7 skills install/info` commands are deleted. |
| 194 | export async function listSkillsFromGitHub(project: string): Promise<GitHubSkillsResult> { |
| 195 | try { |
| 196 | const parts = project.split("/").filter(Boolean); |
| 197 | if (parts.length < 2) return { status: "error", error: "Invalid project format" }; |
| 198 | const [owner, repo] = parts; |
| 199 | |
| 200 | const headers = getGitHubHeaders(); |
| 201 | const branchResult = await fetchDefaultBranch(owner, repo, headers); |
| 202 | if ("error" in branchResult) { |
| 203 | if (branchResult.status === 404) return { status: "repo_not_found" }; |
| 204 | return { status: "error", error: branchResult.error }; |
| 205 | } |
| 206 | |
| 207 | const treeData = await fetchRepoTree(owner, repo, branchResult.branch, headers); |
| 208 | if ("error" in treeData) return { status: "error", error: treeData.error }; |
| 209 | |
| 210 | const skillMdFiles = treeData.tree.filter( |
| 211 | (item) => item.type === "blob" && item.path.toLowerCase().endsWith("skill.md") |
| 212 | ); |
| 213 | |
| 214 | const skills: (Skill & { project: string })[] = []; |
| 215 | for (const item of skillMdFiles) { |
| 216 | const rawUrl = `${GITHUB_RAW}/${owner}/${repo}/${branchResult.branch}/${item.path}`; |
| 217 | const response = await fetch(rawUrl, { headers }); |
| 218 | if (!response.ok) continue; |
| 219 | |
| 220 | const content = await response.text(); |
| 221 | const meta = parseSkillFrontmatter(content); |
| 222 | if (!meta) continue; |
| 223 | |
| 224 | const skillDir = item.path.split("/").slice(0, -1).join("/"); |
| 225 | skills.push({ |
| 226 | name: meta.name, |
| 227 | description: meta.description, |
| 228 | url: `https://github.com/${owner}/${repo}/tree/${branchResult.branch}/${skillDir}`, |
| 229 | project, |
| 230 | }); |
| 231 | } |
| 232 | |
| 233 | return { status: "ok", skills }; |
| 234 | } catch (err) { |
| 235 | const message = err instanceof Error ? err.message : String(err); |
| 236 | return { status: "error", error: message }; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | export async function getSkillFromGitHub( |
| 241 | project: string, |
no test coverage detected