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

Function getRunLog

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

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