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

Function getRunLog

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

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