UNPKG

@androbinco/prompts-cli

Version:

Robin CLI for importing generative AI prompts

40 lines (33 loc) 1.1 kB
import { getOctokitClient } from '../octokit/octokit.js'; /** * Fetches the content of a given Gist ID. * @param {string} gistId - The ID of the Gist to fetch. * @returns {Promise<object|null>} A promise that resolves to the Gist's files object, * or throws an error if fetching fails. * The files object structure is: * { "filename1.txt": { content: "...", ... }, ... } */ export async function fetchGistContent(gistId) { const octokit = getOctokitClient(); try { const response = await octokit.rest.gists.get({ gist_id: gistId, }); if (response.status === 200) { return response.data.files; } else { const error = new Error( `Failed to fetch Gist ${gistId}: GitHub API responded with status ${response.status}`, ); error.status = response.status; throw error; } } catch (error) { const enhancedError = new Error( `Failed to fetch Gist ${gistId}. Original message: ${error.message}`, ); enhancedError.status = error.status || 500; enhancedError.originalError = error; throw enhancedError; } }