You want a GitHub Copilot agent to run automatically every time a pull request is opened against the main branch. The agent should analyze the diff and post a review comment. Which GitHub Actions workflow trigger and job configuration correctly invokes the agent in this CI context?
Select an answer to reveal the explanation.
Short Explanation
You want the agent to ring when someone arrives (PR opened/updated), not after they've already come inside (after merge). Use the pull_request trigger with types: [opened, synchronize], then pass the PR number and diff to the appropriate Copilot agent action. Running it post-merge defeats the purpose of a review.
Full Explanation
GitHub Actions workflows are event-driven. Selecting the correct trigger is the first step; then the job must properly invoke the agent with the right context.
The scheduled trigger with a cron expression that checks for open PRs every 15 minutes is incorrect. Scheduled polling every 15 minutes introduces latency, wastes compute on runs with no new PRs, and is complex to implement correctly (needing to fetch and iterate open PRs). It is not a real-time response to PR creation and is not the right pattern for CI review automation.
The pull_request trigger with types: [opened, synchronize] is correct. The pull_request event with types: [opened, synchronize] fires immediately when a PR is opened (opened) or when new commits are pushed to the PR branch (synchronize). This covers both the initial PR and subsequent updates. In the workflow job, call the agent step using the appropriate Copilot agent action, passing the PR number and diff as inputs. The agent step receives the PR context (number, head SHA, diff URL, etc.) via GitHub context variables (${{ github.event.pull_request.number }}, etc.) and uses these to fetch the diff and post review comments via the GitHub API. The agent action may use GITHUB_TOKEN with write permissions on pull-requests to post comments.
The repository_dispatch trigger with a custom event type agent-review is incorrect. repository_dispatch requires an external HTTP POST to trigger it. While valid for some automation scenarios, it requires the PR author to manually fire the event — which breaks the automatic CI review use case and creates friction. This trigger is designed for external system integration, not automatic PR review.
The push to main trigger is incorrect. The push to main event fires after the PR is merged. The code review agent running at this point cannot inform the merge decision. The review would be retroactive and the comment would appear on a merged PR branch, which is not the intended workflow.
Key pattern: on: pull_request for real-time PR review automation; pass PR context via GitHub Actions context expressions to the agent step.