(ctx context.Context, codespace *Codespace, path string)
| 1139 | } |
| 1140 | |
| 1141 | func (a *API) GetCodespaceRepositoryContents(ctx context.Context, codespace *Codespace, path string) ([]byte, error) { |
| 1142 | req, err := http.NewRequest(http.MethodGet, a.githubAPI+"/repos/"+codespace.Repository.FullName+"/contents/"+path, nil) |
| 1143 | if err != nil { |
| 1144 | return nil, fmt.Errorf("error creating request: %w", err) |
| 1145 | } |
| 1146 | |
| 1147 | q := req.URL.Query() |
| 1148 | q.Add("ref", codespace.GitStatus.Ref) |
| 1149 | req.URL.RawQuery = q.Encode() |
| 1150 | |
| 1151 | a.setHeaders(req) |
| 1152 | resp, err := a.do(ctx, req, "/repos/*/contents/*") |
| 1153 | if err != nil { |
| 1154 | return nil, fmt.Errorf("error making request: %w", err) |
| 1155 | } |
| 1156 | defer resp.Body.Close() |
| 1157 | |
| 1158 | if resp.StatusCode == http.StatusNotFound { |
| 1159 | return nil, nil |
| 1160 | } else if resp.StatusCode != http.StatusOK { |
| 1161 | return nil, api.HandleHTTPError(resp) |
| 1162 | } |
| 1163 | |
| 1164 | b, err := io.ReadAll(resp.Body) |
| 1165 | if err != nil { |
| 1166 | return nil, fmt.Errorf("error reading response body: %w", err) |
| 1167 | } |
| 1168 | |
| 1169 | var response getCodespaceRepositoryContentsResponse |
| 1170 | if err := json.Unmarshal(b, &response); err != nil { |
| 1171 | return nil, fmt.Errorf("error unmarshalling response: %w", err) |
| 1172 | } |
| 1173 | |
| 1174 | decoded, err := base64.StdEncoding.DecodeString(response.Content) |
| 1175 | if err != nil { |
| 1176 | return nil, fmt.Errorf("error decoding content: %w", err) |
| 1177 | } |
| 1178 | |
| 1179 | return decoded, nil |
| 1180 | } |
| 1181 | |
| 1182 | // do executes the given request and returns the response. It creates an |
| 1183 | // opentracing span to track the length of the request. |
nothing calls this directly
no test coverage detected