DEV Community

JB
JB

Posted on

AI Powered Automatic PR Body Generator

What I built

I built a GitHub Action that automatically generates and updates a pull request body on each push by feeding the diff to the Text Completion endpoint of OpenAI. The generated pull request bodies include a summary of the PR, a list of changes, as well as refactoring suggestions.

Category Submission:

Maintainer Must-Haves

App Link

https://github.com/marketplace/actions/ai-powered-automatic-pr-body-generation

Screenshots

Ai generated PR body 1

AI generated PR body 2

Description

The GitHub Action takes the diff of the changes made in a pull request and uses OpenAI to generate a summary of the changes. The summary includes information such as the files changed, lines added, and lines removed, as well as suggestions for refactoring the code. The pull request body is then updated with the summary on each push.

Link to Source Code

https://github.com/jbrocher/auto-pr-body-generator

Permissive License

MIT

Background (What made you decide to build this particular app? What inspired you?)

As a developer, I spend a lot of time writing pull request bodies manually, which can be a tedious task. However it is important to maintainers so they can quickly get a high level overview of a Pull Request. I think automating this process would bring benefits to both the person submitting the PR and the maintainers. With an automated system in place, the PR author can save time, while the maintainers can rest assured that they have all the relevant information they need to prioritize the PR they want to review.

I was also interested in exploring the capabilities of OpenAI and how it could be used to automate tasks in software development. This was a great way to do that!

How I built it (How did you utilize GitHub Actions or GitHub Codespaces? Did you learn something new along the way? Pick up a new skill?)

I used a composite Github Action and the Text Completion endpoint of OpenAI.

The diff can be of any length, and there is a limit on the number of tokens that can be submitted to OpenAI. To work around this, I split the diff into smaller chunks and combined and summarized the results by recursively feeding them to the completion endpoint.

The prompt needed to be engineered to provide more relevant information. I am still working on refining the prompts to improve the relevance of the refactoring suggestions. I'm discovering the world of prompt engineering, which is a lot of fun!

I'm still working on the project, and have a few next steps in mind:

  • Add a safeguard to limit the number of tokens processing credit spent by the action for a single run
  • Use more information from the PR to generate better prompts
  • Improve the prompt chaining to provide an accurate big picture for large pull requests
  • Improve the relevance of the refactoring suggestions. It should be possible to incorporates customizable coding style guides.

Additional Resources/Info

Top comments (1)

Collapse
 
sunishsurendrank profile image
Sunish Surendran K

I really like the way u thought about it