getFileContent retrieves the actual content of a file
(ctx context.Context, owner, repo string, content *github.RepositoryContent)
| 177 | |
| 178 | // getFileContent retrieves the actual content of a file |
| 179 | func (g *GitHubAdapter) getFileContent(ctx context.Context, owner, repo string, content *github.RepositoryContent) ([]byte, error) { |
| 180 | fileContent, err := content.GetContent() |
| 181 | if err != nil { |
| 182 | return nil, fmt.Errorf("failed to get content: %w", err) |
| 183 | } |
| 184 | |
| 185 | if fileContent != "" { |
| 186 | // Content is already available (for small files) |
| 187 | return []byte(fileContent), nil |
| 188 | } |
| 189 | |
| 190 | // For larger files, we need to download them |
| 191 | url := content.GetDownloadURL() |
| 192 | if url == "" { |
| 193 | return nil, fmt.Errorf("no download URL available for file") |
| 194 | } |
| 195 | |
| 196 | resp, err := g.client.Client().Get(url) |
| 197 | if err != nil { |
| 198 | return nil, fmt.Errorf("failed to download file: %w", err) |
| 199 | } |
| 200 | defer resp.Body.Close() |
| 201 | |
| 202 | return io.ReadAll(resp.Body) |
| 203 | } |
| 204 | |
| 205 | // isTextFile checks if a file is likely to be a text file |
| 206 | func isTextFile(filename string) bool { |