33
44package project
55
6- import "code.gitea.io/gitea/models/db"
6+ import (
7+ "context"
8+
9+ "code.gitea.io/gitea/models/db"
10+ "code.gitea.io/gitea/modules/timeutil"
11+ "code.gitea.io/gitea/modules/util"
12+ )
713
814type WorkflowEvent string
915
@@ -19,12 +25,52 @@ const (
1925 WorkflowEventAutoCloseIssue WorkflowEvent = "auto_close_issue"
2026)
2127
22- type ProjectWorkflow struct {
23- ID int64
24- ProjectID int64 `xorm:"index"`
25- WorkflowEvent WorkflowEvent `xorm:"index"`
28+ type WorkflowActionType string
29+
30+ const (
31+ WorkflowActionTypeScope WorkflowActionType = "scope" // issue, pull_request, etc.
32+ WorkflowActionTypeLabel WorkflowActionType = "label" // choose one or more labels
33+ WorkflowActionTypeColumn WorkflowActionType = "column" // choose one column
34+ WorkflowActionTypeClose WorkflowActionType = "close" // close the issue
35+ )
36+
37+ type WorkflowAction struct {
38+ ActionType WorkflowActionType
39+ ActionValue string
40+ }
41+
42+ type ProjectWorkflowEvent struct {
43+ ID int64
44+ ProjectID int64 `xorm:"unique(s)"`
45+ WorkflowEvent WorkflowEvent `xorm:"unique(s)"`
46+ WorkflowActions []WorkflowAction `xorm:"TEXT json"`
47+ CreatedUnix timeutil.TimeStamp `xorm:"created"`
48+ UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
2649}
2750
2851func init () {
29- db .RegisterModel (new (ProjectWorkflow ))
52+ db .RegisterModel (new (ProjectWorkflowEvent ))
53+ }
54+
55+ func FindWorkflowEvents (ctx context.Context , projectID int64 ) (map [WorkflowEvent ]ProjectWorkflowEvent , error ) {
56+ events := make (map [WorkflowEvent ]ProjectWorkflowEvent )
57+ if err := db .GetEngine (ctx ).Where ("project_id=?" , projectID ).Find (& events ); err != nil {
58+ return nil , err
59+ }
60+ res := make (map [WorkflowEvent ]ProjectWorkflowEvent , len (events ))
61+ for _ , event := range events {
62+ res [event .WorkflowEvent ] = event
63+ }
64+ return res , nil
65+ }
66+
67+ func GetWorkflowEventByID (ctx context.Context , id int64 ) (* ProjectWorkflowEvent , error ) {
68+ p , exist , err := db .GetByID [ProjectWorkflowEvent ](ctx , id )
69+ if err != nil {
70+ return nil , err
71+ }
72+ if ! exist {
73+ return nil , util .ErrNotExist
74+ }
75+ return p , nil
3076}
0 commit comments