Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize actions approval #33326

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a target="_blank" rel="noopener noreferrer" href="https://docs.github.com/actions/managing-workflow-runs/approving-workflow-runs-from-public-forks">approve the pull request workflow to be run.</a>
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

Expand Down
37 changes: 37 additions & 0 deletions routers/web/repo/setting/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

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)
}
4 changes: 0 additions & 4 deletions routers/web/repo/setting/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
3 changes: 2 additions & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion templates/repo/settings/actions.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{template "repo/settings/layout_head" (dict "ctxData" . "pageClass" "repository settings actions")}}
<div class="repo-setting-content">
{{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" .}}
Expand Down
5 changes: 4 additions & 1 deletion templates/repo/settings/navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
{{end}}
{{end}}
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
<details class="item toggleable-item" {{if or .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables}}open{{end}}>
<details class="item toggleable-item" {{if or .PageIsSharedSettingsActionsGeneral .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables}}open{{end}}>
<summary>{{ctx.Locale.Tr "actions.actions"}}</summary>
<div class="menu">
<a class="{{if .PageIsSharedSettingsActionsGeneral}}active {{end}}item" href="{{.RepoLink}}/settings/actions">
{{ctx.Locale.Tr "actions.general"}}
</a>
<a class="{{if .PageIsSharedSettingsRunners}}active {{end}}item" href="{{.RepoLink}}/settings/actions/runners">
{{ctx.Locale.Tr "actions.runners"}}
</a>
Expand Down
37 changes: 37 additions & 0 deletions templates/shared/actions/general.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div>
<h4 class="ui top attached header">
{{ctx.Locale.Tr "actions.general.approval_for_workflows_from_contributors"}}
</h4>
<div class="ui attached segment">
{{ctx.Locale.Tr "actions.general.approval_for_workflows_from_contributors_desc"}}
</div>
<div class="ui bottom attached segment">
<form class="ui form" action="" method="post">
{{.CsrfTokenHtml}}
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="approvalType" value="1" {{if eq .Checked 1}}checked{{end}}>
<label>{{ctx.Locale.Tr "actions.general.approval_for_first_time_contributors_to_gitea"}}</label>
<span class="help">{{ctx.Locale.Tr "actions.general.approval_for_first_time_contributors_to_gitea_helper"}}</span>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="approvalType" value="2" {{if eq .Checked 2}}checked{{end}}>
<label>{{ctx.Locale.Tr "actions.general.approval_for_first_time_contributors"}}</label>
<span class="help">{{ctx.Locale.Tr "actions.general.approval_for_first_time_contributors_helper"}}</span>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="approvalType" value="3" {{if eq .Checked 3}}checked{{end}}>
<label>{{ctx.Locale.Tr "actions.general.approval_for_all_external_contributors"}}</label>
<span class="help">{{ctx.Locale.Tr "actions.general.approval_for_all_external_contributors_helper"}}</span>
</div>
</div>
<div class="field">
<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.update_settings"}}</button>
</div>
</form>
</div>
</div>
1 change: 1 addition & 0 deletions web_src/css/form.css
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ textarea:focus,

.form .help {
color: var(--color-secondary-dark-5);
padding-top: 0.6em;
padding-bottom: 0.6em;
display: inline-block;
}
Expand Down
Loading