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

Function getRunLog

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

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