( ctx context.Context, owner string, repoName string, commit string, path string, )
| 74 | } |
| 75 | |
| 76 | func (c client) getFile( |
| 77 | ctx context.Context, |
| 78 | owner string, |
| 79 | repoName string, |
| 80 | commit string, |
| 81 | path string, |
| 82 | ) ([]byte, error) { |
| 83 | reqID := connectpkg.RequestIDFrom(ctx) |
| 84 | |
| 85 | start := time.Now() |
| 86 | c.log.DebugContext(ctx, "github getFile start", |
| 87 | slog.String("owner", owner), |
| 88 | slog.String("repo", repoName), |
| 89 | slog.String("path", path), |
| 90 | slog.String("request_id", reqID), |
| 91 | ) |
| 92 | r, _, err := c.repos.DownloadContents( |
| 93 | ctx, |
| 94 | owner, |
| 95 | repoName, |
| 96 | path, |
| 97 | &github.RepositoryContentGetOptions{Ref: commit}, |
| 98 | ) |
| 99 | dur := time.Since(start) |
| 100 | if err != nil { |
| 101 | c.log.LogAttrs(ctx, slog.LevelDebug, "github getFile failed", |
| 102 | slog.String("owner", owner), |
| 103 | slog.String("repo", repoName), |
| 104 | slog.String("path", path), |
| 105 | slog.String("request_id", reqID), |
| 106 | slog.Duration("duration", dur), |
| 107 | slog.String("error", err.Error()), |
| 108 | ) |
| 109 | return nil, fmt.Errorf("requesting: %w", err) |
| 110 | } |
| 111 | |
| 112 | defer r.Close() |
| 113 | |
| 114 | data, err := io.ReadAll(r) |
| 115 | if err != nil { |
| 116 | return data, fmt.Errorf("downloading: %w", err) |
| 117 | } |
| 118 | |
| 119 | c.log.LogAttrs(ctx, slog.LevelDebug, "github getFile completed", |
| 120 | slog.String("owner", owner), |
| 121 | slog.String("repo", repoName), |
| 122 | slog.String("path", path), |
| 123 | slog.String("request_id", reqID), |
| 124 | slog.Duration("duration", dur), |
| 125 | slog.Int("size", len(data)), |
| 126 | ) |
| 127 | |
| 128 | return data, nil |
| 129 | } |
no test coverage detected