Skip to content

Commit

Permalink
Add gap to commit status details (go-gitea#30284)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
silverwind authored and AvengerMoJo committed Apr 8, 2024
1 parent 345b1d7 commit 3e2eca2
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 91 deletions.
43 changes: 30 additions & 13 deletions models/actions/require_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -44,6 +39,7 @@ type FindRequireActionOptions struct {
db.ListOptions
RequireActionID int64
OrgID int64
RepoName string
}

func (opts FindRequireActionOptions) ToConds() builder.Cond {
Expand All @@ -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
}

Expand All @@ -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)
}
3 changes: 3 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions models/migrations/v1_23/v295.go
Original file line number Diff line number Diff line change
@@ -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))
}
30 changes: 16 additions & 14 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3640,20 +3640,22 @@ runs.no_workflows.documentation = For more information on Gitea Actions, see <a
runs.no_runs = The workflow has no runs yet.
runs.empty_commit_message = (empty commit message)
require_actions = Require Actions
require_actions.require_actions_manage_panel = Require Actions Management Panel
require_actions.enable_global_workflow = How to Enable Global Workflow
require_actions.id = ID
require_actions.name = Name
require_actions.add = Add Global Workflow
require_actions.add_require_actions = Enable selected Workflow
require_actions.new = Create New
require_actions.status = Status
require_actions.version = Version
require_actions.repo = Repo
require_actions.workflow = Workflow Filename
require_actions.link = Link
require_actions.none = No Require Actions Available
require_action = Require Actions
require_action.require_action_manage_panel = Require Actions Management Panel
require_action.enable_global_workflow = How to Enable Global Workflow
require_action.id = ID
require_action.add = Add Global Workflow
require_action.add_require_action = Enable selected Workflow
require_action.new = Create New
require_action.status = Status
require_action.version = Version
require_action.repo = Repo Name
require_action.workflow = Workflow Filename
require_action.link = Link
require_action.remove = Remove
require_action.none = No Require Actions Available.
require_action.creation.failed = Create Global Require Action %s Failed.
require_action.creation.success = Create Global Require Action %s successfully.
workflow.disable = Disable Workflow
workflow.disable_success = Workflow '%s' disabled successfully.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import (
)

