From 3e2eca23c962f68aa100c2e4ffb39de260c71875 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 5 Apr 2024 13:11:26 +0200 Subject: [PATCH] Add gap to commit status details (#30284) Before: Screenshot 2024-04-05 at 02 25 27 After: Screenshot 2024-04-05 at 02 27 25 Rename everything correctly so the binding work Signed-off-by: Alex Lau(AvengerMoJo) Adding migration for the database Signed-off-by: Alex Lau(AvengerMoJo) --- models/actions/require_action.go | 43 +++++++--- models/migrations/migrations.go | 3 + models/migrations/v1_23/v295.go | 21 +++++ options/locale/locale_en-US.ini | 30 +++---- .../{require_actions.go => require_action.go} | 2 +- .../{require_actions.go => require_action.go} | 33 +++++--- routers/web/shared/actions/require_action.go | 27 ++++-- routers/web/web.go | 11 +-- services/actions/require_action.go | 18 ++++ services/forms/user_form.go | 7 ++ templates/org/settings/actions.tmpl | 2 +- templates/org/settings/navbar.tmpl | 4 +- .../shared/actions/require_action_list.tmpl | 82 ++++++++++--------- 13 files changed, 192 insertions(+), 91 deletions(-) create mode 100644 models/migrations/v1_23/v295.go rename routers/web/org/setting/{require_actions.go => require_action.go} (97%) rename routers/web/repo/setting/{require_actions.go => require_action.go} (62%) create mode 100644 services/actions/require_action.go diff --git a/models/actions/require_action.go b/models/actions/require_action.go index 02a67fffcf33f..990bd2a6ed012 100644 --- a/models/actions/require_action.go +++ b/models/actions/require_action.go @@ -7,11 +7,6 @@ package actions import ( "context" - //"errors" - //"fmt" - - // org_model "code.gitea.io/gitea/models/organization" - // repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/db" //"code.gitea.io/gitea/models/unit" @@ -21,14 +16,14 @@ import ( ) type RequireAction struct { - ID int64 `xorm:"pk autoincr"` - OrgID int64 `xorm:"index"` - RepoID int64 `xorm:"index"` - Name string `xorm:"UNIQUE(owner_repo_name) NOT NULL"` - Description string `xorm:"LONGTEXT NOT NULL"` - CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` - UpdatedUnix timeutil.TimeStamp `xorm:"updated"` - RepoRange string // glob match which repositories could use this runner + ID int64 `xorm:"pk autoincr"` + OrgID int64 `xorm:"index"` + RepoName string `xorm:"VARCHAR(255)"` + WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"` + //Description string `xorm:"LONGTEXT NOT NULL"` + CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` + UpdatedUnix timeutil.TimeStamp `xorm:"updated"` + // RepoRange string // glob match which repositories could use this runner } type GlobalWorkflow struct { @@ -44,6 +39,7 @@ type FindRequireActionOptions struct { db.ListOptions RequireActionID int64 OrgID int64 + RepoName string } func (opts FindRequireActionOptions) ToConds() builder.Cond { @@ -54,6 +50,9 @@ func (opts FindRequireActionOptions) ToConds() builder.Cond { if opts.RequireActionID > 0 { cond = cond.And(builder.Eq{"id": opts.RequireActionID}) } + if opts.RepoName != "" { + cond = cond.And(builder.Eq{"repo_name": opts.RepoName}) + } return cond } @@ -63,3 +62,21 @@ func (r *RequireAction) LoadAttributes(ctx context.Context) error { return nil } +// if the workflow is removable +func (r *RequireAction) Removable(orgID int64) bool { + // everyone can remove for now + if r.OrgID == orgID { + return true + } + return false +} + + +func AddRequireAction(ctx context.Context, orgID int64, repoName string, workflowName string) (*RequireAction, error) { + ra := &RequireAction{ + OrgID: orgID, + RepoName: repoName, + WorkflowName: workflowName, + } + return ra, db.Insert(ctx, ra) +} diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 387cd96a53471..5462ae960cef6 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -576,7 +576,10 @@ var migrations = []Migration{ // Gitea 1.22.0 ends at 294 + // v294 -> v295 NewMigration("Add unique index for project issue table", v1_23.AddUniqueIndexForProjectIssue), + // v295 -> v296 + NewMigration("Add RequireAction Global Workflow", v1_23.AddRequireActionTable), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_23/v295.go b/models/migrations/v1_23/v295.go new file mode 100644 index 0000000000000..20656bf6dbe79 --- /dev/null +++ b/models/migrations/v1_23/v295.go @@ -0,0 +1,21 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_23 //nolint + +import ( + "code.gitea.io/gitea/modules/timeutil" + "xorm.io/xorm" +) + +func AddRequireActionTable(x *xorm.Engine) error { + type RequireAction struct { + ID int64 `xorm:"pk autoincr"` + OrgID int64 `xorm:"index"` + RepoName string `xorm:"VARCHAR(255)"` + WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"` + CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` + UpdatedUnix timeutil.TimeStamp `xorm:"updated"` + } + return x.Sync(new(RequireAction)) +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index add3f4728f4d8..25587e2590745 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3640,20 +3640,22 @@ runs.no_workflows.documentation = For more information on Gitea Actions, see - {{if eq .PageType "require_actions"}} + {{if eq .PageType "require_action"}} {{template "shared/actions/require_action_list" .}} {{else if eq .PageType "runners"}} {{template "shared/actions/runner_list" .}} diff --git a/templates/org/settings/navbar.tmpl b/templates/org/settings/navbar.tmpl index f8f28864eca70..7ee058dbeeb05 100644 --- a/templates/org/settings/navbar.tmpl +++ b/templates/org/settings/navbar.tmpl @@ -29,8 +29,8 @@
{{ctx.Locale.Tr "actions.actions"}} +