aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2023-08-14 23:14:30 +0800
committerGitHub <noreply@github.com>2023-08-14 15:14:30 +0000
commit19872063a3c14256a1d89b2a104d63e7538a3a28 (patch)
treedcdfb5ffa923fb0f66d5e0b4b94f890be3e9fdf5 /routers
parent253737eb364192e31c8be1fc9bd9581331ca37a9 (diff)
downloadgitea-19872063a3c14256a1d89b2a104d63e7538a3a28.tar.gz
gitea-19872063a3c14256a1d89b2a104d63e7538a3a28.zip
add disable workflow feature (#26413)
As title, that's simmilar with github. ![image](https://github.com/go-gitea/gitea/assets/25342410/9e8b2444-63e0-4e87-80da-730c1e4d09d6) ![image](https://github.com/go-gitea/gitea/assets/25342410/6c3a3345-3ba7-48c9-9acd-3e621632491b) --------- Signed-off-by: a1012112796 <1012112796@qq.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Jason Song <i@wolfogre.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/actions/actions.go9
-rw-r--r--routers/web/repo/actions/view.go41
-rw-r--r--routers/web/web.go2
3 files changed, 52 insertions, 0 deletions
diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go
index 5a12f52dcd..b0f4b6f897 100644
--- a/routers/web/repo/actions/actions.go
+++ b/routers/web/repo/actions/actions.go
@@ -137,6 +137,15 @@ func List(ctx *context.Context) {
actorID := ctx.FormInt64("actor")
status := ctx.FormInt("status")
ctx.Data["CurWorkflow"] = workflow
+
+ actionsConfig := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
+ ctx.Data["ActionsConfig"] = actionsConfig
+
+ if len(workflow) > 0 && ctx.Repo.IsAdmin() {
+ ctx.Data["AllowDisableOrEnableWorkflow"] = true
+ ctx.Data["CurWorkflowDisabled"] = actionsConfig.IsWorkflowDisabled(workflow)
+ }
+
// if status or actor query param is not given to frontend href, (href="/<repoLink>/actions")
// they will be 0 by default, which indicates get all status or actors
ctx.Data["CurActor"] = actorID
diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go
index abb1f6b66b..af2ec21e4b 100644
--- a/routers/web/repo/actions/view.go
+++ b/routers/web/repo/actions/view.go
@@ -17,6 +17,7 @@ import (
actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/base"
@@ -572,3 +573,43 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
}
}
}
+
+func DisableWorkflowFile(ctx *context_module.Context) {
+ disableOrEnableWorkflowFile(ctx, false)
+}
+
+func EnableWorkflowFile(ctx *context_module.Context) {
+ disableOrEnableWorkflowFile(ctx, true)
+}
+
+func disableOrEnableWorkflowFile(ctx *context_module.Context, isEnable bool) {
+ workflow := ctx.FormString("workflow")
+ if len(workflow) == 0 {
+ ctx.ServerError("workflow", nil)
+ return
+ }
+
+ cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
+ cfg := cfgUnit.ActionsConfig()
+
+ if isEnable {
+ cfg.EnableWorkflow(workflow)
+ } else {
+ cfg.DisableWorkflow(workflow)
+ }
+
+ if err := repo_model.UpdateRepoUnit(cfgUnit); err != nil {
+ ctx.ServerError("UpdateRepoUnit", err)
+ return
+ }
+
+ if isEnable {
+ ctx.Flash.Success(ctx.Tr("actions.workflow.enable_success", workflow))
+ } else {
+ ctx.Flash.Success(ctx.Tr("actions.workflow.disable_success", workflow))
+ }
+
+ redirectURL := fmt.Sprintf("%s/actions?workflow=%s&actor=%s&status=%s", ctx.Repo.RepoLink, url.QueryEscape(workflow),
+ url.QueryEscape(ctx.FormString("actor")), url.QueryEscape(ctx.FormString("status")))
+ ctx.JSONRedirect(redirectURL)
+}
diff --git a/routers/web/web.go b/routers/web/web.go
index f857a36b04..e70e360d59 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -1200,6 +1200,8 @@ func registerRoutes(m *web.Route) {
m.Group("/actions", func() {
m.Get("", actions.List)
+ m.Post("/disable", reqRepoAdmin, actions.DisableWorkflowFile)
+ m.Post("/enable", reqRepoAdmin, actions.EnableWorkflowFile)
m.Group("/runs/{run}", func() {
m.Combo("").