func RedirectToRepoSetting(ctx *context.Context) {
ctx.Redirect(ctx.Org.OrgLink + "/settings/actions/require_actions")
ctx.Redirect(ctx.Org.OrgLink + "/settings/actions/require_action")
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,37 @@ import (

const (
// let start with org WIP
tplOrgRequireActions base.TplName = "org/settings/actions"
tplOrgRequireAction base.TplName = "org/settings/actions"
)

type requireActionsCtx struct {
OrgID int64
IsOrg bool
RequireActionsTemplate base.TplName
RequireActionTemplate base.TplName
RedirectLink string
}

func getRequireActionsCtx(ctx *context.Context) (*requireActionsCtx, error) {
func getRequireActionCtx(ctx *context.Context) (*requireActionsCtx, error) {
if ctx.Data["PageIsOrgSettings"] == true {
return &requireActionsCtx{
OrgID: ctx.Org.Organization.ID,
IsOrg: true,
RequireActionsTemplate: tplOrgRequireActions,
RequireActionTemplate: tplOrgRequireAction,
RedirectLink: ctx.Org.OrgLink + "/settings/actions/require_action",
}, nil
}
return nil, errors.New("unable to set Require Actions context")
}

// Listing all RequireActions
func RequireActions(ctx *context.Context) {
// Listing all RequireAction
func RequireAction(ctx *context.Context) {
ctx.Data["ActionsTitle"] = ctx.Tr("actions.requires")
ctx.Data["PageType"] = "require_actions"
ctx.Data["PageIsSharedSettingsRequireActions"] = true
ctx.Data["PageType"] = "require_action"
ctx.Data["PageIsSharedSettingsRequireAction"] = true

vCtx, err := getRequireActionsCtx(ctx)
vCtx, err := getRequireActionCtx(ctx)
if err != nil {
ctx.ServerError("getRequireActionsCtx", err)
ctx.ServerError("getRequireActionCtx", err)
return
}

Expand All @@ -64,8 +64,17 @@ func RequireActions(ctx *context.Context) {
PageSize: 10,
},
}
shared.SetRequireActionsContext(ctx, opts)
shared.SetRequireActionContext(ctx, opts)
ctx.Data["Link"] = vCtx.RedirectLink
shared.GlobalEnableWorkflow(ctx, ctx.Org.Organization.ID)
ctx.HTML(http.StatusOK, vCtx.RequireActionsTemplate)
ctx.HTML(http.StatusOK, vCtx.RequireActionTemplate)
}

func RequireActionCreate(ctx *context.Context) {
vCtx, err := getRequireActionCtx(ctx)
if err != nil {
ctx.ServerError("getRequireActionCtx", err)
return
}
shared.CreateRequireAction(ctx, vCtx.OrgID, vCtx.RedirectLink)
}
27 changes: 21 additions & 6 deletions routers/web/shared/actions/require_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import (
actions_model "code.gitea.io/gitea/models/actions"
org_model "code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/db"
//"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/log"
//"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/models/unit"
//"code.gitea.io/gitea/modules/web"
//"code.gitea.io/gitea/services/forms"
// action_service "code.gitea.io/gitea/services/actions"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
actions_service "code.gitea.io/gitea/services/actions"

"code.gitea.io/gitea/services/context"
)

// SetRequireActionDeletePost response for deleting a require action workflow
func SetRequireActionsContext(ctx *context.Context, opts actions_model.FindRequireActionOptions) {
func SetRequireActionContext(ctx *context.Context, opts actions_model.FindRequireActionOptions) {
require_actions, count, err := db.FindAndCount[actions_model.RequireAction](ctx, opts)
if err != nil {
ctx.ServerError("CountRequireAction", err)
ctx.ServerError("CountRequireActions", err)
return
}
ctx.Data["RequireActions"] = require_actions
Expand Down Expand Up @@ -57,3 +57,18 @@ func GlobalEnableWorkflow(ctx *context.Context, orgID int64){
}
ctx.Data["GlobalEnableWorkflows"] = gwfList
}

func CreateRequireAction(ctx *context.Context, orgID int64, redirectURL string){
ctx.Data["OrgID"] = ctx.Org.Organization.ID
form := web.GetForm(ctx).(*forms.RequireActionForm)
// log.Error("org %d, repo_name: %s, workflow_name %s", orgID, form.RepoName, form.WorkflowName)
log.Error("org %d, repo_name: %+v", orgID, form)
v, err := actions_service.CreateRequireAction(ctx, orgID, form.RepoName, form.WorkflowName)
if err != nil {
log.Error("CreateRequireAction: %v", err)
ctx.JSONError(ctx.Tr("actions.require_action.creation.failed"))
return
}
ctx.Flash.Success(ctx.Tr("actions.require_action.creation.success", v.WorkflowName))
ctx.JSONRedirect(redirectURL)
}
11 changes: 6 additions & 5 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,10 @@ func registerRoutes(m *web.Route) {
}

// WIP RequireAction
addSettingsRequireActionsRoutes := func() {
m.Group("/require_actions", func() {
m.Get("", repo_setting.RequireActions)
addSettingsRequireActionRoutes := func() {
m.Group("/require_action", func() {
m.Get("", repo_setting.RequireAction)
m.Post("/add", web.Bind(forms.RequireActionForm{}), repo_setting.RequireActionCreate)
})
}

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

m.Group("/actions", func() {
m.Get("", user_setting.RedirectToDefaultSetting)
addSettingsRequireActionsRoutes()
addSettingsRequireActionRoutes()
addSettingsRunnersRoutes()
addSettingsSecretsRoutes()
addSettingsVariablesRoutes()
Expand Down Expand Up @@ -933,7 +934,7 @@ func registerRoutes(m *web.Route) {

m.Group("/actions", func() {
m.Get("", org_setting.RedirectToDefaultSetting)
addSettingsRequireActionsRoutes()
addSettingsRequireActionRoutes()
addSettingsRunnersRoutes()
addSettingsSecretsRoutes()
addSettingsVariablesRoutes()
Expand Down
18 changes: 18 additions & 0 deletions services/actions/require_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package actions

import (
"context"

actions_model "code.gitea.io/gitea/models/actions"
)

func CreateRequireAction(ctx context.Context, orgID int64, repoName string, workflowName string) (*actions_model.RequireAction, error) {
v, err := actions_model.AddRequireAction(ctx, orgID, repoName, workflowName)
if err != nil {
return nil, err
}
return v, nil
}
7 changes: 7 additions & 0 deletions services/forms/user_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ func (f *EditVariableForm) Validate(req *http.Request, errs binding.Errors) bind
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}

//WIP RequireAction create form

type RequireActionForm struct {
RepoName string `binding:"Required;MaxSize(255)"`
WorkflowName string `binding:"Required;MaxSize(255)"`
}

// NewAccessTokenForm form for creating access token
type NewAccessTokenForm struct {
Name string `binding:"Required;MaxSize(255)" locale:"settings.token_name"`
Expand Down
2 changes: 1 addition & 1 deletion templates/org/settings/actions.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{template "org/settings/layout_head" (dict "ctxData" . "pageClass" "organization settings actions")}}
<div class="org-setting-content">
{{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" .}}
Expand Down
4 changes: 2 additions & 2 deletions templates/org/settings/navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<details class="item toggleable-item" {{if or .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables}}open{{end}}>
<summary>{{ctx.Locale.Tr "actions.actions"}}</summary>
<div class="menu">
<a class="{{if .PageIsSharedSettingsRequireActions}}active {{end}}item" href="{{.OrgLink}}/settings/actions/require_actions">
{{ctx.Locale.Tr "actions.require_actions"}}
<a class="{{if .PageIsSharedSettingsRequireAction}}active {{end}}item" href="{{.OrgLink}}/settings/actions/require_action">
{{ctx.Locale.Tr "actions.require_action"}}
</a>
<a class="{{if .PageIsSharedSettingsRunners}}active {{end}}item" href="{{.OrgLink}}/settings/actions/runners">
{{ctx.Locale.Tr "actions.runners"}}
Expand Down
Loading

0 comments on commit 3e2eca2

Please sign in to comment.