feat: include attempt in getRunLog

This commit is contained in:
Wing-Kam Wong 2023-03-26 19:12:21 +08:00
parent 897a2aa53f
commit a4c77ffd92

View file

@ -277,7 +277,7 @@ func runView(opts *ViewOptions) error {
}
opts.IO.StartProgressIndicator()
runLogZip, err := getRunLog(opts.RunLogCache, httpClient, repo, run)
runLogZip, err := getRunLog(opts.RunLogCache, httpClient, repo, run, attempt)
opts.IO.StopProgressIndicator()
if err != nil {
return fmt.Errorf("failed to get run log: %w", err)
@ -431,13 +431,19 @@ func getLog(httpClient *http.Client, logURL string) (io.ReadCloser, error) {
return resp.Body, nil
}
func getRunLog(cache runLogCache, httpClient *http.Client, repo ghrepo.Interface, run *shared.Run) (*zip.ReadCloser, error) {
func getRunLog(cache runLogCache, httpClient *http.Client, repo ghrepo.Interface, run *shared.Run, attempt uint64) (*zip.ReadCloser, error) {
filename := fmt.Sprintf("run-log-%d-%d.zip", run.ID, run.StartedTime().Unix())
filepath := filepath.Join(os.TempDir(), "gh-cli-cache", filename)
if !cache.Exists(filepath) {
// Run log does not exist in cache so retrieve and store it
logURL := fmt.Sprintf("%srepos/%s/actions/runs/%d/logs",
ghinstance.RESTPrefix(repo.RepoHost()), ghrepo.FullName(repo), run.ID)
var logURL string
if attempt == 0 {
logURL = fmt.Sprintf("%srepos/%s/actions/runs/%d/logs",
ghinstance.RESTPrefix(repo.RepoHost()), ghrepo.FullName(repo), run.ID)
} else {
logURL = fmt.Sprintf("%srepos/%s/actions/runs/%d/attempts/%d/logs",
ghinstance.RESTPrefix(repo.RepoHost()), ghrepo.FullName(repo), run.ID, attempt)
}
resp, err := getLog(httpClient, logURL)
if err != nil {