forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update from upstream then re-add the global actions
Remove the cycle call function Create Org Setting Actions RequireAction Signed-off-by: Alex Lau(AvengerMoJo) <[email protected]>
- Loading branch information
1 parent
d872ce0
commit 345b1d7
Showing
13 changed files
with
450 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// WIP RequireAction | ||
|
||
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" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"xorm.io/builder" | ||
) | ||
|
||
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 | ||
} | ||
|
||
type GlobalWorkflow struct { | ||
RepoName string | ||
Filename string | ||
} | ||
|
||
func init() { | ||
db.RegisterModel(new(RequireAction)) | ||
} | ||
|
||
type FindRequireActionOptions struct { | ||
db.ListOptions | ||
RequireActionID int64 | ||
OrgID int64 | ||
} | ||
|
||
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}) | ||
} | ||
return cond | ||
} | ||
|
||
// LoadAttributes loads the attributes of the require action | ||
func (r *RequireAction) LoadAttributes(ctx context.Context) error { | ||
// place holder for now. | ||
return nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// WIP RequireAction | ||
|
||
package setting | ||
|
||
import ( | ||
"code.gitea.io/gitea/services/context" | ||
) | ||
|
||
func RedirectToRepoSetting(ctx *context.Context) { | ||
ctx.Redirect(ctx.Org.OrgLink + "/settings/actions/require_actions") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// WIP RequireAction | ||
|
||
package setting | ||
|
||
import ( | ||
"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/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" | ||
) | ||
|
||
const ( | ||
// let start with org WIP | ||
tplOrgRequireActions base.TplName = "org/settings/actions" | ||
) | ||
|
||
type requireActionsCtx struct { | ||
OrgID int64 | ||
IsOrg bool | ||
RequireActionsTemplate base.TplName | ||
RedirectLink string | ||
} | ||
|
||
func getRequireActionsCtx(ctx *context.Context) (*requireActionsCtx, error) { | ||
if ctx.Data["PageIsOrgSettings"] == true { | ||
return &requireActionsCtx{ | ||
OrgID: ctx.Org.Organization.ID, | ||
IsOrg: true, | ||
RequireActionsTemplate: tplOrgRequireActions, | ||
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) { | ||
ctx.Data["ActionsTitle"] = ctx.Tr("actions.requires") | ||
ctx.Data["PageType"] = "require_actions" | ||
ctx.Data["PageIsSharedSettingsRequireActions"] = true | ||
|
||
vCtx, err := getRequireActionsCtx(ctx) | ||
if err != nil { | ||
ctx.ServerError("getRequireActionsCtx", err) | ||
return | ||
} | ||
|
||
page := ctx.FormInt("page") | ||
if page <= 1 { page = 1 } | ||
opts := actions_model.FindRequireActionOptions{ | ||
ListOptions: db.ListOptions{ | ||
Page: page, | ||
PageSize: 10, | ||
}, | ||
} | ||
shared.SetRequireActionsContext(ctx, opts) | ||
ctx.Data["Link"] = vCtx.RedirectLink | ||
shared.GlobalEnableWorkflow(ctx, ctx.Org.Organization.ID) | ||
ctx.HTML(http.StatusOK, vCtx.RequireActionsTemplate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// WIP RequireAction | ||
|
||
package actions | ||
|
||
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/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/services/context" | ||
) | ||
|
||
// SetRequireActionDeletePost response for deleting a require action workflow | ||
func SetRequireActionsContext(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) | ||
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 | ||
} | ||
|
||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.