44package projects
55
66import (
7+ stdCtx "context"
78 "errors"
89 "io"
910 "net/http"
@@ -25,22 +26,56 @@ var (
2526)
2627
2728// getFilterSummary returns a human-readable summary of the filters
28- func getFilterSummary (filters []project_model.WorkflowFilter ) string {
29+ func getFilterSummary (ctx stdCtx. Context , filters []project_model.WorkflowFilter ) string {
2930 if len (filters ) == 0 {
3031 return ""
3132 }
3233
34+ var summary strings.Builder
35+ labelIDs := make ([]int64 , 0 )
3336 for _ , filter := range filters {
34- if filter .Type == "scope" {
37+ switch filter .Type {
38+ case project_model .WorkflowFilterTypeIssueType :
3539 switch filter .Value {
3640 case "issue" :
37- return " (Issues only)"
41+ summary . WriteString ( " (Issues only)" )
3842 case "pull_request" :
39- return " (Pull requests only)"
43+ summary .WriteString (" (Pull requests only)" )
44+ }
45+ case project_model .WorkflowFilterTypeColumn :
46+ columnID , _ := strconv .ParseInt (filter .Value , 10 , 64 )
47+ if columnID <= 0 {
48+ continue
49+ }
50+ col , err := project_model .GetColumn (ctx , columnID )
51+ if err != nil {
52+ log .Error ("GetColumn: %v" , err )
53+ continue
54+ }
55+ summary .WriteString (" (Column: " + col .Title + ")" )
56+ case project_model .WorkflowFilterTypeLabels :
57+ labelID , _ := strconv .ParseInt (filter .Value , 10 , 64 )
58+ if labelID > 0 {
59+ labelIDs = append (labelIDs , labelID )
4060 }
4161 }
4262 }
43- return ""
63+ if len (labelIDs ) > 0 {
64+ labels , err := issues_model .GetLabelsByIDs (ctx , labelIDs )
65+ if err != nil {
66+ log .Error ("GetLabelsByIDs: %v" , err )
67+ } else {
68+ summary .WriteString (" (Labels: " )
69+ for i , label := range labels {
70+ summary .WriteString (label .Name )
71+ if i < len (labels )- 1 {
72+ summary .WriteString (", " )
73+ }
74+ }
75+ summary .WriteString (")" )
76+ }
77+ }
78+ return summary .String ()
4479}
4580
4681// convertFormToFilters converts form filters to WorkflowFilter objects
@@ -133,28 +168,16 @@ func convertFormToActions(formActions map[string]any) []project_model.WorkflowAc
133168 }
134169 }
135170 }
136- case "issueState " :
171+ case "issue_state " :
137172 if strValue , ok := value .(string ); ok {
138- switch strings .ToLower (strValue ) {
139- case "close" , "closed" , "true" :
140- actions = append (actions , project_model.WorkflowAction {
141- Type : project_model .WorkflowActionTypeClose ,
142- Value : "close" ,
143- })
144- case "reopen" , "open" , "false" :
173+ v := strings .ToLower (strValue )
174+ if v == "close" || v == "reopen" {
145175 actions = append (actions , project_model.WorkflowAction {
146- Type : project_model .WorkflowActionTypeClose ,
147- Value : "reopen" ,
176+ Type : project_model .WorkflowActionTypeIssueState ,
177+ Value : v ,
148178 })
149179 }
150180 }
151- case "closeIssue" :
152- if boolValue , ok := value .(bool ); ok && boolValue {
153- actions = append (actions , project_model.WorkflowAction {
154- Type : project_model .WorkflowActionTypeClose ,
155- Value : "close" ,
156- })
157- }
158181 }
159182 }
160183
@@ -216,7 +239,7 @@ func WorkflowsEvents(ctx *context.Context) {
216239 if len (existingWorkflows ) > 0 {
217240 // Add all existing workflows for this event
218241 for _ , wf := range existingWorkflows {
219- filterSummary := getFilterSummary (wf .WorkflowFilters )
242+ filterSummary := getFilterSummary (ctx , wf .WorkflowFilters )
220243 outputWorkflows = append (outputWorkflows , & WorkflowConfig {
221244 ID : wf .ID ,
222245 EventID : strconv .FormatInt (wf .ID , 10 ),
@@ -485,7 +508,7 @@ func WorkflowsPost(ctx *context.Context) {
485508 }
486509
487510 // Return the newly created workflow with filter summary
488- filterSummary := getFilterSummary (wf .WorkflowFilters )
511+ filterSummary := getFilterSummary (ctx , wf .WorkflowFilters )
489512 ctx .JSON (http .StatusOK , map [string ]any {
490513 "success" : true ,
491514 "workflow" : map [string ]any {
@@ -518,7 +541,7 @@ func WorkflowsPost(ctx *context.Context) {
518541 }
519542
520543 // Return the updated workflow with filter summary
521- filterSummary := getFilterSummary (wf .WorkflowFilters )
544+ filterSummary := getFilterSummary (ctx , wf .WorkflowFilters )
522545 ctx .JSON (http .StatusOK , map [string ]any {
523546 "success" : true ,
524547 "workflow" : map [string ]any {
0 commit comments