-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combined all RequestActions implementation and merge upstream
Update all formating issues Signed-off-by: Alex Lau(AvengerMoJo) <[email protected]>
- Loading branch information
1 parent
e0c27e5
commit c0d50fd
Showing
19 changed files
with
695 additions
and
15 deletions.
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
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
Oops, something went wrong.