aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web
diff options
context:
space:
mode:
authoryp05327 <576951401@qq.com>2023-08-22 11:30:02 +0900
committerGitHub <noreply@github.com>2023-08-22 10:30:02 +0800
commita4a567f29f69e39d57a9fa7008d708f7fd080e58 (patch)
treea33773d1860087d7ec4c766c2117e405b03be335 /routers/web
parentb3f713717407fcb66515a7a702e81b2028800f76 (diff)
downloadgitea-a4a567f29f69e39d57a9fa7008d708f7fd080e58.tar.gz
gitea-a4a567f29f69e39d57a9fa7008d708f7fd080e58.zip
Check disabled workflow when rerun jobs (#26535)
In GitHub, we can not rerun jobs if the workflow is disabled. --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers/web')
-rw-r--r--routers/web/repo/actions/view.go28
-rw-r--r--routers/web/web.go4
2 files changed, 18 insertions, 14 deletions
diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go
index af2ec21e4b..e4ca6a7198 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 e70e360d59..bbab9b37b5 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)