From fac59ac4a67282cf9a29b7c0b45d782307924f77 Mon Sep 17 00:00:00 2001 From: hiifong Date: Sun, 19 Jan 2025 20:20:13 +0800 Subject: [PATCH 1/2] Actions approval --- options/locale/locale_en-US.ini | 9 +++++++ routers/web/repo/setting/action.go | 34 ++++++++++++++++++++++++ routers/web/repo/setting/runners.go | 4 --- routers/web/web.go | 3 ++- templates/repo/settings/actions.tmpl | 4 ++- templates/repo/settings/navbar.tmpl | 5 +++- templates/shared/actions/general.tmpl | 37 +++++++++++++++++++++++++++ web_src/css/form.css | 1 + 8 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 routers/web/repo/setting/action.go create mode 100644 templates/shared/actions/general.tmpl diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 41f6c5055d64b..d0238f5268afb 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3690,6 +3690,15 @@ management = Secrets Management [actions] actions = Actions +general = General +general.approval_for_workflows_from_contributors = Approval for running fork pull request workflows from contributors +general.approval_for_workflows_from_contributors_desc = Choose which subset of users will require approval before running workflows on their pull requests. Both the pull request author and the actor of the pull request event triggering the workflow will be checked to determine if approval is required. If approval is required, a user with write access to the repository must approve the pull request workflow to be run. +general.approval_for_first_time_contributors_to_gitea = Require approval for first-time contributors who are new to Gitea +general.approval_for_first_time_contributors_to_gitea_helper = Only users who are both new on Gitea and who have never had a commit or pull request merged into this repository will require approval to run workflows. +general.approval_for_first_time_contributors = Require approval for first-time contributors +general.approval_for_first_time_contributors_helper = Only users who have never had a commit or pull request merged into this repository will require approval to run workflows. +general.approval_for_all_external_contributors = Require approval for all external contributors +general.approval_for_all_external_contributors_helper = All users that are not a member or owner of this repository and not a member of the %s will require approval to run workflows. unit.desc = Manage actions diff --git a/routers/web/repo/setting/action.go b/routers/web/repo/setting/action.go new file mode 100644 index 0000000000000..44a3935680868 --- /dev/null +++ b/routers/web/repo/setting/action.go @@ -0,0 +1,34 @@ +package setting + +import ( + "net/http" + + "code.gitea.io/gitea/modules/templates" + "code.gitea.io/gitea/services/context" +) + +const ( + tmplRepoActionsGeneral templates.TplName = "repo/settings/actions" +) + +// General ... +func General(ctx *context.Context) { + ctx.Data["PageIsSharedSettingsActionsGeneral"] = true + ctx.Data["Title"] = ctx.Tr("actions.general") + ctx.Data["PageType"] = "general" + + ctx.Data["Checked"] = 3 + + ctx.HTML(http.StatusOK, tmplRepoActionsGeneral) +} + +// GeneralPost ... +func GeneralPost(ctx *context.Context) { + ctx.Data["PageIsSharedSettingsActionsGeneral"] = true + ctx.Data["Title"] = ctx.Tr("actions.general") + ctx.Data["PageType"] = "general" + + ctx.Data["Checked"] = 3 + + ctx.HTML(http.StatusOK, tmplRepoActionsGeneral) +} diff --git a/routers/web/repo/setting/runners.go b/routers/web/repo/setting/runners.go index 94f2ae7a0c092..8d58b5023efb3 100644 --- a/routers/web/repo/setting/runners.go +++ b/routers/web/repo/setting/runners.go @@ -181,7 +181,3 @@ func RunnerDeletePost(ctx *context.Context) { } actions_shared.RunnerDeletePost(ctx, ctx.PathParamInt64("runnerid"), rCtx.RedirectLink, rCtx.RedirectLink+url.PathEscape(ctx.PathParam("runnerid"))) } - -func RedirectToDefaultSetting(ctx *context.Context) { - ctx.Redirect(ctx.Repo.RepoLink + "/settings/actions/runners") -} diff --git a/routers/web/web.go b/routers/web/web.go index 609a7d77ac596..4c66b37cd0ea0 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1135,7 +1135,8 @@ func registerRoutes(m *web.Router) { }) }) m.Group("/actions", func() { - m.Get("", repo_setting.RedirectToDefaultSetting) + m.Get("", repo_setting.General) + m.Post("", repo_setting.GeneralPost) addSettingsRunnersRoutes() addSettingsSecretsRoutes() addSettingsVariablesRoutes() diff --git a/templates/repo/settings/actions.tmpl b/templates/repo/settings/actions.tmpl index f38ab5b658412..5f42e2f32705f 100644 --- a/templates/repo/settings/actions.tmpl +++ b/templates/repo/settings/actions.tmpl @@ -1,6 +1,8 @@ {{template "repo/settings/layout_head" (dict "ctxData" . "pageClass" "repository settings actions")}}
- {{if eq .PageType "runners"}} + {{if eq .PageType "general"}} + {{template "shared/actions/general" .}} + {{else if eq .PageType "runners"}} {{template "shared/actions/runner_list" .}} {{else if eq .PageType "secrets"}} {{template "shared/secrets/add_list" .}} diff --git a/templates/repo/settings/navbar.tmpl b/templates/repo/settings/navbar.tmpl index 3e127ccbb3517..05adabadf2471 100644 --- a/templates/repo/settings/navbar.tmpl +++ b/templates/repo/settings/navbar.tmpl @@ -34,9 +34,12 @@ {{end}} {{end}} {{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}} -
+
{{ctx.Locale.Tr "actions.actions"}}