MCPcopy Create free account
hub / github.com/cli/cli / GetLog

Method GetLog

pkg/cmd/run/view/logs.go:41–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41func (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.

Callers 1

TestApiLogFetcherFunction · 0.95

Calls 10

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
UnexpectedStatusErrorFunction · 0.92
RequestMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestApiLogFetcherFunction · 0.76