diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 547429a05a..378b0caec5 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -709,8 +709,21 @@ func getCurrentRunJobsByPathParam(ctx *context_module.Context) (*actions_model.A } func getCurrentRunAndUploadedArtifacts(ctx *context_module.Context, artifactName string) (*actions_model.ActionRun, []*actions_model.ActionArtifact, bool) { - run := getCurrentRunByPathParam(ctx) - if ctx.Written() { + var ( + run *actions_model.ActionRun + err error + ) + if ctx.PathParam("run") == "latest" { + run, err = actions_model.GetLatestRun(ctx, ctx.Repo.Repository.ID) + } else { + run, err = actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("run")) + } + if err != nil { + if errors.Is(err, util.ErrNotExist) { + ctx.HTTPError(http.StatusNotFound, err.Error()) + return nil, nil, false + } + ctx.ServerError("GetRunByIndex", err) return nil, nil, false } diff --git a/tests/integration/actions_artifact_preview_test.go b/tests/integration/actions_artifact_preview_test.go index c127915f9c..7df2dc708d 100644 --- a/tests/integration/actions_artifact_preview_test.go +++ b/tests/integration/actions_artifact_preview_test.go @@ -35,7 +35,7 @@ func TestActionsArtifactPreviewSingleFile(t *testing.T) { req := NewRequestf(t, "GET", "/%s/actions/runs/187/artifacts/artifact-download/preview", repo.FullName()) resp := session.MakeRequest(t, req, http.StatusOK) assert.Contains(t, resp.Body.String(), "abc.txt") - assert.Contains(t, resp.Body.String(), "/preview/raw?path=abc.txt") + assert.Contains(t, resp.Body.String(), "/preview/raw/abc.txt") req = NewRequestf(t, "GET", "/%s/actions/runs/187/artifacts/artifact-download/preview/raw", repo.FullName()) resp = session.MakeRequest(t, req, http.StatusOK)