Skip to content

Commit 1136088

Browse files
committed
Create Org Setting Actions RequireAction
1 parent 77a4a94 commit 1136088

File tree

9 files changed

+198
-35
lines changed

9 files changed

+198
-35
lines changed

models/repo/repo_unit.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ func (cfg *ActionsConfig) EnableGlobalWorkflow(file string) {
187187
cfg.EnabledGlobalWorkflows = append(cfg.EnabledGlobalWorkflows, file)
188188
}
189189

190+
func (cfg *ActionsConfig) GetGlobalWorkflow() []string {
191+
return cfg.EnabledGlobalWorkflows
192+
}
193+
190194
func (cfg *ActionsConfig) ToString() string {
191195
return strings.Join(cfg.DisabledWorkflows, ",")
192196
}

options/locale/locale_en-US.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,12 +3640,16 @@ runs.empty_commit_message = (empty commit message)
36403640
36413641
require_actions = Require Actions
36423642
require_actions.require_actions_manage_panel = Require Actions Management Panel
3643+
require_actions.enable_global_workflow = How to Enable Global Workflow
36433644
require_actions.id = ID
36443645
require_actions.name = Name
3646+
require_actions.add = Add Global Workflow
3647+
require_actions.add_require_actions = Enable selected Workflow
36453648
require_actions.new = Create New
36463649
require_actions.status = Status
36473650
require_actions.version = Version
36483651
require_actions.repo = Repo
3652+
require_actions.workflow = Workflow Filename
36493653
require_actions.link = Link
36503654
require_actions.none = No Require Actions Available
36513655
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
// WIP RequireAction
5+
6+
package setting
7+
8+
import (
9+
"code.gitea.io/gitea/services/context"
10+
)
11+
12+
func RedirectToRepoSetting(ctx *context.Context) {
13+
ctx.Redirect(ctx.Org.OrgLink + "/settings/actions/require_actions")
14+
}

routers/web/repo/setting/require_actions.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ func RequireActions(ctx *context.Context) {
5555
ctx.ServerError("getRequireActionsCtx", err)
5656
return
5757
}
58-
shared.SetRequireActionsContext(ctx)
59-
if ctx.Written() {
60-
return
61-
}
58+
59+
page := ctx.FormInt("page")
60+
if page <= 1 { page = 1 }
6261
opts := actions_model.FindRequireActionOptions{
6362
ListOptions: db.ListOptions{
64-
Page: 1,
63+
Page: page,
6564
PageSize: 10,
6665
},
67-
OrgID: ctx.Org.Organization.ID,
6866
}
69-
shared.RequireActionsList(ctx, opts)
67+
shared.SetRequireActionsContext(ctx, opts)
68+
ctx.Data["Link"] = vCtx.RedirectLink
69+
shared.GlobalEnableWorkflow(ctx, ctx.Org.Organization.ID)
7070
ctx.HTML(http.StatusOK, vCtx.RequireActionsTemplate)
7171
}

routers/web/shared/actions/require_action.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,54 @@
66
package actions
77

88
import (
9-
//"errors"
109

11-
actions_model "code.gitea.io/gitea/models/actions"
10+
actions_model "code.gitea.io/gitea/models/actions"
11+
org_model "code.gitea.io/gitea/models/organization"
1212
"code.gitea.io/gitea/models/db"
1313
//"code.gitea.io/gitea/modules/log"
1414
//"code.gitea.io/gitea/modules/util"
15+
"code.gitea.io/gitea/models/unit"
1516
//"code.gitea.io/gitea/modules/web"
1617
//"code.gitea.io/gitea/services/forms"
1718
// action_service "code.gitea.io/gitea/services/actions"
1819

1920
"code.gitea.io/gitea/services/context"
2021
)
2122

