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

Function getRunLog

pkg/cmd/run/view/view.go:495–541  ·  view source on GitHub ↗
(cache RunLogCache, httpClient *http.Client, repo ghrepo.Interface, run *shared.Run, attempt uint64)

Source from the content-addressed store, hash-verified

493}
494
495func getRunLog(cache RunLogCache, httpClient *http.Client, repo ghrepo.Interface, run *shared.Run, attempt uint64) (*zip.ReadCloser, error) {
496 cacheKey := fmt.Sprintf("%d-%d", run.ID, run.StartedTime().Unix())
497 isCached, err := cache.Exists(cacheKey)
498 if err != nil {
499 return nil, err
500 }
501
502 if !isCached {
503 // Run log does not exist in cache so retrieve and store it
504 logURL, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "actions", "runs", strconv.FormatInt(run.ID, 10), "logs")
505 if err != nil {
506 return nil, err
507 }
508
509 if attempt > 0 {
510 logURL, err = safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "actions", "runs", strconv.FormatInt(run.ID, 10), "attempts", strconv.FormatUint(attempt, 10), "logs")
511 if err != nil {
512 return nil, err
513 }
514 }
515
516 resp, err := getLog(httpClient, logURL)
517 if err != nil {
518 return nil, err
519 }
520 defer resp.Close()
521
522 data, err := io.ReadAll(resp)
523 if err != nil {
524 return nil, err
525 }
526 respReader := bytes.NewReader(data)
527
528 // Check if the response is a valid zip format
529 _, err = zip.NewReader(respReader, respReader.Size())
530 if err != nil {
531 return nil, err
532 }
533
534 err = cache.Create(cacheKey, respReader)
535 if err != nil {
536 return nil, err
537 }
538 }
539
540 return cache.Open(cacheKey)
541}
542
543func promptForJob(prompter shared.Prompter, cs *iostreams.ColorScheme, jobs []shared.Job) (*shared.Job, error) {
544 candidates := []string{"View all jobs in this run"}

Callers 1

runViewFunction · 0.85

Calls 12

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
getLogFunction · 0.85
StartedTimeMethod · 0.80
ExistsMethod · 0.80
OpenMethod · 0.80
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
CloseMethod · 0.65
SizeMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected