summaryrefslogtreecommitdiffstats
path: root/routers/web/repo/actions/manual.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-12-12 23:57:56 +0100
commite68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch)
tree97775d6c13b0f416af55314eb6a89ef792474615 /routers/web/repo/actions/manual.go
parentInitial commit. (diff)
downloadforgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz
forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to '')
-rw-r--r--routers/web/repo/actions/manual.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/routers/web/repo/actions/manual.go b/routers/web/repo/actions/manual.go
new file mode 100644
index 0000000..949469f
--- /dev/null
+++ b/routers/web/repo/actions/manual.go
@@ -0,0 +1,62 @@
+// Copyright 2024 The Forgejo Authors.
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package actions
+
+import (
+ "net/url"
+
+ actions_service "code.gitea.io/gitea/services/actions"
+ context_module "code.gitea.io/gitea/services/context"
+)
+
+func ManualRunWorkflow(ctx *context_module.Context) {
+ workflowID := ctx.FormString("workflow")
+ if len(workflowID) == 0 {
+ ctx.ServerError("workflow", nil)
+ return
+ }
+
+ ref := ctx.FormString("ref")
+ if len(ref) == 0 {
+ ctx.ServerError("ref", nil)
+ return
+ }
+
+ if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil {
+ ctx.ServerError("IsEmpty", err)
+ return
+ } else if empty {
+ ctx.NotFound("IsEmpty", nil)
+ return
+ }
+
+ workflow, err := actions_service.GetWorkflowFromCommit(ctx.Repo.GitRepo, ref, workflowID)
+ if err != nil {
+ ctx.ServerError("GetWorkflowFromCommit", err)
+ return
+ }
+
+ location := ctx.Repo.RepoLink + "/actions?workflow=" + url.QueryEscape(workflowID) +
+ "&actor=" + url.QueryEscape(ctx.FormString("actor")) +
+ "&status=" + url.QueryEscape(ctx.FormString("status"))
+
+ formKeyGetter := func(key string) string {
+ formKey := "inputs[" + key + "]"
+ return ctx.Req.PostFormValue(formKey)
+ }
+
+ if err := workflow.Dispatch(ctx, formKeyGetter, ctx.Repo.Repository, ctx.Doer); err != nil {
+ if actions_service.IsInputRequiredErr(err) {
+ ctx.Flash.Error(ctx.Locale.Tr("actions.workflow.dispatch.input_required", err.(actions_service.InputRequiredErr).Name))
+ ctx.Redirect(location)
+ return
+ }
+ ctx.ServerError("workflow.Dispatch", err)
+ return
+ }
+
+ // forward to the page of the run which was just created
+ ctx.Flash.Info(ctx.Locale.Tr("actions.workflow.dispatch.success"))
+ ctx.Redirect(location)
+}