| 40 | } |
| 41 | |
| 42 | func (f *apiLogFetcher) GetLog() (io.ReadCloser, error) { |
| 43 | logURL, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(f.repo.RepoHost()), "repos", f.repo.RepoOwner(), f.repo.RepoName(), "actions", "jobs", strconv.FormatInt(f.jobID, 10), "logs") |
| 44 | if err != nil { |
| 45 | return nil, err |
| 46 | } |
| 47 | |
| 48 | // TODO(api-client-rollout) |
| 49 | // This has been deferred from moving to api.Client due to returning the job log response body as an io.ReadCloser instead of decoding JSON. |
| 50 | req, err := http.NewRequest("GET", logURL.String(), nil) |
| 51 | if err != nil { |
| 52 | return nil, err |
| 53 | } |
| 54 | |
| 55 | resp, err := f.httpClient.Do(req) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | |
| 60 | if resp.StatusCode == 404 { |
| 61 | return nil, fmt.Errorf("log not found: %v", f.jobID) |
| 62 | } else if resp.StatusCode != 200 { |
| 63 | return nil, api.HandleHTTPError(resp) |
| 64 | } |
| 65 | |
| 66 | return resp.Body, nil |
| 67 | } |
| 68 | |
| 69 | // logSegment represents a segment of a log trail, which can be either an entire |
| 70 | // job log or an individual step log. |