From 66e2e3a4d2f7be431da86dc5451ff69f522a678a Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 16 Aug 2023 06:10:53 +0000 Subject: [PATCH 1/5] improve --- options/locale/locale_en-US.ini | 1 + routers/web/repo/actions/view.go | 28 ++++++++++++++---------- routers/web/web.go | 4 ++-- templates/repo/actions/view.tmpl | 1 + web_src/js/components/RepoActionView.vue | 17 ++++++++++---- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 2f32a9df7000a..3e27175d3ba67 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3495,6 +3495,7 @@ workflow.disable = Disable Workflow workflow.disable_success = Workflow '%s' disabled successfully. workflow.enable = Enable Workflow workflow.enable_success = Workflow '%s' enabled successfully. +workflow.disabled = Workflow is disabled. need_approval_desc = Need approval to run workflows for fork pull request. diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index af2ec21e4bdda..e4ca6a71987f6 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -259,31 +259,35 @@ func ViewPost(ctx *context_module.Context) { ctx.JSON(http.StatusOK, resp) } -func RerunOne(ctx *context_module.Context) { +// Rerun will rerun jobs in the given run +// jobIndex = 0 means rerun all jobs +func Rerun(ctx *context_module.Context) { runIndex := ctx.ParamsInt64("run") jobIndex := ctx.ParamsInt64("job") - job, _ := getRunJobs(ctx, runIndex, jobIndex) - if ctx.Written() { + run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex) + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) return } - if err := rerunJob(ctx, job); err != nil { - ctx.Error(http.StatusInternalServerError, err.Error()) + // can not rerun job when workflow is disabled + cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions) + cfg := cfgUnit.ActionsConfig() + if cfg.IsWorkflowDisabled(run.WorkflowID) { + ctx.JSONError(ctx.Locale.Tr("actions.workflow.disabled")) return } - ctx.JSON(http.StatusOK, struct{}{}) -} - -func RerunAll(ctx *context_module.Context) { - runIndex := ctx.ParamsInt64("run") - - _, jobs := getRunJobs(ctx, runIndex, 0) + job, jobs := getRunJobs(ctx, runIndex, jobIndex) if ctx.Written() { return } + if jobIndex != 0 { + jobs = []*actions_model.ActionRunJob{job} + } + for _, j := range jobs { if err := rerunJob(ctx, j); err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) diff --git a/routers/web/web.go b/routers/web/web.go index e70e360d5991d..bbab9b37b5973 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1211,14 +1211,14 @@ func registerRoutes(m *web.Route) { m.Combo(""). Get(actions.View). Post(web.Bind(actions.ViewRequest{}), actions.ViewPost) - m.Post("/rerun", reqRepoActionsWriter, actions.RerunOne) + m.Post("/rerun", reqRepoActionsWriter, actions.Rerun) m.Get("/logs", actions.Logs) }) m.Post("/cancel", reqRepoActionsWriter, actions.Cancel) m.Post("/approve", reqRepoActionsWriter, actions.Approve) m.Post("/artifacts", actions.ArtifactsView) m.Get("/artifacts/{artifact_name}", actions.ArtifactsDownloadView) - m.Post("/rerun", reqRepoActionsWriter, actions.RerunAll) + m.Post("/rerun", reqRepoActionsWriter, actions.Rerun) }) }, reqRepoActionsReader, actions.MustEnableActions) diff --git a/templates/repo/actions/view.tmpl b/templates/repo/actions/view.tmpl index 7b07aa155b57d..438b0333ffc3d 100644 --- a/templates/repo/actions/view.tmpl +++ b/templates/repo/actions/view.tmpl @@ -2,6 +2,7 @@