Skip to content

Commit fac59ac

Browse files
committed
Actions approval
1 parent fffc855 commit fac59ac

File tree

8 files changed

+90
-7
lines changed

8 files changed

+90
-7
lines changed

options/locale/locale_en-US.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,6 +3690,15 @@ management = Secrets Management
36903690
36913691
[actions]
36923692
actions = Actions
3693+
general = General
3694+
general.approval_for_workflows_from_contributors = Approval for running fork pull request workflows from contributors
3695+
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>
3696+
general.approval_for_first_time_contributors_to_gitea = Require approval for first-time contributors who are new to Gitea
3697+
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.
3698+
general.approval_for_first_time_contributors = Require approval for first-time contributors
3699+
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.
3700+
general.approval_for_all_external_contributors = Require approval for all external contributors
3701+
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.
36933702
36943703
unit.desc = Manage actions
36953704

routers/web/repo/setting/action.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package setting
2+
3+
import (
4+
"net/http"
5+
6+
"code.gitea.io/gitea/modules/templates"
7+
"code.gitea.io/gitea/services/context"
8+
)
9+
10+
const (
11+
tmplRepoActionsGeneral templates.TplName = "repo/settings/actions"
12+
)
13+
14+
// General ...
15+
func General(ctx *context.Context) {
16+
ctx.Data["PageIsSharedSettingsActionsGeneral"] = true
17+
ctx.Data["Title"] = ctx.Tr("actions.general")
18+
ctx.Data["PageType"] = "general"
19+
20+
ctx.Data["Checked"] = 3
21+
22+
ctx.HTML(http.StatusOK, tmplRepoActionsGeneral)
23+
}
24+
25+
// GeneralPost ...
26+
func GeneralPost(ctx *context.Context) {
27+
ctx.Data["PageIsSharedSettingsActionsGeneral"] = true
28+
ctx.Data["Title"] = ctx.Tr("actions.general")
29+
ctx.Data["PageType"] = "general"
30+
31+
ctx.Data["Checked"] = 3
32+
33+
ctx.HTML(http.StatusOK, tmplRepoActionsGeneral)
34+
}

routers/web/repo/setting/runners.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,3 @@ func RunnerDeletePost(ctx *context.Context) {
181181
}
182182
actions_shared.RunnerDeletePost(ctx, ctx.PathParamInt64("runnerid"), rCtx.RedirectLink, rCtx.RedirectLink+url.PathEscape(ctx.PathParam("runnerid")))
183183
}
184-
185-
func RedirectToDefaultSetting(ctx *context.Context) {
186-
ctx.Redirect(ctx.Repo.RepoLink + "/settings/actions/runners")
187-
}

routers/web/web.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,8 @@ func registerRoutes(m *web.Router) {
11351135
})
11361136
})
11371137
m.Group("/actions", func() {
1138-
m.Get("", repo_setting.RedirectToDefaultSetting)
1138+
m.Get("", repo_setting.General)
1139+
m.Post("", repo_setting.GeneralPost)
11391140
addSettingsRunnersRoutes()
11401141
addSettingsSecretsRoutes()
11411142
addSettingsVariablesRoutes()

templates/repo/settings/actions.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{{template "repo/settings/layout_head" (dict "ctxData" . "pageClass" "repository settings actions")}}
22
<div class="repo-setting-content">
3-
{{if eq .PageType "runners"}}
3+
{{if eq .PageType "general"}}
4+
{{template "shared/actions/general" .}}
5+
{{else if eq .PageType "runners"}}
46
{{template "shared/actions/runner_list" .}}
57
{{else if eq .PageType "secrets"}}
68
{{template "shared/secrets/add_list" .}}

templates/repo/settings/navbar.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@
3434
{{end}}
3535
{{end}}
3636
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
37-
<details class="item toggleable-item" {{if or .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables}}open{{end}}>
37+
<details class="item toggleable-item" {{if or .PageIsSharedSettingsActionsGeneral .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables}}open{{end}}>
3838
<summary>{{ctx.Locale.Tr "actions.actions"}}</summary>
3939
<div class="menu">
40+
<a class="{{if .PageIsSharedSettingsActionsGeneral}}active {{end}}item" href="{{.RepoLink}}/settings/actions">
41+
{{ctx.Locale.Tr "actions.general"}}
42+
</a>
4043
<a class="{{if .PageIsSharedSettingsRunners}}active {{end}}item" href="{{.RepoLink}}/settings/actions/runners">
4144
{{ctx.Locale.Tr "actions.runners"}}
4245
</a>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div>
2+
<h4 class="ui top attached header">
3+
{{ctx.Locale.Tr "actions.general.approval_for_workflows_from_contributors"}}
4+
</h4>
5+
<div class="ui attached segment">
6+
{{ctx.Locale.Tr "actions.general.approval_for_workflows_from_contributors_desc"}}
7+
</div>
8+
<div class="ui bottom attached segment">
9+
<form class="ui form" action="" method="post">
10+
{{.CsrfTokenHtml}}
11+
<div class="field">
12+
<div class="ui radio checkbox">
13+
<input type="radio" name="approvalType" value="1" {{if eq .Checked 1}}checked{{end}}>
14+
<label>{{ctx.Locale.Tr "actions.general.approval_for_first_time_contributors_to_gitea"}}</label>
15+
<span class="help">{{ctx.Locale.Tr "actions.general.approval_for_first_time_contributors_to_gitea_helper"}}</span>
16+
</div>
17+
</div>
18+
<div class="field">
19+
<div class="ui radio checkbox">
20+
<input type="radio" name="approvalType" value="2" {{if eq .Checked 2}}checked{{end}}>
21+
<label>{{ctx.Locale.Tr "actions.general.approval_for_first_time_contributors"}}</label>
22+
<span class="help">{{ctx.Locale.Tr "actions.general.approval_for_first_time_contributors_helper"}}</span>
23+
</div>
24+
</div>
25+
<div class="field">
26+
<div class="ui radio checkbox">
27+
<input type="radio" name="approvalType" value="3" {{if eq .Checked 3}}checked{{end}}>
28+
<label>{{ctx.Locale.Tr "actions.general.approval_for_all_external_contributors"}}</label>
29+
<span class="help">{{ctx.Locale.Tr "actions.general.approval_for_all_external_contributors_helper"}}</span>
30+
</div>
31+
</div>
32+
<div class="field">
33+
<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.update_settings"}}</button>
34+
</div>
35+
</form>
36+
</div>
37+
</div>

web_src/css/form.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ textarea:focus,
218218

219219
.form .help {
220220
color: var(--color-secondary-dark-5);
221+
padding-top: 0.6em;
221222
padding-bottom: 0.6em;
222223
display: inline-block;
223224
}

0 commit comments

Comments
 (0)