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

Function getRunLog

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

507}
508
509func getRunLog(cache RunLogCache, httpClient *http.Client, repo ghrepo.Interface, run *shared.Run, attempt uint64) (*zip.ReadCloser, error) {
510 cacheKey := fmt.Sprintf("%d-%d", run.ID, run.StartedTime().Unix())
511 isCached, err := cache.Exists(cacheKey)
512 if err != nil {
513 return nil, err
514 }
515
516 if !isCached {
517 // Run log does not exist in cache so retrieve and store it
518 logPath, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "runs", strconv.FormatInt(run.ID, 10), "logs")
519 if err != nil {
520 return nil, err
521 }
522
523 if attempt > 0 {
524 logPath, err = safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "runs", strconv.FormatInt(run.ID, 10), "attempts", strconv.FormatUint(attempt, 10), "logs")
525 if err != nil {
526 return nil, err
527 }
528 }
529
530 resp, err := getLog(httpClient, repo.RepoHost(), logPath)
531 if err != nil {
532 return nil, err
533 }
534 defer resp.Close()
535
536 data, err := io.ReadAll(resp)
537 if err != nil {
538 return nil, err
539 }
540 respReader := bytes.NewReader(data)
541
542 // Check if the response is a valid zip format
543 _, err = zip.NewReader(respReader, respReader.Size())
544 if err != nil {
545 return nil, err
546 }
547
548 err = cache.Create(cacheKey, respReader)
549 if err != nil {
550 return nil, err
551 }
552 }
553
554 return cache.Open(cacheKey)
555}
556
557func promptForJob(prompter shared.Prompter, cs *iostreams.ColorScheme, jobs []shared.Job) (*shared.Job, error) {
558 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