( gist: GitHubGistResponse, source: string, )
| 97 | } |
| 98 | |
| 99 | export function parseGitHubGistResponse( |
| 100 | gist: GitHubGistResponse, |
| 101 | source: string, |
| 102 | ): SnippetImportParseResult { |
| 103 | const files = getGistFiles(gist) |
| 104 | const warnings: SnippetImportParseResult['warnings'] = [] |
| 105 | |
| 106 | if (!files.length) { |
| 107 | return { |
| 108 | snippets: [], |
| 109 | warnings: [ |
| 110 | { |
| 111 | code: 'gist.noFiles', |
| 112 | source, |
| 113 | }, |
| 114 | ], |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | const contents: SnippetImportCandidate['contents'] = [] |
| 119 | |
| 120 | files.forEach((file) => { |
| 121 | const filename |
| 122 | = typeof file.filename === 'string' && file.filename.trim() |
| 123 | ? file.filename |
| 124 | : 'gist-file' |
| 125 | |
| 126 | if (file.truncated) { |
| 127 | warnings.push({ |
| 128 | code: 'gist.truncatedSkipped', |
| 129 | source: `${source}/${filename}`, |
| 130 | }) |
| 131 | return |
| 132 | } |
| 133 | |
| 134 | if (typeof file.content !== 'string') { |
| 135 | warnings.push({ |
| 136 | code: 'gist.contentMissing', |
| 137 | source: `${source}/${filename}`, |
| 138 | }) |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | contents.push({ |
| 143 | label: normalizeImportEntryName(filename, 'Fragment'), |
| 144 | language: getLanguage(file), |
| 145 | value: file.content, |
| 146 | }) |
| 147 | }) |
| 148 | |
| 149 | if (!contents.length) { |
| 150 | return { |
| 151 | snippets: [], |
| 152 | warnings, |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | return { |
no test coverage detected