Skip to content

Add documentation for Automated GitHub PR Review Bot with Breadboard #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ name: Build, Test and Deploy
on:
push:
workflow_dispatch:
pull_request:

concurrency:
cancel-in-progress: false
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}

permissions:
Expand Down Expand Up @@ -124,6 +125,9 @@ jobs:
# preview: true

deploy:
concurrency:
cancel-in-progress: false
group: ${{ github.workflow }}-${{ github.ref }}-deploy
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs:
- build
Expand Down
1 change: 0 additions & 1 deletion content/projects/Breadboard/Phase 2/Board for Each.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ The "Board for Each" is a versatile tool designed to simplify data processing ta

This board is used with the [Object Manipulator Board](projects/Breadboard/Phase%202/Object%20Manipulator%20Board.md) in the [Simple Hacker News Search](projects/Breadboard/Phase%202/Hacker%20News/simplified/Simple%20Hacker%20News%20Search.md) board to remove unnecessary attributes from the results array.

- [TypeScript](https://github.com/breadboard-ai/breadboard/blob/main/packages/example-boards/src/boards/playground/board-for-each.ts)
- [JSON](https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/visual-editor/public/example-boards/playground/board-for-each.json)
- [Open in Breadboard Web](https://breadboard-ai.web.app/?board=https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/visual-editor/public/example-boards/playground/board-for-each.json)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ This board is used in the [Simple Hacker News Search](projects/Breadboard/Phase%

## Source

- [TypeScript](https://github.com/breadboard-ai/breadboard/blob/main/packages/example-boards/src/boards/playground/object-manipulator.ts)
- [JSON](https://github.com/breadboard-ai/breadboard/blob/main/packages/visual-editor/public/example-boards/playground/object-manipulator.json)

## Breadboard Web
Expand Down
97 changes: 97 additions & 0 deletions content/projects/Breadboard/Phase 2/PR Reviewer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
title: Automated GitHub PR Review Bot with Breadboard
aliases: []
tags:
- board
- breadboard
created: 2024-10-01T08:36:22Z
modified: 2024-10-01T08:36:22Z
---

# Demo: Automated GitHub PR Review Bot with Breadboard

![](https://youtu.be/Fmm_dn2bXcU)

<iframe src="https://breadboard-ai.web.app/?board=https://exadev.github.io/boards/breadboard-pr-bot.bgl.json&embed" style="width: 100%; height: 500px; border: 0;"></iframe>

## Introduction

Welcome! In this demo, we'll showcase a GitHub Pull Request (PR) bot created using [Breadboard](https://breadboard-ai.github.io/breadboard). This bot automates code reviews by analyzing PR diffs and posting comments directly on GitHub, helping developers identify and address issues efficiently.

## Overview of the GitHub PR Bot

The GitHub PR bot leverages Breadboard to:

- **Fetch the diff** of a public repository's PR.
- **Analyze the changes** using a Language Model (LM).
- **Generate insightful comments** on the PR.
- **Automatically post** these comments to GitHub using the GitHub API.

## Setting Up the Bot

To use the bot, you'll need to provide the following:

1. **Personal Access Token (PAT)**: Used for authentication with the GitHub API. This should be supplied securely using secrets.
2. **Project Owner**: The GitHub username or organization that owns the repository.
3. **Project Name**: The name of the repository.
4. **PR Number**: The number of the pull request you want to review.

### Supplying the Personal Access Token

Ensure that your PAT has the necessary permissions to read and write comments on PRs. Keep your token secure by using environment variables or secret management features provided by Breadboard.

## Demonstration

### The Sample Repository

For this demo, we'll use a simple C program that prints numbers from an array sequentially. The code resides in a public GitHub repository.

### Creating a PR with Issues

We've created a PR that modifies the program to use a linked list instead of a static array. However, we've intentionally introduced some issues by using ChatGPT to generate suboptimal code. This allows the bot to identify and comment on these issues.

## Using Breadboard to Review the PR

With the bot set up, we'll input the required information:

- **Project Owner**: `username`
- **Project Name**: `sample-c-project`
- **PR Number**: `2`

The bot follows these steps:

1. **Fetches the PR diff** from the repository.
2. **Processes the diff** through an LM to analyze the code changes.
3. **Generates comments** highlighting potential issues or improvements.
4. **Posts the comments** to the PR via the GitHub API.

## Reviewing the Bot's Comments

After the bot completes its review, we can visit the PR to see the new comments:

1. **Comment on Node Creation**:
- *"Consider using a loop to create nodes rather than creating each node individually. This will make your code more efficient and scalable."*

**Original Code Snippet:**

```c
// Creating nodes individually without a loop
Node* node1 = (Node*)malloc(sizeof(Node));
node1->data = 1;
node1->next = NULL;

Node* node2 = (Node*)malloc(sizeof(Node));
node2->data = 2;
node2->next = NULL;

// ... and so on
```

2. **Comment on Memory Management**:
- *"It's important to free allocated memory to avoid memory leaks. Please ensure you free the memory after use."*

This is crucial in C programming to prevent memory leaks, which can lead to increased memory usage and potential crashes.

## Conclusion

This demo illustrates how the GitHub PR bot built with Breadboard can automate code reviews, providing valuable feedback directly on your PRs. By integrating a Language Model for code analysis, the bot helps maintain code quality and saves developers time.