DEV Community

Eray Gündoğmuş
Eray Gündoğmuş

Posted on

GPT-4 and GitHub Actions for PR Review Automation: AI Code Reviewer

banner

Pull request reviews generally involve exchanging ideas with team members to improve code quality, passing our written code through a pipeline with certain automation tools, and allow us to use our time more efficiently and systematically.

Following advancements in artificial intelligence, I thought, why not benefit from AI in an area as crucial for software development teams as "Pull request review?" After some research, I came across a solution: AI Code Reviewer.

AI Code Reviewer is an innovative tool that can perform automatic code reviews for pull requests in an integrated manner with GitHub Actions using OpenAI's GPT-4 technology. This tool is designed to facilitate the software development process and offers developers valuable feedback by intelligently identifying potential issues and improvement opportunities in their code. AI Code Reviewer examines pull requests in real time, provides detailed suggestions for code changes, and makes customizable comments. It also focuses only on important areas by excluding certain files and patterns. This tool is an ideal solution for teams looking to enhance code quality and manage development processes efficiently.

I am aware that there are tools like SonarQube that analyze code quality, control rules, and patterns. However, AI Code Reviewer offers a different approach by providing more dynamic and context-sensitive automatic reviews in pull requests using OpenAI's GPT-4 technology.

While SonarQube detects overall code quality and security vulnerabilities through static code analysis, AI Code Reviewer provides customizable and interactive feedback by examining code changes in real time and integrates with GitHub. Therefore, it can be said that both tools serve different needs in the software development process and complement each other.

Setup

To use AI Code Reviewer in GitHub Actions, obtain an OpenAI API key.
Save the OpenAI API key as a GitHub Secret value named OPENAI_API_KEY.

openai_api_key

  1. Create a folder named ".github" and add another folder named "workflows." Then create a file named "[name].yml" inside it and paste the following content into the file.
name: AI Code Reviewer

on:
  pull_request:
    types:
      - opened
      - synchronize
permissions: write-all
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3

      - name: AI Code Reviewer
        uses: your-username/ai-codereviewer@main
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          OPENAI_API_MODEL: "gpt-4" # Optional: defaults to "gpt-4"
          exclude: "**/*.json, **/*.md" # Optional: exclude patterns separated by commas
Enter fullscreen mode Exit fullscreen mode

example

Actually that's all! Now:

  • Customize the "exclude" feature to specify files you don't want to be reviewed.
  • Commit your changes. Now, AI Code Reviewer will be working on your next pull request.

Thanks to this tool, we will now receive AI support before our team members and make the job easier for those who will review.

example

Wishing everyone good work.

About me
As a frontend engineer with a passion for open-source work, I take pride in my ability to deliver high-quality results to clients. My experience and expertise have equipped me with the skills needed to develop innovative solutions that exceed expectations. As an active member of the tech community, I value the importance of open communication, continuous learning, and collaboration. If you're interested in learning more about my work or how I can contribute to your project, feel free to connect with me.

Top comments (0)