ProbableOdyssey | Blake Cook

Automating PR descriptions with the LLM CLI

· 2 min read · 270 words

Writing PR descriptions has always been the most tedious part of working with git for me. After expending a lot of effort on the change, reviewing the diff carefully, writing good commits throughout the process, the PR description feels like I’m backtracking.

A good PR description should tell the reviewer at a glance what the change entails, what to look out for, provide some justification for major choices made, and provide a bit of testing evidence. This is a crucial part of the process when working with git across a team.

The only part of this process that I get stuck on is writing the dang summary. As remarked by Blaise Pascal:

I have made this longer than usual because I have not had time to make it shorter.

A quote which is often paraphrased as

If I had more time, I would have written a shorter letter.

Sometimes all you need is a good draft to edit. Yet another application of the llm CLI, this alias in my ~/.gitconfig is one of my regular uses for LLMs:

[alias]
    genpr = "!f() { \
        target_branch=\"${1:-main}\"; \
        template_file=\".github/PULL_REQUEST_TEMPLATE.md\"; \
        template_arg=\"\"; \
        prompt='Generate a concise PR description from this diff.'; \
        if [ -f \"$template_file\" ]; then \
            template_arg=\"-f $template_file\"; \
            prompt=\"Fill in the PR template using this diff. Keep descriptions concise. \
            If template sections aren't applicable, leave blank\"; \
        fi; \
        git diff \"$target_branch\" | llm $template_arg \"$prompt\"; \
    }; f"

Usage:

git genpr           # vs main
git genpr develop   # vs develop
git genpr | pbcopy  # ready to paste into github

One command, ready-to-submit PR descriptions. What’s not to like?

Reply to this post by email blZake@proZbableodyssey.blog (remove Z characters) ↪