-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wip require action feature fail post #30067
Closed
AvengerMoJo
wants to merge
9
commits into
go-gitea:main
from
AvengerMoJo:wip_require_action_feature_fail_post
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5243490
Enable the global workflow and require_action in org setting
AvengerMoJo 1fc9989
Fix all the format of the commit
AvengerMoJo d4fd5b5
Add the delete function and remove formatting error.
AvengerMoJo c10d144
Remove duplicate error for the global enable flag remove formatting e…
AvengerMoJo 32cb526
Remove formatting all the template
AvengerMoJo c4b9238
moving the js to a seperated file in web_src/js/features/
AvengerMoJo 325842d
Merge branch 'main' into wip_require_action_feature_fail_post
AvengerMoJo d68a821
Fix the format
AvengerMoJo c4feb3d
Merge branch 'main' into wip_require_action_feature_fail_post
AvengerMoJo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,82 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// WIP RequireAction | ||
|
||
package actions | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"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"` | ||
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` | ||
UpdatedUnix timeutil.TimeStamp `xorm:"updated"` | ||
} | ||
|
||
type GlobalWorkflow struct { | ||
RepoName string | ||
Filename string | ||
} | ||
|
||
func init() { | ||
db.RegisterModel(new(RequireAction)) | ||
} | ||
|
||
type FindRequireActionOptions struct { | ||
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 | ||
} | ||
|
||
// LoadAttributes loads the attributes of the require action | ||
func (r *RequireAction) LoadAttributes(ctx context.Context) error { | ||
// place holder for now. | ||
return nil | ||
} | ||
|
||
// if the workflow is removable | ||
func (r *RequireAction) Removable(orgID int64) bool { | ||
// everyone can remove for now | ||
return r.OrgID == orgID | ||
} | ||
|
||
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) | ||
} | ||
|
||
func DeleteRequireAction(ctx context.Context, requireActionID int64) error { | ||
if _, err := db.DeleteByID[RequireAction](ctx, requireActionID); err != nil { | ||
return err | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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)) | ||
} |
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_action") | ||
} |
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,87 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// WIP RequireAction | ||
|
||
package setting | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
actions_model "code.gitea.io/gitea/models/actions" | ||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/modules/base" | ||
shared "code.gitea.io/gitea/routers/web/shared/actions" | ||
"code.gitea.io/gitea/services/context" | ||
) | ||
|
||
const ( | ||
// let start with org WIP | ||
tplOrgRequireAction base.TplName = "org/settings/actions" | ||
) | ||
|
||
type requireActionsCtx struct { | ||
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") | ||
} | ||
|
||
// Listing all RequireAction | ||
func RequireAction(ctx *context.Context) { | ||
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 | ||
} | ||
|
||
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) | ||
} | ||
|
||
func RequireActionDelete(ctx *context.Context) { | ||
vCtx, err := getRequireActionCtx(ctx) | ||
if err != nil { | ||
ctx.ServerError("getRequireActionCtx", err) | ||
return | ||
} | ||
shared.DeleteRequireAction(ctx, vCtx.RedirectLink) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.