Skip to content

Commit 1fc9989

Browse files
committed
Fix all the format of the commit
Signed-off-by: Alex Lau(AvengerMoJo) <[email protected]>
1 parent 5243490 commit 1fc9989

File tree

12 files changed

+227
-232
lines changed

12 files changed

+227
-232
lines changed

models/actions/require_action.go

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

88
import (
9-
"context"
9+
"context"
1010

11-
"code.gitea.io/gitea/models/db"
12-
//"code.gitea.io/gitea/models/unit"
13-
"code.gitea.io/gitea/modules/timeutil"
11+
"code.gitea.io/gitea/models/db"
12+
//"code.gitea.io/gitea/models/unit"
13+
"code.gitea.io/gitea/modules/timeutil"
1414

15-
"xorm.io/builder"
15+
"xorm.io/builder"
1616
)
1717

1818
type RequireAction struct {
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
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
2727
}
2828

2929
type GlobalWorkflow struct {
30-
RepoName string
31-
Filename string
30+
RepoName string
31+
Filename string
3232
}
3333

3434
func init() {
35-
db.RegisterModel(new(RequireAction))
35+
db.RegisterModel(new(RequireAction))
3636
}
3737

3838
type FindRequireActionOptions struct {
39-
db.ListOptions
40-
RequireActionID int64
41-
OrgID int64
42-
RepoName string
39+
db.ListOptions
40+
RequireActionID int64
41+
OrgID int64
42+
RepoName string
4343
}
4444

4545
func (opts FindRequireActionOptions) ToConds() builder.Cond {
46-
cond := builder.NewCond()
47-
if opts.OrgID > 0 {
48-
cond = cond.And(builder.Eq{"org_id": opts.OrgID})
49-
}
50-
if opts.RequireActionID > 0 {
51-
cond = cond.And(builder.Eq{"id": opts.RequireActionID})
52-
}
53-
if opts.RepoName != "" {
54-
cond = cond.And(builder.Eq{"repo_name": opts.RepoName})
55-
}
56-
return cond
46+
cond := builder.NewCond()
47+
if opts.OrgID > 0 {
48+
cond = cond.And(builder.Eq{"org_id": opts.OrgID})
49+
}
50+
if opts.RequireActionID > 0 {
51+
cond = cond.And(builder.Eq{"id": opts.RequireActionID})
52+
}
53+
if opts.RepoName != "" {
54+
cond = cond.And(builder.Eq{"repo_name": opts.RepoName})
55+
}
56+
return cond
5757
}
5858

5959
// LoadAttributes loads the attributes of the require action
6060
func (r *RequireAction) LoadAttributes(ctx context.Context) error {
61-
// place holder for now.
62-
return nil
61+
// place holder for now.
62+
return nil
6363
}
6464

6565
// if the workflow is removable
6666
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
67+
// everyone can remove for now
68+
return r.OrgID == orgID
7269
}
7370

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)
71+
func AddRequireAction(ctx context.Context, orgID int64, repoName, workflowName string) (*RequireAction, error) {
72+
ra := &RequireAction{
73+
OrgID: orgID,
74+
RepoName: repoName,
75+
WorkflowName: workflowName,
76+
}
77+
return ra, db.Insert(ctx, ra)
8278
}

models/migrations/v1_23/v295.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
)
1010

1111
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-
}
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+
}
2020
return x.Sync(new(RequireAction))
2121
}

models/repo/repo_unit.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,28 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
167167
}
168168

169169
type ActionsConfig struct {
170-
DisabledWorkflows []string
171-
EnabledGlobalWorkflows []string
170+
DisabledWorkflows []string
171+
EnabledGlobalWorkflows []string
172172
}
173173

174174
func (cfg *ActionsConfig) EnableWorkflow(file string) {
175175
cfg.DisabledWorkflows = util.SliceRemoveAll(cfg.DisabledWorkflows, file)
176-
}
176+
}
177177

178178
func (cfg *ActionsConfig) DisableGlobalWorkflow(file string) {
179-
cfg.EnabledGlobalWorkflows = util.SliceRemoveAll(cfg.EnabledGlobalWorkflows, file)
179+
cfg.EnabledGlobalWorkflows = util.SliceRemoveAll(cfg.EnabledGlobalWorkflows, file)
180180
}
181181

182182
func (cfg *ActionsConfig) IsGlobalWorkflowEnabled(file string) bool {
183-
return slices.Contains(cfg.EnabledGlobalWorkflows, file)
183+
return slices.Contains(cfg.EnabledGlobalWorkflows, file)
184184
}
185185

186186
func (cfg *ActionsConfig) EnableGlobalWorkflow(file string) {
187-
cfg.EnabledGlobalWorkflows = append(cfg.EnabledGlobalWorkflows, file)
187+
cfg.EnabledGlobalWorkflows = append(cfg.EnabledGlobalWorkflows, file)
188188
}
189189

190190
func (cfg *ActionsConfig) GetGlobalWorkflow() []string {
191-
return cfg.EnabledGlobalWorkflows
191+
return cfg.EnabledGlobalWorkflows
192192
}
193193

