Use Merged Pull Requests To Guide AI Reviews

Pull requests are likely to be similar to already merged pull requests.

Here is a neat little trick to simplify guiding AI code reviews. In addition to maintaining agent instructions for code reviews, tell the agent to find a similar already merged pull request, and apply the code review patterns to the current PR. For example, let's say in my repo, I merged a pull request that adds a console.log statement. In my PR review, I change the simple console.log to console.log(**text**) to mark the text as "bold".

The first pull request has console log with ** around the text

So let's say we open another pull request with the following change

1
2
3
  console.log('**hello**')

+ console.log('world!')

We can give our agent the following instructions via AGENTS.md or copilot-instructions.md file

1
2
3
4
5
6
7
8
9
10
When reviewing a pull request, first try finding a pull request merged within the last 90 days
in the same repository with work that modifies the same files or directories and addresses
the same type of change (for example, bug fix, refactor, or new feature).
If more than one matching pull request is found, use the most recently merged one.
If they conflict, state the conflict in the review and apply the approach from the most recent one.
Apply the coding style, test expectations, and review checklist demonstrated in that pull request,
and do not replicate any defects or deprecated patterns it contains. If no suitable merged pull
request is found or repository history is unavailable, review the pull request against
the repository's contributing guidelines and existing code conventions,
and state in the review that no reference pull request was used.

Without specifics, these instructions simply state:

  • find a similar already merged pull request
    • if found, apply the same patterns

That's it. Here is the result when I asked Copilot to perform the review in this repository:

The second pull request applies the pattern from the first PR

Nice.