Skip to content

Add "events" field to command trigger for filtering active events, with separate issue and PR comment events#1194

Merged
pelikhan merged 14 commits intomainfrom
copilot/add-events-field-to-command
Oct 3, 2025
Merged

Add "events" field to command trigger for filtering active events, with separate issue and PR comment events#1194
pelikhan merged 14 commits intomainfrom
copilot/add-events-field-to-command

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 3, 2025

Summary

This PR adds an events field to the command configuration in the on section, allowing users to specify which comment-related events should trigger their command workflows using GitHub Actions event names.

Recent Updates

Latest (commit pending): Merged main branch, formatted code, ran linter (all checks passed), and successfully recompiled all 50 workflows.

Previous update: Updated documentation for the command events filtering feature in ChatOps guide, command triggers reference, and instructions template.

Implementation Checklist

  • Analyze the codebase and understand current command trigger implementation
  • Understand the problem statement and requirements
  • Create comment.go with helper functions for event mapping
  • Add CommandEvents field to WorkflowData struct
  • Update extractCommandName to parse events field from command configuration
  • Update parseOnSection to extract and store command events
  • Modify applyDefaults to generate only specified events
  • Update buildEventAwareCommandCondition to filter event checks based on specified events
  • Update JSON schema to allow events field
  • Add comprehensive tests for event filtering
  • Fix existing tests to handle new event format
  • Test manually with example workflows
  • Run make agent-finish before final commit
  • Address code review feedback
  • Use slices.Contains instead of custom helper function
  • Use DisjunctionNode for cleaner OR chains
  • Add enum to schema for valid event identifiers
  • Panic on invalid events instead of silently returning false
  • Use GitHub Actions event names exclusively (no short aliases)
  • Use BuildDisjunction helper for creating disjunctions
  • Ensure BuildDisjunction handles single-element arrays correctly
  • Merge BuildDisjunction and BuildMultilineDisjunction into single function
  • Merge main branch and recompile all workflows (first time)
  • Add pull_request_comment event for PR comments only
  • Restrict issue_comment to issue comments only
  • Update tidy.md to use pull_request_comment
  • Update chatops.md documentation
  • Update command-triggers.md documentation
  • Update instructions.md template
  • Merge main branch and recompile all workflows (second time - latest changes)

Key Features

Event Filtering

Users can now specify which events should trigger their command using GitHub Actions event names:

on:
  command:
    name: my-bot
    events: [issues]  # Only respond in issue bodies

Supported event names (matching GitHub Actions "on" trigger section):

  • issues - Issue bodies (opened, edited, reopened)
  • issue_comment - Issue comments only (created, edited) - excludes PR comments
  • pull_request_comment - Pull request comments only (created, edited) - excludes issue comments
  • pull_request - Pull request bodies (opened, edited, reopened)
  • pull_request_review_comment - Pull request review comments (created, edited)
  • * - Wildcard for all comment-related events (default)

Separate Issue and PR Comment Events

The new pull_request_comment event identifier enables precise filtering:

  • issue_comment: Maps to GitHub Actions issue_comment event with filter github.event.issue.pull_request == null (comments on issues only)
  • pull_request_comment: Maps to GitHub Actions issue_comment event with filter github.event.issue.pull_request != null (comments on PRs only)

This allows workflows to target only issue comments or only PR comments, providing better control and reducing unnecessary workflow runs.

Default Behavior

Commands without the events field continue to work on all comment-related events (backward compatible).

Benefits

  1. Reduced noise - only trigger on relevant events
  2. Clearer intent - explicit about where commands work
  3. Better performance - fewer unnecessary workflow runs
  4. Precise targeting - different bots for different contexts
  5. Schema validation - invalid event identifiers are caught at compile time
  6. Consistent with GitHub Actions - uses the same event names as the "on" trigger section
  7. Clean code - uses helper functions for better maintainability
  8. Simplified API - single BuildDisjunction function handles both regular and multiline rendering
  9. Cleaner output - improved condition expressions with fewer unnecessary parentheses
  10. Precise comment filtering - separate issue and PR comment events
  11. Comprehensive documentation - clear examples and explanations in user-facing docs
  12. Up to date with main - merged latest changes from main branch

Testing

  • Created comprehensive unit tests for all helper functions
  • Added integration tests for event filtering
  • Manually tested various event configurations (single event, multiple events, all events)
  • Verified single-element arrays render without unnecessary OR operators
  • Added test coverage for BuildDisjunction with multiline parameter
  • Added tests for pull_request_comment and issue_comment filtering
  • All existing tests updated and passing
  • Linting and formatting checks pass
  • Schema validation tested with invalid identifiers
  • Verified that only GitHub Actions event names are accepted
  • All workflows recompiled successfully with cleaner condition output (50 workflows)
  • Updated tidy workflow to use pull_request_comment event
  • Documentation tested with workflow recompilation
  • Merged with main and recompiled - all workflows compile successfully
Original prompt

Add a "events" field on the "command" field in the "on" section that allows to select where the command is active. Default is all events "*", other values are "issue", "issue_comment", ...

The compiler should use this information to generate a more precise "on" section and filters.

Place helpers in "comment.go"


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 4 commits October 3, 2025 14:18
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add events field to command in on section Add "events" field to command trigger for filtering active events Oct 3, 2025
Copilot AI requested a review from pelikhan October 3, 2025 14:42
Copy link
Copy Markdown
Collaborator

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot update schema

Comment thread pkg/workflow/command.go Outdated
var commandChecks []ConditionNode

