| 39 | } |
| 40 | |
| 41 | func (f *apiLogFetcher) GetLog() (io.ReadCloser, error) { |
| 42 | logPath, err := safeurl.JoinPath("repos", f.repo.RepoOwner(), f.repo.RepoName(), "actions", "jobs", strconv.FormatInt(f.jobID, 10), "logs") |
| 43 | if err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | |
| 47 | // The response body is the log stream, which is handed to the caller rather than decoded. |
| 48 | // TODO(api-client-rollout) |
| 49 | // This line of code is part of a mechanical roll out of the api client. |
| 50 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 51 | resp, err := api.NewClientFromHTTP(f.httpClient).Request(f.repo.RepoHost(), http.MethodGet, logPath.String(), nil) |
| 52 | if err != nil { |
| 53 | if httpErr, ok := errors.AsType[api.HTTPError](err); ok && httpErr.StatusCode == http.StatusNotFound { |
| 54 | return nil, fmt.Errorf("log not found: %v", f.jobID) |
| 55 | } |
| 56 | return nil, err |
| 57 | } |
| 58 | |
| 59 | if resp.StatusCode != http.StatusOK { |
| 60 | defer resp.Body.Close() |
| 61 | return nil, api.UnexpectedStatusError(resp) |
| 62 | } |
| 63 | |
| 64 | return resp.Body, nil |
| 65 | } |
| 66 | |
| 67 | // logSegment represents a segment of a log trail, which can be either an entire |
| 68 | // job log or an individual step log. |