|
6 | 6 | package actions |
7 | 7 |
|
8 | 8 | import ( |
9 | | - "context" |
| 9 | + "context" |
10 | 10 |
|
11 | | - "code.gitea.io/gitea/models/db" |
12 | | - //"code.gitea.io/gitea/models/unit" |
13 | | - "code.gitea.io/gitea/modules/timeutil" |
| 11 | + "code.gitea.io/gitea/models/db" |
| 12 | + //"code.gitea.io/gitea/models/unit" |
| 13 | + "code.gitea.io/gitea/modules/timeutil" |
14 | 14 |
|
15 | | - "xorm.io/builder" |
| 15 | + "xorm.io/builder" |
16 | 16 | ) |
17 | 17 |
|
18 | 18 | type RequireAction struct { |
19 | | - ID int64 `xorm:"pk autoincr"` |
20 | | - OrgID int64 `xorm:"index"` |
21 | | - RepoName string `xorm:"VARCHAR(255)"` |
22 | | - WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"` |
23 | | - //Description string `xorm:"LONGTEXT NOT NULL"` |
24 | | - CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` |
25 | | - UpdatedUnix timeutil.TimeStamp `xorm:"updated"` |
26 | | - // RepoRange string // glob match which repositories could use this runner |
| 19 | + ID int64 `xorm:"pk autoincr"` |
| 20 | + OrgID int64 `xorm:"index"` |
| 21 | + RepoName string `xorm:"VARCHAR(255)"` |
| 22 | + WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"` |
| 23 | + // Description string `xorm:"LONGTEXT NOT NULL"` |
| 24 | + CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` |
| 25 | + UpdatedUnix timeutil.TimeStamp `xorm:"updated"` |
| 26 | + // RepoRange string // glob match which repositories could use this runner |
27 | 27 | } |
28 | 28 |
|
29 | 29 | type GlobalWorkflow struct { |
30 | | - RepoName string |
31 | | - Filename string |
| 30 | + RepoName string |
| 31 | + Filename string |
32 | 32 | } |
33 | 33 |
|
34 | 34 | func init() { |
35 | | - db.RegisterModel(new(RequireAction)) |
| 35 | + db.RegisterModel(new(RequireAction)) |
36 | 36 | } |
37 | 37 |
|
38 | 38 | type FindRequireActionOptions struct { |
39 | | - db.ListOptions |
40 | | - RequireActionID int64 |
41 | | - OrgID int64 |
42 | | - RepoName string |
| 39 | + db.ListOptions |
| 40 | + RequireActionID int64 |
| 41 | + OrgID int64 |
| 42 | + RepoName string |
43 | 43 | } |
44 | 44 |
|
45 | 45 | func (opts FindRequireActionOptions) ToConds() builder.Cond { |
46 | | - cond := builder.NewCond() |
47 | | - if opts.OrgID > 0 { |
48 | | - cond = cond.And(builder.Eq{"org_id": opts.OrgID}) |
49 | | - } |
50 | | - if opts.RequireActionID > 0 { |
51 | | - cond = cond.And(builder.Eq{"id": opts.RequireActionID}) |
52 | | - } |
53 | | - if opts.RepoName != "" { |
54 | | - cond = cond.And(builder.Eq{"repo_name": opts.RepoName}) |
55 | | - } |
56 | | - return cond |
| 46 | + cond := builder.NewCond() |
| 47 | + if opts.OrgID > 0 { |
| 48 | + cond = cond.And(builder.Eq{"org_id": opts.OrgID}) |
| 49 | + } |
| 50 | + if opts.RequireActionID > 0 { |
| 51 | + cond = cond.And(builder.Eq{"id": opts.RequireActionID}) |
| 52 | + } |
| 53 | + if opts.RepoName != "" { |
| 54 | + cond = cond.And(builder.Eq{"repo_name": opts.RepoName}) |
| 55 | + } |
| 56 | + return cond |
57 | 57 | } |
58 | 58 |
|
59 | 59 | // LoadAttributes loads the attributes of the require action |
60 | 60 | func (r *RequireAction) LoadAttributes(ctx context.Context) error { |
61 | | - // place holder for now. |
62 | | - return nil |
| 61 | + // place holder for now. |
| 62 | + return nil |
63 | 63 | } |
64 | 64 |
|
65 | 65 | // if the workflow is removable |
66 | 66 | func (r *RequireAction) Removable(orgID int64) bool { |
67 | | - // everyone can remove for now |
68 | | - if r.OrgID == orgID { |
69 | | - return true |
70 | | - } |
71 | | - return false |
| 67 | + // everyone can remove for now |
| 68 | + return r.OrgID == orgID |
72 | 69 | } |
73 | 70 |
|
74 | | - |
75 | | -func AddRequireAction(ctx context.Context, orgID int64, repoName string, workflowName string) (*RequireAction, error) { |
76 | | - ra := &RequireAction{ |
77 | | - OrgID: orgID, |
78 | | - RepoName: repoName, |
79 | | - WorkflowName: workflowName, |
80 | | - } |
81 | | - return ra, db.Insert(ctx, ra) |
| 71 | +func AddRequireAction(ctx context.Context, orgID int64, repoName, workflowName string) (*RequireAction, error) { |
| 72 | + ra := &RequireAction{ |
| 73 | + OrgID: orgID, |
| 74 | + RepoName: repoName, |
| 75 | + WorkflowName: workflowName, |
| 76 | + } |
| 77 | + return ra, db.Insert(ctx, ra) |
82 | 78 | } |
0 commit comments