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