mirror of
https://github.com/go-gitea/gitea
synced 2024-11-19 02:39:28 +01:00
Fix all the format of the commit
Signed-off-by: Alex Lau(AvengerMoJo) <avengermojo@gmail.com>
This commit is contained in:
parent
5243490071
commit
1fc998984f
@ -6,77 +6,73 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
//"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
//"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
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"`
|
||||
//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 {
|
||||
RepoName string
|
||||
Filename string
|
||||
RepoName string
|
||||
Filename string
|
||||
}
|
||||
|
||||
func init() {
|
||||
db.RegisterModel(new(RequireAction))
|
||||
db.RegisterModel(new(RequireAction))
|
||||
}
|
||||
|
||||
type FindRequireActionOptions struct {
|
||||
db.ListOptions
|
||||
RequireActionID int64
|
||||
OrgID int64
|
||||
RepoName string
|
||||
db.ListOptions
|
||||
RequireActionID int64
|
||||
OrgID int64
|
||||
RepoName string
|
||||
}
|
||||
|
||||
func (opts FindRequireActionOptions) ToConds() builder.Cond {
|
||||
cond := builder.NewCond()
|
||||
if opts.OrgID > 0 {
|
||||
cond = cond.And(builder.Eq{"org_id": opts.OrgID})
|
||||
}
|
||||
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
|
||||
cond := builder.NewCond()
|
||||
if opts.OrgID > 0 {
|
||||
cond = cond.And(builder.Eq{"org_id": opts.OrgID})
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
// LoadAttributes loads the attributes of the require action
|
||||
func (r *RequireAction) LoadAttributes(ctx context.Context) error {
|
||||
// place holder for now.
|
||||
return nil
|
||||
// place holder for now.
|
||||
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
|
||||
// everyone can remove for now
|
||||
return r.OrgID == orgID
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
func AddRequireAction(ctx context.Context, orgID int64, repoName, workflowName string) (*RequireAction, error) {
|
||||
ra := &RequireAction{
|
||||
OrgID: orgID,
|
||||
RepoName: repoName,
|
||||
WorkflowName: workflowName,
|
||||
}
|
||||
return ra, db.Insert(ctx, ra)
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ import (
|
||||
)
|
||||
|
||||
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"`
|
||||
}
|
||||
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))
|
||||
}
|
||||
|
@ -167,28 +167,28 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
|
||||
}
|
||||
|
||||
type ActionsConfig struct {
|
||||
DisabledWorkflows []string
|
||||
EnabledGlobalWorkflows []string
|
||||
DisabledWorkflows []string
|
||||
EnabledGlobalWorkflows []string
|
||||
}
|
||||
|
||||
func (cfg *ActionsConfig) EnableWorkflow(file string) {
|
||||
cfg.DisabledWorkflows = util.SliceRemoveAll(cfg.DisabledWorkflows, file)
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *ActionsConfig) DisableGlobalWorkflow(file string) {
|
||||
cfg.EnabledGlobalWorkflows = util.SliceRemoveAll(cfg.EnabledGlobalWorkflows, file)
|
||||
cfg.EnabledGlobalWorkflows = util.SliceRemoveAll(cfg.EnabledGlobalWorkflows, file)
|
||||
}
|
||||
|
||||
func (cfg *ActionsConfig) IsGlobalWorkflowEnabled(file string) bool {
|
||||
return slices.Contains(cfg.EnabledGlobalWorkflows, file)
|
||||
return slices.Contains(cfg.EnabledGlobalWorkflows, file)
|
||||
}
|
||||
|
||||
func (cfg *ActionsConfig) EnableGlobalWorkflow(file string) {
|
||||
cfg.EnabledGlobalWorkflows = append(cfg.EnabledGlobalWorkflows, file)
|
||||
cfg.EnabledGlobalWorkflows = append(cfg.EnabledGlobalWorkflows, file)
|
||||
}
|
||||
|
||||
func (cfg *ActionsConfig) GetGlobalWorkflow() []string {
|
||||
return cfg.EnabledGlobalWorkflows
|
||||
return cfg.EnabledGlobalWorkflows
|
||||
}
|
||||
|
||||
func (cfg *ActionsConfig) ToString() string {
|
||||
|
@ -6,9 +6,9 @@
|
||||
package setting
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
func RedirectToRepoSetting(ctx *context.Context) {
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/settings/actions/require_action")
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/settings/actions/require_action")
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ func List(ctx *context.Context) {
|
||||
workflow := ctx.FormString("workflow")
|
||||
actorID := ctx.FormInt64("actor")
|
||||
status := ctx.FormInt("status")
|
||||
isGlobal := false
|
||||
isGlobal := false
|
||||
ctx.Data["CurWorkflow"] = workflow
|
||||
|
||||
actionsConfig := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
|
||||
@ -154,8 +154,8 @@ func List(ctx *context.Context) {
|
||||
if len(workflow) > 0 && ctx.Repo.IsAdmin() {
|
||||
ctx.Data["AllowDisableOrEnableWorkflow"] = true
|
||||
ctx.Data["CurWorkflowDisabled"] = actionsConfig.IsWorkflowDisabled(workflow)
|
||||
ctx.Data["CurGlobalWorkflowEnable"] = actionsConfig.IsGlobalWorkflowEnabled(workflow)
|
||||
isGlobal = actionsConfig.IsGlobalWorkflowEnabled(workflow)
|
||||
ctx.Data["CurGlobalWorkflowEnable"] = actionsConfig.IsGlobalWorkflowEnabled(workflow)
|
||||
isGlobal = actionsConfig.IsGlobalWorkflowEnabled(workflow)
|
||||
}
|
||||
|
||||
// if status or actor query param is not given to frontend href, (href="/<repoLink>/actions")
|
||||
@ -212,9 +212,9 @@ func List(ctx *context.Context) {
|
||||
pager.AddParamString("workflow", workflow)
|
||||
pager.AddParamString("actor", fmt.Sprint(actorID))
|
||||
pager.AddParamString("status", fmt.Sprint(status))
|
||||
if isGlobal {
|
||||
pager.AddParamString("global", fmt.Sprint(isGlobal))
|
||||
}
|
||||
if isGlobal {
|
||||
pager.AddParamString("global", fmt.Sprint(isGlobal))
|
||||
}
|
||||
ctx.Data["Page"] = pager
|
||||
ctx.Data["HasWorkflowsOrRuns"] = len(workflows) > 0 || len(runs) > 0
|
||||
|
||||
|
@ -716,36 +716,36 @@ func disableOrEnableWorkflowFile(ctx *context_module.Context, isEnable bool) {
|
||||
}
|
||||
|
||||
func DisableGlobalWorkflowFile(ctx *context_module.Context) {
|
||||
disableOrEnableGlobalWorkflowFile(ctx, true)
|
||||
disableOrEnableGlobalWorkflowFile(ctx, true)
|
||||
}
|
||||
|
||||
func EnableGlobalWorkflowFile(ctx *context_module.Context) {
|
||||
disableOrEnableGlobalWorkflowFile(ctx, false)
|
||||
disableOrEnableGlobalWorkflowFile(ctx, false)
|
||||
}
|
||||
|
||||
func disableOrEnableGlobalWorkflowFile(ctx *context_module.Context, isGlobalEnable bool) {
|
||||
workflow := ctx.FormString("workflow")
|
||||
if len(workflow) == 0 {
|
||||
ctx.ServerError("workflow", nil)
|
||||
return
|
||||
}
|
||||
cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
|
||||
cfg := cfgUnit.ActionsConfig()
|
||||
if isGlobalEnable {
|
||||
cfg.DisableGlobalWorkflow(workflow)
|
||||
} else {
|
||||
cfg.EnableGlobalWorkflow(workflow)
|
||||
}
|
||||
if err := repo_model.UpdateRepoUnit(ctx, cfgUnit); err != nil {
|
||||
ctx.ServerError("UpdateRepoUnit", err)
|
||||
return
|
||||
}
|
||||
if isGlobalEnable {
|
||||
ctx.Flash.Success(ctx.Tr("actions.workflow.global_disable_success", workflow))
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("actions.workflow.global_enable_success", workflow))
|
||||
}
|
||||
redirectURL := fmt.Sprintf("%s/actions?workflow=%s&actor=%s&status=%s", ctx.Repo.RepoLink, url.QueryEscape(workflow),
|
||||
url.QueryEscape(ctx.FormString("actor")), url.QueryEscape(ctx.FormString("status")))
|
||||
ctx.JSONRedirect(redirectURL)
|
||||
workflow := ctx.FormString("workflow")
|
||||
if len(workflow) == 0 {
|
||||
ctx.ServerError("workflow", nil)
|
||||
return
|
||||
}
|
||||
cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
|
||||
cfg := cfgUnit.ActionsConfig()
|
||||
if isGlobalEnable {
|
||||
cfg.DisableGlobalWorkflow(workflow)
|
||||
} else {
|
||||
cfg.EnableGlobalWorkflow(workflow)
|
||||
}
|
||||
if err := repo_model.UpdateRepoUnit(ctx, cfgUnit); err != nil {
|
||||
ctx.ServerError("UpdateRepoUnit", err)
|
||||
return
|
||||
}
|
||||
if isGlobalEnable {
|
||||
ctx.Flash.Success(ctx.Tr("actions.workflow.global_disable_success", workflow))
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("actions.workflow.global_enable_success", workflow))
|
||||
}
|
||||
redirectURL := fmt.Sprintf("%s/actions?workflow=%s&actor=%s&status=%s", ctx.Repo.RepoLink, url.QueryEscape(workflow),
|
||||
url.QueryEscape(ctx.FormString("actor")), url.QueryEscape(ctx.FormString("status")))
|
||||
ctx.JSONRedirect(redirectURL)
|
||||
}
|
||||
|
@ -6,75 +6,77 @@
|
||||
package setting
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
// "code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
// "code.gitea.io/gitea/modules/log"
|
||||
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
|
||||
//"code.gitea.io/gitea/modules/setting"
|
||||
shared "code.gitea.io/gitea/routers/web/shared/actions"
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
//"code.gitea.io/gitea/modules/setting"
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
shared "code.gitea.io/gitea/routers/web/shared/actions"
|
||||
)
|
||||
|
||||
const (
|
||||
// let start with org WIP
|
||||
tplOrgRequireAction base.TplName = "org/settings/actions"
|
||||
// let start with org WIP
|
||||
tplOrgRequireAction base.TplName = "org/settings/actions"
|
||||
)
|
||||
|
||||
type requireActionsCtx struct {
|
||||
OrgID int64
|
||||
IsOrg bool
|
||||
RequireActionTemplate base.TplName
|
||||
RedirectLink string
|
||||
OrgID int64
|
||||
IsOrg bool
|
||||
RequireActionTemplate base.TplName
|
||||
RedirectLink string
|
||||
}
|
||||
|
||||
func getRequireActionCtx(ctx *context.Context) (*requireActionsCtx, error) {
|
||||
if ctx.Data["PageIsOrgSettings"] == true {
|
||||
return &requireActionsCtx{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
IsOrg: true,
|
||||
RequireActionTemplate: tplOrgRequireAction,
|
||||
RedirectLink: ctx.Org.OrgLink + "/settings/actions/require_action",
|
||||
}, nil
|
||||
}
|
||||
return nil, errors.New("unable to set Require Actions context")
|
||||
if ctx.Data["PageIsOrgSettings"] == true {
|
||||
return &requireActionsCtx{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
IsOrg: true,
|
||||
RequireActionTemplate: tplOrgRequireAction,
|
||||
RedirectLink: ctx.Org.OrgLink + "/settings/actions/require_action",
|
||||
}, nil
|
||||
}
|
||||
return nil, errors.New("unable to set Require Actions context")
|
||||
}
|
||||
|
||||
// Listing all RequireAction
|
||||
func RequireAction(ctx *context.Context) {
|
||||
ctx.Data["ActionsTitle"] = ctx.Tr("actions.requires")
|
||||
ctx.Data["PageType"] = "require_action"
|
||||
ctx.Data["PageIsSharedSettingsRequireAction"] = true
|
||||
ctx.Data["ActionsTitle"] = ctx.Tr("actions.requires")
|
||||
ctx.Data["PageType"] = "require_action"
|
||||
ctx.Data["PageIsSharedSettingsRequireAction"] = true
|
||||
|
||||
vCtx, err := getRequireActionCtx(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("getRequireActionCtx", err)
|
||||
return
|
||||
}
|
||||
vCtx, err := getRequireActionCtx(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("getRequireActionCtx", err)
|
||||
return
|
||||
}
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 { page = 1 }
|
||||
opts := actions_model.FindRequireActionOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: 10,
|
||||
},
|
||||
}
|
||||
shared.SetRequireActionContext(ctx, opts)
|
||||
ctx.Data["Link"] = vCtx.RedirectLink
|
||||
shared.GlobalEnableWorkflow(ctx, ctx.Org.Organization.ID)
|
||||
ctx.HTML(http.StatusOK, vCtx.RequireActionTemplate)
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
opts := actions_model.FindRequireActionOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: 10,
|
||||
},
|
||||
}
|
||||
shared.SetRequireActionContext(ctx, opts)
|
||||
ctx.Data["Link"] = vCtx.RedirectLink
|
||||
shared.GlobalEnableWorkflow(ctx, ctx.Org.Organization.ID)
|
||||
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)
|
||||
vCtx, err := getRequireActionCtx(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("getRequireActionCtx", err)
|
||||
return
|
||||
}
|
||||
shared.CreateRequireAction(ctx, vCtx.OrgID, vCtx.RedirectLink)
|
||||
}
|
||||
|
@ -6,69 +6,70 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
org_model "code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
actions_service "code.gitea.io/gitea/services/actions"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
|
||||
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/util"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
"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"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
// SetRequireActionDeletePost response for deleting a require action workflow
|
||||
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("CountRequireActions", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["RequireActions"] = require_actions
|
||||
ctx.Data["Total"] = count
|
||||
ctx.Data["OrgID"] = ctx.Org.Organization.ID
|
||||
ctx.Data["OrgName"] = ctx.Org.Organization.Name
|
||||
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
|
||||
ctx.Data["Page"] = pager
|
||||
requireActions, count, err := db.FindAndCount[actions_model.RequireAction](ctx, opts)
|
||||
if err != nil {
|
||||
ctx.ServerError("CountRequireActions", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["RequireActions"] = requireActions
|
||||
ctx.Data["Total"] = count
|
||||
ctx.Data["OrgID"] = ctx.Org.Organization.ID
|
||||
ctx.Data["OrgName"] = ctx.Org.Organization.Name
|
||||
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
|
||||
ctx.Data["Page"] = pager
|
||||
}
|
||||
|
||||
// get all the available enable global workflow in the org's repo
|
||||
func GlobalEnableWorkflow(ctx *context.Context, orgID int64){
|
||||
var gwfList []actions_model.GlobalWorkflow
|
||||
orgRepos, err := org_model.GetOrgRepositories(ctx, orgID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GlobalEnableWorkflows get org repos: ", err)
|
||||
return
|
||||
}
|
||||
for _, repo := range orgRepos {
|
||||
repo.LoadUnits(ctx)
|
||||
actionsConfig := repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
|
||||
enabledWorkflows := actionsConfig.GetGlobalWorkflow()
|
||||
for _, workflow := range enabledWorkflows {
|
||||
gwf := actions_model.GlobalWorkflow{
|
||||
RepoName: repo.Name,
|
||||
Filename: workflow,
|
||||
}
|
||||
gwfList = append(gwfList, gwf)
|
||||
}
|
||||
}
|
||||
ctx.Data["GlobalEnableWorkflows"] = gwfList
|
||||
func GlobalEnableWorkflow(ctx *context.Context, orgID int64) {
|
||||
var gwfList []actions_model.GlobalWorkflow
|
||||
orgRepos, err := org_model.GetOrgRepositories(ctx, orgID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GlobalEnableWorkflows get org repos: ", err)
|
||||
return
|
||||
}
|
||||
for _, repo := range orgRepos {
|
||||
err := repo.LoadUnits(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("GlobalEnableWorkflows LoadUnits : ", err)
|
||||
}
|
||||
actionsConfig := repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
|
||||
enabledWorkflows := actionsConfig.GetGlobalWorkflow()
|
||||
for _, workflow := range enabledWorkflows {
|
||||
gwf := actions_model.GlobalWorkflow{
|
||||
RepoName: repo.Name,
|
||||
Filename: workflow,
|
||||
}
|
||||
gwfList = append(gwfList, gwf)
|
||||
}
|
||||
}
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
@ -458,13 +458,13 @@ func registerRoutes(m *web.Route) {
|
||||
})
|
||||
}
|
||||
|
||||
// WIP RequireAction
|
||||
addSettingsRequireActionRoutes := func() {
|
||||
m.Group("/require_action", func() {
|
||||
m.Get("", repo_setting.RequireAction)
|
||||
m.Post("/add", web.Bind(forms.RequireActionForm{}), repo_setting.RequireActionCreate)
|
||||
})
|
||||
}
|
||||
// WIP RequireAction
|
||||
addSettingsRequireActionRoutes := func() {
|
||||
m.Group("/require_action", func() {
|
||||
m.Get("", repo_setting.RequireAction)
|
||||
m.Post("/add", web.Bind(forms.RequireActionForm{}), repo_setting.RequireActionCreate)
|
||||
})
|
||||
}
|
||||
|
||||
// FIXME: not all routes need go through same middleware.
|
||||
// Especially some AJAX requests, we can reduce middleware number to improve performance.
|
||||
@ -1368,8 +1368,8 @@ func registerRoutes(m *web.Route) {
|
||||
m.Get("", actions.List)
|
||||
m.Post("/disable", reqRepoAdmin, actions.DisableWorkflowFile)
|
||||
m.Post("/enable", reqRepoAdmin, actions.EnableWorkflowFile)
|
||||
m.Post("/global_disable", reqRepoAdmin, actions.DisableGlobalWorkflowFile)
|
||||
m.Post("/global_enable", reqRepoAdmin, actions.EnableGlobalWorkflowFile)
|
||||
m.Post("/global_disable", reqRepoAdmin, actions.DisableGlobalWorkflowFile)
|
||||
m.Post("/global_enable", reqRepoAdmin, actions.EnableGlobalWorkflowFile)
|
||||
|
||||
m.Group("/runs/{run}", func() {
|
||||
m.Combo("").
|
||||
|
@ -4,15 +4,15 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"context"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
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
|
||||
func CreateRequireAction(ctx context.Context, orgID int64, repoName, workflowName string) (*actions_model.RequireAction, error) {
|
||||
v, err := actions_model.AddRequireAction(ctx, orgID, repoName, workflowName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
@ -359,8 +359,7 @@ func (f *EditVariableForm) Validate(req *http.Request, errs binding.Errors) bind
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
}
|
||||
|
||||
//WIP RequireAction create form
|
||||
|
||||
// WIP RequireAction create form
|
||||
type RequireActionForm struct {
|
||||
RepoName string `binding:"Required;MaxSize(255)"`
|
||||
WorkflowName string `binding:"Required;MaxSize(255)"`
|
||||
|
@ -1,18 +1,16 @@
|
||||
<div class="require-actions-container">
|
||||
<h4 class="ui top attached header">
|
||||
{{ctx.Locale.Tr "actions.require_action.require_action_manage_panel"}} ({{ctx.Locale.Tr "admin.total" .Total}})
|
||||
<div class="ui right">
|
||||
<div class="ui top right">
|
||||
<button class="ui primary tiny button show-modal"
|
||||
data-modal="#add-require-actions-modal"
|
||||
{{ctx.Locale.Tr "actions.require_action.require_action_manage_panel"}} ({{ctx.Locale.Tr "admin.total" .Total}})
|
||||
<div class="ui right">
|
||||
<div class="ui top right">
|
||||
<button class="ui primary tiny button show-modal"
|
||||
data-modal="#add-require-actions-modal"
|
||||
data-modal-form.action="{{.Link}}/add"
|
||||
data-modal-header="{{ctx.Locale.Tr "actions.require_action.add"}}"
|
||||
>
|
||||
data-modal-header="{{ctx.Locale.Tr "actions.require_action.add"}}">
|
||||
{{ctx.Locale.Tr "actions.require_action.add"}}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</h4>
|
||||
<div class="ui attached segment">
|
||||
<form class="ui form ignore-dirty" id="require-action-list-search-form" action="{{$.Link}}">
|
||||
@ -61,7 +59,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{template "base/paginate" .}}
|
||||
{{template "base/paginate"}}
|
||||
</div>
|
||||
|
||||
|
||||
@ -69,7 +67,7 @@
|
||||
{{/* Add RequireAction dialog */}}
|
||||
<div class="ui small modal" id="add-require-actions-modal">
|
||||
<div class="header">
|
||||
<span id="actions-modal-header">Availble Enable Workflows</span>
|
||||
<span id="actions-modal-header">Enable Workflows</span>
|
||||
</div>
|
||||
<form class="ui form form-fetch-action" method="post">
|
||||
<div class="content">
|
||||
@ -77,7 +75,6 @@
|
||||
<a href="https://docs.gitea.com/usage/actions/require-action">{{ctx.Locale.Tr "actions.require_action.enable_global_workflow"}}</a>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<!-- <div class="ui input"> -->
|
||||
<table class="ui very basic striped table unstackable">
|
||||
<thead>
|
||||
<tr>
|
||||
|
Loading…
Reference in New Issue
Block a user