@@ -55,7 +55,7 @@ func (m *workflowNotifier) NewIssue(ctx context.Context, issue *issues_model.Iss
5555 // Find workflows for the ItemOpened event
5656 for _ , workflow := range workflows {
5757 if workflow .WorkflowEvent == project_model .WorkflowEventItemOpened {
58- fireIssueWorkflow (ctx , workflow , issue )
58+ fireIssueWorkflow (ctx , workflow , issue , 0 )
5959 }
6060 }
6161}
@@ -92,7 +92,7 @@ func (m *workflowNotifier) IssueChangeStatus(ctx context.Context, doer *user_mod
9292 // Find workflows for the specific event
9393 for _ , workflow := range workflows {
9494 if workflow .WorkflowEvent == workflowEvent {
95- fireIssueWorkflow (ctx , workflow , issue )
95+ fireIssueWorkflow (ctx , workflow , issue , 0 )
9696 }
9797 }
9898}
@@ -124,7 +124,7 @@ func (*workflowNotifier) IssueChangeProjects(ctx context.Context, doer *user_mod
124124 // Find workflows for the ItemOpened event
125125 for _ , workflow := range workflows {
126126 if workflow .WorkflowEvent == project_model .WorkflowEventItemAddedToProject {
127- fireIssueWorkflow (ctx , workflow , issue )
127+ fireIssueWorkflow (ctx , workflow , issue , 0 )
128128 }
129129 }
130130}
@@ -158,7 +158,7 @@ func (*workflowNotifier) IssueChangeProjectColumn(ctx context.Context, doer *use
158158 // Find workflows for the ItemColumnChanged event
159159 for _ , workflow := range workflows {
160160 if workflow .WorkflowEvent == project_model .WorkflowEventItemColumnChanged {
161- fireIssueWorkflowWithColumn (ctx , workflow , issue , newColumnID )
161+ fireIssueWorkflow (ctx , workflow , issue , newColumnID )
162162 }
163163 }
164164}
@@ -192,7 +192,7 @@ func (*workflowNotifier) MergePullRequest(ctx context.Context, doer *user_model.
192192 // Find workflows for the PullRequestMerged event
193193 for _ , workflow := range workflows {
194194 if workflow .WorkflowEvent == project_model .WorkflowEventPullRequestMerged {
195- fireIssueWorkflow (ctx , workflow , issue )
195+ fireIssueWorkflow (ctx , workflow , issue , 0 )
196196 }
197197 }
198198}
@@ -231,14 +231,12 @@ func (*workflowNotifier) PullRequestReview(ctx context.Context, pr *issues_model
231231 for _ , workflow := range workflows {
232232 if (workflow .WorkflowEvent == project_model .WorkflowEventCodeChangesRequested && review .Type == issues_model .ReviewTypeReject ) ||
233233 (workflow .WorkflowEvent == project_model .WorkflowEventCodeReviewApproved && review .Type == issues_model .ReviewTypeApprove ) {
234- fireIssueWorkflow (ctx , workflow , issue )
234+ fireIssueWorkflow (ctx , workflow , issue , 0 )
235235 }
236236 }
237237}
238238
239- // fireIssueWorkflowWithColumn fires a workflow for an issue with a specific column ID
240- // This is used for ItemColumnChanged events where we need to check the target column
241- func fireIssueWorkflowWithColumn (ctx context.Context , workflow * project_model.Workflow , issue * issues_model.Issue , columnID int64 ) {
239+ func fireIssueWorkflow (ctx context.Context , workflow * project_model.Workflow , issue * issues_model.Issue , columnID int64 ) {
242240 if ! workflow .Enabled {
243241 return
244242 }
@@ -249,72 +247,15 @@ func fireIssueWorkflowWithColumn(ctx context.Context, workflow *project_model.Wo
249247 return
250248 }
251249
252- for _ , filter := range workflow .WorkflowFilters {
253- switch filter .Type {
254- case project_model .WorkflowFilterTypeIssueType :
255- // If filter value is empty, match all types
256- if filter .Value == "" {
257- continue
258- }
259- // Filter value can be "issue" or "pull_request"
260- if filter .Value == "issue" && issue .IsPull {
261- return
262- }
263- if filter .Value == "pull_request" && ! issue .IsPull {
264- return
265- }
266- case project_model .WorkflowFilterTypeColumn :
267- // If filter value is empty, match all columns
268- if filter .Value == "" {
269- continue
270- }
271- filterColumnID , _ := strconv .ParseInt (filter .Value , 10 , 64 )
272- if filterColumnID == 0 {
273- log .Error ("Invalid column ID: %s" , filter .Value )
274- return
275- }
276- // For column changed event, check against the new column ID
277- if columnID != filterColumnID {
278- return
279- }
280- case project_model .WorkflowFilterTypeLabels :
281- // Check if issue has the specified label
282- labelID , _ := strconv .ParseInt (filter .Value , 10 , 64 )
283- if labelID == 0 {
284- log .Error ("Invalid label ID: %s" , filter .Value )
285- return
286- }
287- // Check if issue has this label
288- hasLabel := false
289- for _ , label := range issue .Labels {
290- if label .ID == labelID {
291- hasLabel = true
292- break
293- }
294- }
295- if ! hasLabel {
296- return
297- }
298- default :
299- log .Error ("Unsupported filter type: %s" , filter .Type )
300- return
301- }
250+ if ! matchWorkflowsFilters (workflow , issue , columnID ) {
251+ return
302252 }
303253
304254 executeWorkflowActions (ctx , workflow , issue )
305255}
306256
307- func fireIssueWorkflow (ctx context.Context , workflow * project_model.Workflow , issue * issues_model.Issue ) {
308- if ! workflow .Enabled {
309- return
310- }
311-
312- // Load issue labels for labels filter
313- if err := issue .LoadLabels (ctx ); err != nil {
314- log .Error ("LoadLabels: %v" , err )
315- return
316- }
317-
257+ // matchWorkflowsFilters checks if the issue matches all filters of the workflow
258+ func matchWorkflowsFilters (workflow * project_model.Workflow , issue * issues_model.Issue , columnID int64 ) bool {
318259 for _ , filter := range workflow .WorkflowFilters {
319260 switch filter .Type {
320261 case project_model .WorkflowFilterTypeIssueType :
@@ -324,35 +265,31 @@ func fireIssueWorkflow(ctx context.Context, workflow *project_model.Workflow, is
324265 }
325266 // Filter value can be "issue" or "pull_request"
326267 if filter .Value == "issue" && issue .IsPull {
327- return
268+ return false
328269 }
329270 if filter .Value == "pull_request" && ! issue .IsPull {
330- return
271+ return false
331272 }
332273 case project_model .WorkflowFilterTypeColumn :
333274 // If filter value is empty, match all columns
334275 if filter .Value == "" {
335276 continue
336277 }
337- columnID , _ := strconv .ParseInt (filter .Value , 10 , 64 )
338- if columnID == 0 {
278+ filterColumnID , _ := strconv .ParseInt (filter .Value , 10 , 64 )
279+ if filterColumnID == 0 {
339280 log .Error ("Invalid column ID: %s" , filter .Value )
340- return
341- }
342- issueProjectColumnID , err := issue .ProjectColumnID (ctx )
343- if err != nil {
344- log .Error ("Issue.ProjectColumnID: %v" , err )
345- return
281+ return false
346282 }
347- if issueProjectColumnID != columnID {
348- return
283+ // For column changed event, check against the new column ID
284+ if columnID > 0 && columnID != filterColumnID {
285+ return false
349286 }
350287 case project_model .WorkflowFilterTypeLabels :
351288 // Check if issue has the specified label
352289 labelID , _ := strconv .ParseInt (filter .Value , 10 , 64 )
353290 if labelID == 0 {
354291 log .Error ("Invalid label ID: %s" , filter .Value )
355- return
292+ return false
356293 }
357294 // Check if issue has this label
358295 hasLabel := false
@@ -363,15 +300,14 @@ func fireIssueWorkflow(ctx context.Context, workflow *project_model.Workflow, is
363300 }
364301 }
365302 if ! hasLabel {
366- return
303+ return false
367304 }
368305 default :
369306 log .Error ("Unsupported filter type: %s" , filter .Type )
370- return
307+ return false
371308 }
372309 }
373-
374- executeWorkflowActions (ctx , workflow , issue )
310+ return true
375311}
376312
377313func executeWorkflowActions (ctx context.Context , workflow * project_model.Workflow , issue * issues_model.Issue ) {
0 commit comments