In order to reduce the amount of time I spend on writing pull request instructions, I’ve been using Aider with OpenRouter to generate them.

How does it work?

Aider is a tool that uses AI to help you write code. It’s a chatbot that can help you write code, fix bugs, and even write tests.

OpenRouter is a tool that allows you to route requests to different APIs. In this case, we’ll use it to route the request to Aider.

With Aider we can run the following command to generate a pull request instruction:

aider \
  --model "openrouter/meta-llama/llama-3-8b-instruct:free" \
  --message="/ask Generate PR description from diff.log using INSTRUCTIONS.MD and PR_TEMPLATE.MD" \
  --read INSTRUCTIONS.MD \
  --read PR_TEMPLATE.MD \
  --read diff.log \
  --no-stream \
  --dry-run \
  --no-git

As you can see, we’re passing the model we want to use, the message we want to send to Aider, and the files we want to use to generate the pull request.

INSTRUCTIONS.MD is a file that contains the instructions for the pull request, i.e:

You are a Pull Request description generator.
You generate helpful pull request descriptions using the pull request template.
You inspect the diff and fill out the template appropriately.
You are concise, insightful, and accurate.
You double check your work.
You return the filled-out template in markdown.
How to section must be in the beginning in the how to test
In how to test, use the experiment values instead of the name of the constants

PR_TEMPLATE.MD is a file that contains the template for the pull request, i.e:

# Description:

- Provide a clear and concise description of the changes introduced in this pull request.
- Highlight key updates or features.

# Jira:

- [x] Related ticket: ENG-

# What areas of the site does it impact?

- (Describe what parts of the site are impacted and _if_ code updated other areas) Ex. Checkout, Redemption, Homepage

# Other Notes

- (Add any additional information that would be useful to the developer or QA tester)

# How to Test

- Best way to test?
- Is this part of an A/B test? (Give experiment slug & variants)
- What should the tester look out for?

# Visual changes (if applicable)

### - Before:

| Mobile              | Tablet              | Desktop              |
| ------------------- | ------------------- | -------------------- |
| <screenshot_mobile> | <screenshot_tablet> | <screenshot_desktop> |

### - After:

| Mobile              | Tablet              | Desktop              |
| ------------------- | ------------------- | -------------------- |
| <screenshot_mobile> | <screenshot_tablet> | <screenshot_desktop> |

# Developer Checklist

- [ ] I have performed self-review of my code
- [ ] I have added unit tests that prove my feature works
- [ ] I have confirmed all the PR checks pass
- [ ] I have added Reviewers to this PR on Github

# Rollback Plan

- [ ] I have a documented plan to deploy and roll back if there is an issue

diff.log is the file that contains the changes we made to the code (basically git diff > diff.log).

Script

To automate the process, I’ve created a script that runs the command above and saves the output to a file.

#!/bin/bash

PROVIDER="openrouter/"
MODEL="google/gemini-2.0-flash-exp:free"
script_dir="$(cd "$(dirname "$0")" && pwd)"

# Parse command line arguments
project="my-default-project-folder"  # Default project
while getopts "p:" opt; do
  case $opt in
    p)
      project="$OPTARG"
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      exit 1
      ;;
  esac
done

# Change to project directory
cd ~/projects/$project

# Ticket number to use in the PR template
branch_name=$(git rev-parse --abbrev-ref HEAD)
ticket_number=$(echo "$branch_name" | awk -F'/' '{print $2}')

# Generate diff file
git diff origin/develop...HEAD > "$script_dir/diff.log"

# Go to the path where the script is located
cd "$script_dir"

aider \
    --model "$PROVIDER$MODEL" \
    --cache-prompts \
    --message="/ask Generate PR description from diff.log using INSTRUCTIONS.MD and PR_TEMPLATE.MD (#$ticket_number)" \
    --read INSTRUCTIONS.MD \
    --read PR_TEMPLATE.MD \
    --read diff.log \
    --no-stream \
    --dry-run \
    --no-git \
    --no-show-model-warnings

Usage

This script is pretty specific to my needs:

  • All my projects are in the same folder called projects
  • Tickets numbers are in the branch name
  • The branch we compare to is develop

But you can use it as a starting point to create your own script.

# Run the script for the default project
./create-pr.sh

# Run the script for an specific project
./create-pr.sh -p my-project-folder