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

Function getRunLog

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

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