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

Function getRunLog

pkg/cmd/run/view/view.go:492–538  ·  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

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

Callers 1

runViewFunction · 0.85

Calls 11

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

Tested by

no test coverage detected