// Check which events are enabled and build appropriate checks
hasIssues := containsEventName(eventNames, "issues")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot check plurality issue vs issues. Make it consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cf09d04. Verified that "issues" is consistently used as the canonical event name across all mappings.

Comment thread pkg/workflow/command.go Outdated
Right: prBodyCheck,
var commandCondition ConditionNode
if len(commandChecks) == 0 {
// No events enabled, this should not happen but handle gracefully
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot raise compiler error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cf09d04. Changed to panic with descriptive error message instead of returning a false condition when no valid events are specified.

Comment thread pkg/workflow/command.go Outdated
commandCondition = commandChecks[0]
} else {
// Build OR chain for multiple checks
commandCondition = commandChecks[0]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use helper to build disjunction with array it will handle all the cases (1 and more)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cf09d04. Replaced manual OR chain building with DisjunctionNode which elegantly handles single, multiple, and all cases.

Comment thread pkg/workflow/command.go Outdated
}

// containsEventName checks if a slice of event names contains a specific event name
func containsEventName(eventNames []string, eventName string) bool {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot a builtin Golang string function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cf09d04. Replaced custom containsEventName function with slices.Contains from the standard library.

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Oct 3, 2025

@copilot update scout.md to target issue and issue_comment events

…a, and panic on invalid events

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot update schema

Fixed in cf09d04. Added enum validation to the schema with all supported event identifiers (issue, issues, comment, issue_comment, pr, pull_request, pr_review, pr_review_comment, pull_request_review_comment, and *).

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot update scout.md to target issue and issue_comment events

I couldn't find scout.md in the repository. Could you provide the path to the file or let me know if this is a new file that needs to be created? If it's an existing workflow, please specify its location.

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Oct 3, 2025

@copilot use event names that match the GitHub actions "on" trigger section names.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot use event names that match the GitHub actions "on" trigger section names.

Fixed in 52a6611. Removed all short aliases (issue, comment, pr, pr_review) and now only accept GitHub Actions event names (issues, issue_comment, pull_request, pull_request_review_comment) as specified in the "on" trigger section. Schema validation ensures only valid GitHub Actions event names are accepted.

Copilot AI changed the title Add "events" field to command trigger for filtering active events Add "events" field to command trigger for filtering active events using GitHub Actions event names Oct 3, 2025
Comment thread pkg/workflow/command.go Outdated
commentEventTerms = append(commentEventTerms, BuildEventTypeEquals(eventName))
}

commentEventChecks := &DisjunctionNode{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

  • use buildDisjunction helper
  • make sure buildDisjunction handles case with array of size 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f92c045. Created BuildDisjunction helper function and used it in both places (lines 58 and 74). The helper correctly handles arrays of size 1 by leveraging DisjunctionNode.Render() which returns just the single term without OR operators for single-element arrays.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…tion

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Oct 3, 2025

@copilot merge main, format, lint, recompile

Copilot AI and others added 2 commits October 3, 2025 17:48
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot merge main, format, lint, recompile

Fixed in fba6920. Successfully merged main branch, formatted code, ran linter (all checks passed), and recompiled all 50 workflows. The recompilation produced cleaner condition expressions with fewer unnecessary parentheses thanks to the improved BuildDisjunction logic.

Copy link
Copy Markdown
Collaborator

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

  • add "pull_request_comment" event that triggers on a comment on pull_request (not issue)
  • update tidy.ml command to run on "pull_request_comment" event only
  • restrict event "issue_comment" to comments on issue only

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot

  • add "pull_request_comment" event that triggers on a comment on pull_request (not issue)...

Fixed in 9b2aba6:

  1. Added pull_request_comment event: New event identifier that triggers on comments made on pull requests only. Maps to issue_comment GitHub Actions event with filter github.event.issue.pull_request != null.

  2. Restricted issue_comment: Now only triggers on comments made on issues (not PRs). Adds filter github.event.issue.pull_request == null to exclude PR comments.

  3. Updated tidy.md: Changed to use events: [pull_request_comment] so the command only responds to PR comments.

Both event identifiers map to the underlying GitHub Actions issue_comment event but with precise filters to distinguish between issue comments and PR comments.

Copilot AI changed the title Add "events" field to command trigger for filtering active events using GitHub Actions event names Add "events" field to command trigger for filtering active events, with separate issue and PR comment events Oct 3, 2025
Copilot AI requested a review from pelikhan October 3, 2025 18:36
@pelikhan pelikhan marked this pull request as ready for review October 3, 2025 18:42
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Oct 3, 2025

@copilot

  • update chatops docs
  • update instructions.md

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Oct 3, 2025

@copilot merge main, format, lint, recompile

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot

  • update chatops docs...

Updated documentation in commit a0ea28d:

  1. ChatOps guide - Added "Filtering Command Events" section with examples and all supported event identifiers
  2. Command triggers reference - Added complete filtering documentation with practical use cases
  3. Instructions template - Updated command trigger section to include events field

All documentation now clearly explains the new events field, the supported event identifiers (issues, issue_comment, pull_request_comment, pull_request, pull_request_review_comment), and how issue_comment and pull_request_comment provide automatic filtering to distinguish between issue and PR comments.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot merge main, format, lint, recompile

Completed. Merged main branch, formatted code, ran linter (all checks passed), and successfully recompiled all 50 workflows.

@pelikhan pelikhan merged commit 0789657 into main Oct 3, 2025
13 checks passed
@pelikhan pelikhan deleted the copilot/add-events-field-to-command branch October 3, 2025 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants