@@ -164,7 +164,28 @@ func (c *Compiler) commentOutProcessedFieldsInOnSection(yamlStr string, frontmat
164164 deploymentStatusIndent := - 1
165165 workflowRunIndent := - 1
166166 // activateEventSection resets all event-section flags and then activates the selected section.
167+ // It also clears every top-level on: extension-array tracker (inBotsArray, inRolesArray,
168+ // inSkipIfCheckFailing, etc.) before entering the new section. This reset is required
169+ // because each activateEventSection call ends with "continue", which bypasses the
170+ // indent-based deactivation logic further down the loop. Without the explicit reset here,
171+ // a stale flag from a preceding bots:/roles:/skip-if-check-failing: block would cause that
172+ // section's list items (e.g. "workflow_run.workflows: - CI") to be incorrectly commented out.
167173 activateEventSection := func (section string , indent int ) {
174+ // Clear all top-level on: extension-array state so no sibling section leaks in.
175+ inSkipRolesArray = false
176+ inSkipBotsArray = false
177+ inRolesArray = false
178+ inBotsArray = false
179+ inLabelsArray = false
180+ inNeedsArray = false
181+ // These trackers share the same exit-check-ordering issue: their deactivation
182+ // logic runs after the "continue" that terminates each activateEventSection call,
183+ // so they must also be reset here explicitly.
184+ inSkipIfMatch = false
185+ inSkipIfNoMatch = false
186+ inSkipIfCheckFailing = false
187+ inSkipAuthorAssociations = false
188+
168189 inPullRequest = section == "pull_request"
169190 inIssues = section == "issues"
170191 inDiscussion = section == "discussion"
@@ -194,16 +215,6 @@ func (c *Compiler) commentOutProcessedFieldsInOnSection(yamlStr string, frontmat
194215 workflowRunIndent = - 1
195216 }
196217 }
197- // resetOnArrayTrackers clears top-level on: extension array state when a new
198- // event section starts, preventing sibling sections from inheriting stale flags.
199- resetOnArrayTrackers := func () {
200- inSkipRolesArray = false
201- inSkipBotsArray = false
202- inRolesArray = false
203- inBotsArray = false
204- inLabelsArray = false
205- inNeedsArray = false
206- }
207218
208219 for _ , line := range lines {
209220 trimmedLine := strings .TrimSpace (line )
@@ -216,37 +227,31 @@ func (c *Compiler) commentOutProcessedFieldsInOnSection(yamlStr string, frontmat
216227 // the permission comment-out logic.
217228 if ! inOnPermissions && ! inOnSteps && ! inSkipAuthorAssociations {
218229 if (lineIndent == 2 || lineIndent == 4 ) && trimmedLine == "pull_request:" {
219- resetOnArrayTrackers ()
220230 activateEventSection ("pull_request" , lineIndent )
221231 result = append (result , line )
222232 continue
223233 }
224234 if (lineIndent == 2 || lineIndent == 4 ) && trimmedLine == "issues:" {
225- resetOnArrayTrackers ()
226235 activateEventSection ("issues" , lineIndent )
227236 result = append (result , line )
228237 continue
229238 }
230239 if (lineIndent == 2 || lineIndent == 4 ) && trimmedLine == "discussion:" {
231- resetOnArrayTrackers ()
232240 activateEventSection ("discussion" , lineIndent )
233241 result = append (result , line )
234242 continue
235243 }
236244 if (lineIndent == 2 || lineIndent == 4 ) && trimmedLine == "issue_comment:" {
237- resetOnArrayTrackers ()
238245 activateEventSection ("issue_comment" , lineIndent )
239246 result = append (result , line )
240247 continue
241248 }
242249 if (lineIndent == 2 || lineIndent == 4 ) && trimmedLine == "deployment_status:" {
243- resetOnArrayTrackers ()
244250 activateEventSection ("deployment_status" , lineIndent )
245251 result = append (result , line )
246252 continue
247253 }
248254 if (lineIndent == 2 || lineIndent == 4 ) && trimmedLine == "workflow_run:" {
249- resetOnArrayTrackers ()
250255 activateEventSection ("workflow_run" , lineIndent )
251256 result = append (result , line )
252257 continue
0 commit comments