194194
func (cfg *ActionsConfig) ToString() string {

routers/web/org/setting/require_action.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
package setting
77

88
import (
9-
"code.gitea.io/gitea/services/context"
9+
"code.gitea.io/gitea/services/context"
1010
)
1111

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

routers/web/repo/actions/actions.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func List(ctx *context.Context) {
145145
workflow := ctx.FormString("workflow")
146146
actorID := ctx.FormInt64("actor")
147147
status := ctx.FormInt("status")
148-
isGlobal := false
148+
isGlobal := false
149149
ctx.Data["CurWorkflow"] = workflow
150150

151151
actionsConfig := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
@@ -154,8 +154,8 @@ func List(ctx *context.Context) {
154154
if len(workflow) > 0 && ctx.Repo.IsAdmin() {
155155
ctx.Data["AllowDisableOrEnableWorkflow"] = true
156156
ctx.Data["CurWorkflowDisabled"] = actionsConfig.IsWorkflowDisabled(workflow)
157-
ctx.Data["CurGlobalWorkflowEnable"] = actionsConfig.IsGlobalWorkflowEnabled(workflow)
158-
isGlobal = actionsConfig.IsGlobalWorkflowEnabled(workflow)
157+
ctx.Data["CurGlobalWorkflowEnable"] = actionsConfig.IsGlobalWorkflowEnabled(workflow)
158+
isGlobal = actionsConfig.IsGlobalWorkflowEnabled(workflow)
159159
}
160160

161161
// if status or actor query param is not given to frontend href, (href="/<repoLink>/actions")
@@ -212,9 +212,9 @@ func List(ctx *context.Context) {
212212
pager.AddParamString("workflow", workflow)
213213
pager.AddParamString("actor", fmt.Sprint(actorID))
214214
pager.AddParamString("status", fmt.Sprint(status))
215-
if isGlobal {
216-
pager.AddParamString("global", fmt.Sprint(isGlobal))
217-
}
215+
if isGlobal {
216+
pager.AddParamString("global", fmt.Sprint(isGlobal))
217+
}
218218
ctx.Data["Page"] = pager
219219
ctx.Data["HasWorkflowsOrRuns"] = len(workflows) > 0 || len(runs) > 0
220220

routers/web/repo/actions/view.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -716,36 +716,36 @@ func disableOrEnableWorkflowFile(ctx *context_module.Context, isEnable bool) {
716716
}
717717

718718
func DisableGlobalWorkflowFile(ctx *context_module.Context) {
719-
disableOrEnableGlobalWorkflowFile(ctx, true)
719+
disableOrEnableGlobalWorkflowFile(ctx, true)
720720
}
721721

722722
func EnableGlobalWorkflowFile(ctx *context_module.Context) {
723-
disableOrEnableGlobalWorkflowFile(ctx, false)
723+
disableOrEnableGlobalWorkflowFile(ctx, false)
724724
}
725725

726726
func disableOrEnableGlobalWorkflowFile(ctx *context_module.Context, isGlobalEnable bool) {
727-
workflow := ctx.FormString("workflow")
728-
if len(workflow) == 0 {
729-
ctx.ServerError("workflow", nil)
730-
return
731-
}
732-
cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
733-
cfg := cfgUnit.ActionsConfig()
734-
if isGlobalEnable {
735-
cfg.DisableGlobalWorkflow(workflow)
736-
} else {
737-
cfg.EnableGlobalWorkflow(workflow)
738-
}
739-
if err := repo_model.UpdateRepoUnit(ctx, cfgUnit); err != nil {
740-
ctx.ServerError("UpdateRepoUnit", err)
741-
return
742-
}
743-
if isGlobalEnable {
744-
ctx.Flash.Success(ctx.Tr("actions.workflow.global_disable_success", workflow))
745-
} else {
746-
ctx.Flash.Success(ctx.Tr("actions.workflow.global_enable_success", workflow))
747-
}
748-
redirectURL := fmt.Sprintf("%s/actions?workflow=%s&actor=%s&status=%s", ctx.Repo.RepoLink, url.QueryEscape(workflow),
749-
url.QueryEscape(ctx.FormString("actor")), url.QueryEscape(ctx.FormString("status")))
750-
ctx.JSONRedirect(redirectURL)
727+
workflow := ctx.FormString("workflow")
728+
if len(workflow) == 0 {
729+
ctx.ServerError("workflow", nil)
730+
return
731+
}
732+
cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
733+
cfg := cfgUnit.ActionsConfig()
734+
if isGlobalEnable {
735+
cfg.DisableGlobalWorkflow(workflow)
736+
} else {
737+
cfg.EnableGlobalWorkflow(workflow)
738+
}
739+
if err := repo_model.UpdateRepoUnit(ctx, cfgUnit); err != nil {
740+
ctx.ServerError("UpdateRepoUnit", err)
741+
return
742+
}
743+
if isGlobalEnable {
744+
ctx.Flash.Success(ctx.Tr("actions.workflow.global_disable_success", workflow))
745+
} else {
746+
ctx.Flash.Success(ctx.Tr("actions.workflow.global_enable_success", workflow))
747+
}
748+
redirectURL := fmt.Sprintf("%s/actions?workflow=%s&actor=%s&status=%s", ctx.Repo.RepoLink, url.QueryEscape(workflow),
749+
url.QueryEscape(ctx.FormString("actor")), url.QueryEscape(ctx.FormString("status")))
750+
ctx.JSONRedirect(redirectURL)
751751
}

0 commit comments

Comments
 (0)