| 506 | } |
| 507 | |
| 508 | func 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 | |
| 556 | func promptForJob(prompter shared.Prompter, cs *iostreams.ColorScheme, jobs []shared.Job) (*shared.Job, error) { |
| 557 | candidates := []string{"View all jobs in this run"} |