Skip to content

Commit cf17ea8

Browse files
silverwindAvengerMoJo
authored andcommitted
Add gap to commit status details (go-gitea#30284)
Before: <img width="162" alt="Screenshot 2024-04-05 at 02 25 27" src="https://github.com/go-gitea/gitea/assets/115237/9f786811-3e45-4b3c-aaf9-e1d2cad284d2"> After: <img width="172" alt="Screenshot 2024-04-05 at 02 27 25" src="https://github.com/go-gitea/gitea/assets/115237/f5254877-9e0d-44cb-9605-ba15c75872bb"> Rename everything correctly so the binding work Signed-off-by: Alex Lau(AvengerMoJo) <[email protected]> Adding migration for the database Signed-off-by: Alex Lau(AvengerMoJo) <[email protected]>
1 parent ed6dbd3 commit cf17ea8

File tree

13 files changed

+192
-91
lines changed

13 files changed

+192
-91
lines changed

models/actions/require_action.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ package actions
77

88
import (
99
"context"
10-
//"errors"
11-
//"fmt"
12-
13-
// org_model "code.gitea.io/gitea/models/organization"
14-
// repo_model "code.gitea.io/gitea/models/repo"
1510

1611
"code.gitea.io/gitea/models/db"
1712
//"code.gitea.io/gitea/models/unit"
@@ -21,14 +16,14 @@ import (
2116
)
2217

2318
type RequireAction struct {
24-
ID int64 `xorm:"pk autoincr"`
25-
OrgID int64 `xorm:"index"`
26-
RepoID int64 `xorm:"index"`
27-
Name string `xorm:"UNIQUE(owner_repo_name) NOT NULL"`
28-
Description string `xorm:"LONGTEXT NOT NULL"`
29-
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
30-
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
31-
RepoRange string // glob match which repositories could use this runner
19+
ID int64 `xorm:"pk autoincr"`
20+
OrgID int64 `xorm:"index"`
21+
RepoName string `xorm:"VARCHAR(255)"`
22+
WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"`
23+
//Description string `xorm:"LONGTEXT NOT NULL"`
24+
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
25+
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
26+
// RepoRange string // glob match which repositories could use this runner
3227
}
3328

3429
type GlobalWorkflow struct {
@@ -44,6 +39,7 @@ type FindRequireActionOptions struct {
4439
db.ListOptions
4540
RequireActionID int64
4641
OrgID int64
42+
RepoName string
4743
}
4844

4945
func (opts FindRequireActionOptions) ToConds() builder.Cond {
@@ -54,6 +50,9 @@ func (opts FindRequireActionOptions) ToConds() builder.Cond {
5450
if opts.RequireActionID > 0 {
5551
cond = cond.And(builder.Eq{"id": opts.RequireActionID})
5652
}
53+
if opts.RepoName != "" {
54+
cond = cond.And(builder.Eq{"repo_name": opts.RepoName})
55+
}
5756
return cond
5857
}
5958

@@ -63,3 +62,21 @@ func (r *RequireAction) LoadAttributes(ctx context.Context) error {
6362
return nil
6463
}
6564

65+
// if the workflow is removable
66+
func (r *RequireAction) Removable(orgID int64) bool {
67+
// everyone can remove for now
68+
if r.OrgID == orgID {
69+
return true
70+
}
71+
return false
72+
}
73+
74+
75+
func AddRequireAction(ctx context.Context, orgID int64, repoName string, workflowName string) (*RequireAction, error) {
76+
ra := &RequireAction{
77+
OrgID: orgID,
78+
RepoName: repoName,
79+
WorkflowName: workflowName,
80+
}
81+
return ra, db.Insert(ctx, ra)
82+
}

models/migrations/migrations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,10 @@ var migrations = []Migration{
576576

577577
// Gitea 1.22.0 ends at 294
578578

579+
// v294 -> v295
579580
NewMigration("Add unique index for project issue table", v1_23.AddUniqueIndexForProjectIssue),
581+
// v295 -> v296
582+
NewMigration("Add RequireAction Global Workflow", v1_23.AddRequireActionTable),
580583
}
581584

582585
// GetCurrentDBVersion returns the current db version

models/migrations/v1_23/v295.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
"xorm.io/xorm"
9+
)
10+
11+
func AddRequireActionTable(x *xorm.Engine) error {
12+
type RequireAction struct {
13+
ID int64 `xorm:"pk autoincr"`
14+
OrgID int64 `xorm:"index"`
15+
RepoName string `xorm:"VARCHAR(255)"`
16+
WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"`
17+
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
18+
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
19+
}
20+
return x.Sync(new(RequireAction))
21+
}

options/locale/locale_en-US.ini

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,20 +3640,22 @@ runs.no_workflows.documentation = For more information on Gitea Actions, see <a
36403640
runs.no_runs = The workflow has no runs yet.
36413641
runs.empty_commit_message = (empty commit message)
36423642
3643-
require_actions = Require Actions
3644-
require_actions.require_actions_manage_panel = Require Actions Management Panel
3645-
require_actions.enable_global_workflow = How to Enable Global Workflow
3646-
require_actions.id = ID
3647-
require_actions.name = Name
3648-
require_actions.add = Add Global Workflow
3649-
require_actions.add_require_actions = Enable selected Workflow
3650-
require_actions.new = Create New
3651-
require_actions.status = Status
3652-
require_actions.version = Version
3653-
require_actions.repo = Repo
3654-
require_actions.workflow = Workflow Filename
3655-
require_actions.link = Link
3656-
require_actions.none = No Require Actions Available
3643+
require_action = Require Actions
3644+
require_action.require_action_manage_panel = Require Actions Management Panel
3645+
require_action.enable_global_workflow = How to Enable Global Workflow
3646+
require_action.id = ID
3647+
require_action.add = Add Global Workflow
3648+
require_action.add_require_action = Enable selected Workflow
3649+
require_action.new = Create New
3650+
require_action.status = Status
3651+
require_action.version = Version
3652+
require_action.repo = Repo Name
3653+
require_action.workflow = Workflow Filename
3654+
require_action.link = Link
3655+
require_action.remove = Remove
3656+
require_action.none = No Require Actions Available.
3657+
require_action.creation.failed = Create Global Require Action %s Failed.
3658+
require_action.creation.success = Create Global Require Action %s successfully.
36573659
36583660
workflow.disable = Disable Workflow
36593661
workflow.disable_success = Workflow '%s' disabled successfully.

routers/web/org/setting/require_actions.go renamed to routers/web/org/setting/require_action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ import (
1010
)
1111

1212
func RedirectToRepoSetting(ctx *context.Context) {
13-
ctx.Redirect(ctx.Org.OrgLink + "/settings/actions/require_actions")
13+
ctx.Redirect(ctx.Org.OrgLink + "/settings/actions/require_action")
1414
}

routers/web/repo/setting/require_actions.go renamed to routers/web/repo/setting/require_action.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,37 @@ import (
2222

2323
const (
2424
// let start with org WIP
25-
tplOrgRequireActions base.TplName = "org/settings/actions"
25+
tplOrgRequireAction base.TplName = "org/settings/actions"
2626
)
2727

2828
type requireActionsCtx struct {
2929
OrgID int64
3030
IsOrg bool
31-
RequireActionsTemplate base.TplName
31+
RequireActionTemplate base.TplName
3232
RedirectLink string
3333
}
3434

35-
func getRequireActionsCtx(ctx *context.Context) (*requireActionsCtx, error) {
35+
func getRequireActionCtx(ctx *context.Context) (*requireActionsCtx, error) {
3636
if ctx.Data["PageIsOrgSettings"] == true {
3737
return &requireActionsCtx{
3838
OrgID: ctx.Org.Organization.ID,
3939
IsOrg: true,
40-
RequireActionsTemplate: tplOrgRequireActions,
40+
RequireActionTemplate: tplOrgRequireAction,
4141
RedirectLink: ctx.Org.OrgLink + "/settings/actions/require_action",
4242
}, nil
4343
}
4444
return nil, errors.New("unable to set Require Actions context")
4545
}
4646

47-
// Listing all RequireActions
48-
func RequireActions(ctx *context.Context) {
47+
// Listing all RequireAction
48+
func RequireAction(ctx *context.Context) {
4949
ctx.Data["ActionsTitle"] = ctx.Tr("actions.requires")
50-
ctx.Data["PageType"] = "require_actions"
51-
ctx.Data["PageIsSharedSettingsRequireActions"] = true
50+
ctx.Data["PageType"] = "require_action"
51+
ctx.Data["PageIsSharedSettingsRequireAction"] = true
5252

53-
vCtx, err := getRequireActionsCtx(ctx)
53+
vCtx, err := getRequireActionCtx(ctx)
5454
if err != nil {
55-
ctx.ServerError("getRequireActionsCtx", err)
55+
ctx.ServerError("getRequireActionCtx", err)
5656
return
5757
}
5858

@@ -64,8 +64,17 @@ func RequireActions(ctx *context.Context) {
6464
PageSize: 10,
6565
},
6666
}
67-
shared.SetRequireActionsContext(ctx, opts)
67+
shared.SetRequireActionContext(ctx, opts)
6868
ctx.Data["Link"] = vCtx.RedirectLink
6969
shared.GlobalEnableWorkflow(ctx, ctx.Org.Organization.ID)
70-
ctx.HTML(http.StatusOK, vCtx.RequireActionsTemplate)
70+
ctx.HTML(http.StatusOK, vCtx.RequireActionTemplate)
71+
}
72+
73+
func RequireActionCreate(ctx *context.Context) {
74+
vCtx, err := getRequireActionCtx(ctx)
75+
if err != nil {
76+
ctx.ServerError("getRequireActionCtx", err)
77+
return
78+
}
79+
shared.CreateRequireAction(ctx, vCtx.OrgID, vCtx.RedirectLink)
7180
}

routers/web/shared/actions/require_action.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import (
1010
actions_model "code.gitea.io/gitea/models/actions"
1111
org_model "code.gitea.io/gitea/models/organization"
1212
"code.gitea.io/gitea/models/db"
13-
//"code.gitea.io/gitea/modules/log"
13+
"code.gitea.io/gitea/modules/log"
1414
//"code.gitea.io/gitea/modules/util"
1515
"code.gitea.io/gitea/models/unit"
16-
//"code.gitea.io/gitea/modules/web"
17-
//"code.gitea.io/gitea/services/forms"
18-
// action_service "code.gitea.io/gitea/services/actions"
16+
"code.gitea.io/gitea/modules/web"
17+
"code.gitea.io/gitea/services/forms"
18+
actions_service "code.gitea.io/gitea/services/actions"
1919

2020
"code.gitea.io/gitea/services/context"
2121
)
2222

2323
// SetRequireActionDeletePost response for deleting a require action workflow
24-
func SetRequireActionsContext(ctx *context.Context, opts actions_model.FindRequireActionOptions) {
24+
func SetRequireActionContext(ctx *context.Context, opts actions_model.FindRequireActionOptions) {
2525
require_actions, count, err := db.FindAndCount[actions_model.RequireAction](ctx, opts)
2626
if err != nil {
27-
ctx.ServerError("CountRequireAction", err)
27+
ctx.ServerError("CountRequireActions", err)
2828
return
2929
}
3030
ctx.Data["RequireActions"] = require_actions
@@ -57,3 +57,18 @@ func GlobalEnableWorkflow(ctx *context.Context, orgID int64){
5757
}
5858
ctx.Data["GlobalEnableWorkflows"] = gwfList
5959
}
60+
61+
func CreateRequireAction(ctx *context.Context, orgID int64, redirectURL string){
62+
ctx.Data["OrgID"] = ctx.Org.Organization.ID
63+
form := web.GetForm(ctx).(*forms.RequireActionForm)
64+
// log.Error("org %d, repo_name: %s, workflow_name %s", orgID, form.RepoName, form.WorkflowName)
65+
log.Error("org %d, repo_name: %+v", orgID, form)
66+
v, err := actions_service.CreateRequireAction(ctx, orgID, form.RepoName, form.WorkflowName)
67+
if err != nil {
68+
log.Error("CreateRequireAction: %v", err)
69+
ctx.JSONError(ctx.Tr("actions.require_action.creation.failed"))
70+
return
71+
}
72+
ctx.Flash.Success(ctx.Tr("actions.require_action.creation.success", v.WorkflowName))
73+
ctx.JSONRedirect(redirectURL)
74+
}

routers/web/web.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,10 @@ func registerRoutes(m *web.Route) {
459459
}
460460

461461
// WIP RequireAction
462-
addSettingsRequireActionsRoutes := func() {
463-
m.Group("/require_actions", func() {
464-
m.Get("", repo_setting.RequireActions)
462+
addSettingsRequireActionRoutes := func() {
463+
m.Group("/require_action", func() {
464+
m.Get("", repo_setting.RequireAction)
465+
m.Post("/add", web.Bind(forms.RequireActionForm{}), repo_setting.RequireActionCreate)
465466
})
466467
}
467468

@@ -635,7 +636,7 @@ func registerRoutes(m *web.Route) {
635636

636637
m.Group("/actions", func() {
637638
m.Get("", user_setting.RedirectToDefaultSetting)
638-
addSettingsRequireActionsRoutes()
639+
addSettingsRequireActionRoutes()
639640
addSettingsRunnersRoutes()
640641
addSettingsSecretsRoutes()
641642
addSettingsVariablesRoutes()
@@ -933,7 +934,7 @@ func registerRoutes(m *web.Route) {
933934

934935
m.Group("/actions", func() {
935936
m.Get("", org_setting.RedirectToDefaultSetting)
936-
addSettingsRequireActionsRoutes()
937+
addSettingsRequireActionRoutes()
937938
addSettingsRunnersRoutes()
938939
addSettingsSecretsRoutes()
939940
addSettingsVariablesRoutes()

services/actions/require_action.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package actions
5+
6+
import (
7+
"context"
8+
9+
actions_model "code.gitea.io/gitea/models/actions"
10+
)
11+
12+
func CreateRequireAction(ctx context.Context, orgID int64, repoName string, workflowName string) (*actions_model.RequireAction, error) {
13+
v, err := actions_model.AddRequireAction(ctx, orgID, repoName, workflowName)
14+
if err != nil {
15+
return nil, err
16+
}
17+
return v, nil
18+
}

services/forms/user_form.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,13 @@ func (f *EditVariableForm) Validate(req *http.Request, errs binding.Errors) bind
359359
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
360360
}
361361

362+
//WIP RequireAction create form
363+
364+
type RequireActionForm struct {
365+
RepoName string `binding:"Required;MaxSize(255)"`
366+
WorkflowName string `binding:"Required;MaxSize(255)"`
367+
}
368+
362369
// NewAccessTokenForm form for creating access token
363370
type NewAccessTokenForm struct {
364371
Name string `binding:"Required;MaxSize(255)" locale:"settings.token_name"`

templates/org/settings/actions.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{template "org/settings/layout_head" (dict "ctxData" . "pageClass" "organization settings actions")}}
22
<div class="org-setting-content">
3-
{{if eq .PageType "require_actions"}}
3+
{{if eq .PageType "require_action"}}
44
{{template "shared/actions/require_action_list" .}}
55
{{else if eq .PageType "runners"}}
66
{{template "shared/actions/runner_list" .}}

templates/org/settings/navbar.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
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"}}
32+
<a class="{{if .PageIsSharedSettingsRequireAction}}active {{end}}item" href="{{.OrgLink}}/settings/actions/require_action">
33+
{{ctx.Locale.Tr "actions.require_action"}}
3434
</a>
3535
<a class="{{if .PageIsSharedSettingsRunners}}active {{end}}item" href="{{.OrgLink}}/settings/actions/runners">
3636
{{ctx.Locale.Tr "actions.runners"}}

0 commit comments

Comments
 (0)