22-
// RequireActionsList prepares data for workflow actions list
23-
func RequireActionsList(ctx *context.Context, opts actions_model.FindRequireActionOptions) {
24-
//all_opts := repo_model.FindEnabledGlobalWorkflowsOptions {}
25-
//avalible_workflows, count, err := db.FindAndCount[repo_model.RepoUnit](ctx, all_opts)
23+
// SetRequireActionDeletePost response for deleting a require action workflow
24+
func SetRequireActionsContext(ctx *context.Context, opts actions_model.FindRequireActionOptions) {
2625
require_actions, count, err := db.FindAndCount[actions_model.RequireAction](ctx, opts)
2726
if err != nil {
2827
ctx.ServerError("CountRequireAction", err)
2928
return
3029
}
31-
/*
32-
if err := actions_model.RequireActionList(require_actions).LoadAttributes(ctx); err != nil {
33-
ctx.ServerError("RequireActionLoadAttributes", err)
34-
return
35-
}
36-
*/
3730
ctx.Data["RequireActions"] = require_actions
3831
ctx.Data["Total"] = count
39-
ctx.Data["RequireActionsOrgID"] = opts.OrgID
40-
//ctx.Data["Sort"] = opts.Sort
32+
ctx.Data["OrgID"] = ctx.Org.Organization.ID
33+
ctx.Data["OrgName"] = ctx.Org.Organization.Name
4134
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
4235
ctx.Data["Page"] = pager
43-
workflow_list, err := actions_model.ListAvailableWorkflows(ctx, opts.OrgID)
36+
}
37+
38+
// get all the available enable global workflow in the org's repo
39+
func GlobalEnableWorkflow(ctx *context.Context, orgID int64){
40+
var gwfList []actions_model.GlobalWorkflow
41+
orgRepos, err := org_model.GetOrgRepositories(ctx, orgID)
4442
if err != nil {
45-
ctx.ServerError("ListAvailableWorkflows", err)
43+
ctx.ServerError("GlobalEnableWorkflows get org repos: ", err)
4644
return
4745
}
48-
/*
49-
var global_workflow []string
50-
for _, workflow := range workflow_list {
51-
global_workflow = append(global_workflow, workflow.Data)
46+
for _, repo := range orgRepos {
47+
repo.LoadUnits(ctx)
48+
actionsConfig := repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
49+
enabledWorkflows := actionsConfig.GetGlobalWorkflow()
50+
for _, workflow := range enabledWorkflows {
51+
gwf := actions_model.GlobalWorkflow{
52+
RepoName: repo.Name,
53+
Filename: workflow,
54+
}
55+
gwfList = append(gwfList, gwf)
56+
}
5257
}
53-
ctx.Data["ListAvailableWorkflows"] = global_workflow */
54-
ctx.Data["ListAvailableWorkflows"] = workflow_list
55-
}
56-
57-
// SetRequireActionDeletePost response for deleting a require action workflow
58-
func SetRequireActionsContext(ctx *context.Context) {
58+
ctx.Data["GlobalEnableWorkflows"] = gwfList
5959
}

routers/web/web.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ func registerRoutes(m *web.Route) {
635635

636636
m.Group("/actions", func() {
637637
m.Get("", user_setting.RedirectToDefaultSetting)
638+
addSettingsRequireActionsRoutes()
638639
addSettingsRunnersRoutes()
639640
addSettingsSecretsRoutes()
640641
addSettingsVariablesRoutes()
@@ -932,7 +933,7 @@ func registerRoutes(m *web.Route) {
932933

933934
m.Group("/actions", func() {
934935
m.Get("", org_setting.RedirectToDefaultSetting)
935-
addSettingsRequireActionsRoutes()
936+
addSettingsRequireActionsRoutes()
936937
addSettingsRunnersRoutes()
937938
addSettingsSecretsRoutes()
938939
addSettingsVariablesRoutes()

templates/org/settings/actions.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{{template "org/settings/layout_head" (dict "ctxData" . "pageClass" "organization settings actions")}}
22
<div class="org-setting-content">
3-
{{if eq .PageType "runners"}}
3+
{{if eq .PageType "require_actions"}}
4+
{{template "shared/actions/require_action_list" .}}
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/org/settings/navbar.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<details class="item toggleable-item" {{if or .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables}}open{{end}}>
3030
<summary>{{ctx.Locale.Tr "actions.actions"}}</summary>
3131
<div class="menu">
32+
<a class="{{if .PageIsSharedSettingsRequireActions}}active {{end}}item" href="{{.OrgLink}}/settings/actions/require_actions">
33+
{{ctx.Locale.Tr "actions.require_actions"}}
34+
</a>
3235
<a class="{{if .PageIsSharedSettingsRunners}}active {{end}}item" href="{{.OrgLink}}/settings/actions/runners">
3336
{{ctx.Locale.Tr "actions.runners"}}
3437
</a>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<div class="require-actions-container">
2+
<h4 class="ui top attached header">
3+
{{ctx.Locale.Tr "actions.require_actions.require_actions_manage_panel"}} ({{ctx.Locale.Tr "admin.total" .Total}})
4+
<div class="ui right">
5+
<div class="ui top right">
6+
<button class="ui primary tiny button show-modal"
7+
data-modal="#add-require-actions-modal"
8+
data-modal-form.action="{{.Link}}"
9+
data-modal-header="{{ctx.Locale.Tr "actions.require_actions.add"}}"
10+
>
11+
{{ctx.Locale.Tr "actions.require_actions.add"}}
12+
</button>
13+
</div>
14+
15+
</div>
16+
</h4>
17+
<div class="ui attached segment">
18+
<form class="ui form ignore-dirty" id="require-action-list-search-form" action="{{$.Link}}">
19+
<!-- Search Text -->
20+
<div class="ui fluid action input">
21+
{{template "shared/search/combo" dict "Value" .Keyword}}
22+
<button class="ui primary button">{{ctx.Locale.Tr "explore.search"}}</button>
23+
</div>
24+
</form>
25+
</div>
26+
<div class="ui attached table segment">
27+
<table class="ui very basic striped table unstackable">
28+
<thead>
29+
<tr>
30+
<th data-sortt-asc="online" data-sortt-desc="offline">
31+
{{ctx.Locale.Tr "actions.require_actions.status"}}
32+
</th>
33+
<th data-sortt-asc="newest" data-sortt-desc="oldest">
34+
{{ctx.Locale.Tr "actions.require_actions.id"}}
35+
</th>
36+
<th data-sortt-asc="alphabetically" data-sortt-desc="reversealphabetically">
37+
{{ctx.Locale.Tr "actions.require_actions.name"}}
38+
</th>
39+
<th>{{ctx.Locale.Tr "actions.require_actions.version"}}</th>
40+
<th>{{ctx.Locale.Tr "actions.require_actions.repo"}}</th>
41+
<th>{{ctx.Locale.Tr "actions.require_actions.link"}}</th>
42+
<th>{{ctx.Locale.Tr "edit"}}</th>
43+
</tr>
44+
</thead>
45+
<tbody>
46+
{{if .RequireActionList}}
47+
{{range .RequireActionList}}
48+
<tr>
49+
<td>
50+
<span class="ui {{if .IsOnline}}green{{else}}basic{{end}} label">{{.StatusLocaleName ctx.Locale}}</span>
51+
</td>
52+
<td>{{.ID}}</td>
53+
<td><p data-tooltip-content="{{.Description}}">{{.Name}}</p></td>
54+
<td>{{if .Version}}{{.Version}}{{else}}{{ctx.Locale.Tr "unknown"}}{{end}}</td>
55+
<td><span data-tooltip-content="{{.BelongsToOwnerName}}">{{.BelongsToOwnerType.LocaleString ctx.Locale}}</span></td>
56+
<td class="require_action-tags">
57+
{{range .AgentLabels}}<span class="ui label">{{.}}</span>{{end}}
58+
</td>
59+
<td>{{if .LastOnline}}{{TimeSinceUnix .LastOnline ctx.Locale}}{{else}}{{ctx.Locale.Tr "never"}}{{end}}</td>
60+
<td class="require_action-ops">
61+
{{if .Editable $.RequireActionOwnerID $.RequireApoID}}
62+
<a href="{{$.Link}}/{{.ID}}">{{svg "octicon-pencil"}}</a>
63+
{{end}}"
64+
</td>
65+
</tr>
66+
{{end}}
67+
{{else}}
68+
<tr>
69+
<td class="center aligned" colspan="8">{{ctx.Locale.Tr "actions.require_actions.none"}}</td>
70+
</tr>
71+
{{end}}
72+
</tbody>
73+
</table>
74+
</div>
75+
{{template "base/paginate" .}}
76+
</div>
77+
78+
79+
80+
{{/* Add RequireAction dialog */}}
81+
<div class="ui small modal" id="add-require-actions-modal">
82+
<div class="header">
83+
<span id="actions-modal-header">Availble Enable Workflows</span>
84+
</div>
85+
<form class="ui form form-fetch-action" method="post">
86+
<div class="content">
87+
<div class="item">
88+
<a href="https://docs.gitea.com/usage/actions/require-action">{{ctx.Locale.Tr "actions.require_actions.enable_global_workflow"}}</a>
89+
</div>
90+
<div class="divider"></div>
91+
<!-- <div class="ui input"> -->
92+
<table class="ui very basic striped table unstackable">
93+
<thead>
94+
<tr>
95+
<th data-sortt-asc="alphabetically" data-sortt-desc="reversealphabetically">
96+
{{ctx.Locale.Tr "actions.require_actions.workflow"}}
97+
</th>
98+
<th>
99+
{{ctx.Locale.Tr "actions.require_actions.repo"}}
100+
</th>
101+
</tr>
102+
</thead>
103+
<tbody>
104+
{{if .GlobalEnableWorkflows}}
105+
{{range .GlobalEnableWorkflows}}
106+
<tr>
107+
<td><div class="field">
108+
<div class="ui radio checkbox">
109+
<input class="select-org-radio" name="enable_global_workflow" type="radio" value="{{.Filename}}">
110+
<label>{{.Filename}}</label>
111+
</div>
112+
</div></td>
113+
<td><div class="field">
114+
<input class="" name="RepoID" type="hidden" value="{{.RepoName}}">
115+
<a href="/{{$.OrgName}}/{{.RepoName}}">
116+
<label>{{.RepoName}}</label>
117+
</a>
118+
</div></td>
119+
</tr>
120+
{{ end }}
121+
{{else}}
122+
<tr>
123+
<td class="center aligned" colspan="8">{{ctx.Locale.Tr "actions.require_actions.none"}}</td>
124+
</tr>
125+
{{ end }}
126+
</tbody>
127+
</table>
128+
<div class="divider"></div>
129+
<div class="item">
130+
<a href="{{$.Link}}/add">{{ctx.Locale.Tr "actions.require_actions.add_require_actions"}}</a>
131+
</div>
132+
</div>
133+
{{template "base/modal_actions_confirm" (dict "ModalButtonTypes" "confirm")}}
134+
</form>
135+
</div>

0 commit comments

Comments
 (0)