From f157e2035bc29c66c72fc6ac29fbe7199ef8f371 Mon Sep 17 00:00:00 2001 From: Joseph mearman Date: Tue, 1 Oct 2024 09:41:37 +0100 Subject: [PATCH 1/5] Add documentation for Automated GitHub PR Review Bot with Breadboard --- .../Breadboard/Phase 2/PR Reviewer.md | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 content/projects/Breadboard/Phase 2/PR Reviewer.md diff --git a/content/projects/Breadboard/Phase 2/PR Reviewer.md b/content/projects/Breadboard/Phase 2/PR Reviewer.md new file mode 100644 index 0000000..c79c97e --- /dev/null +++ b/content/projects/Breadboard/Phase 2/PR Reviewer.md @@ -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) + + + +## 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. From 5c34ca77eec47d9ad7d597158f6951ab14f241b5 Mon Sep 17 00:00:00 2001 From: Joseph mearman Date: Tue, 1 Oct 2024 09:43:33 +0100 Subject: [PATCH 2/5] Add pull_request trigger to build workflow --- .github/workflows/build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e6c68a8..6b3f63d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,6 +3,7 @@ name: Build, Test and Deploy on: push: workflow_dispatch: + pull_request: concurrency: cancel-in-progress: false From 7f33bda1c9fb99762acf3484f6a35a0358ce4682 Mon Sep 17 00:00:00 2001 From: Joseph mearman Date: Tue, 1 Oct 2024 09:44:10 +0100 Subject: [PATCH 3/5] Enable cancellation of in-progress builds for pull requests --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6b3f63d..d8b75b2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -6,7 +6,7 @@ on: pull_request: concurrency: - cancel-in-progress: false + cancel-in-progress: true group: ${{ github.workflow }}-${{ github.ref }} permissions: From 275975bd33a7de3e34a4f4cd1d4276f627283030 Mon Sep 17 00:00:00 2001 From: Joseph mearman Date: Tue, 1 Oct 2024 09:44:14 +0100 Subject: [PATCH 4/5] Configure deployment concurrency settings in build workflow --- .github/workflows/build.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d8b75b2..c0fb2d6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -125,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 From 1ae159f26d3efcf399da0dc8b4d725680093ce92 Mon Sep 17 00:00:00 2001 From: Joseph mearman Date: Tue, 1 Oct 2024 09:47:31 +0100 Subject: [PATCH 5/5] Remove TypeScript links from "Board for Each" and "Object Manipulator Board" documentation --- content/projects/Breadboard/Phase 2/Board for Each.md | 1 - content/projects/Breadboard/Phase 2/Object Manipulator Board.md | 1 - 2 files changed, 2 deletions(-) diff --git a/content/projects/Breadboard/Phase 2/Board for Each.md b/content/projects/Breadboard/Phase 2/Board for Each.md index 1161ccd..f66f077 100644 --- a/content/projects/Breadboard/Phase 2/Board for Each.md +++ b/content/projects/Breadboard/Phase 2/Board for Each.md @@ -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) diff --git a/content/projects/Breadboard/Phase 2/Object Manipulator Board.md b/content/projects/Breadboard/Phase 2/Object Manipulator Board.md index b237483..cfd357d 100644 --- a/content/projects/Breadboard/Phase 2/Object Manipulator Board.md +++ b/content/projects/Breadboard/Phase 2/Object Manipulator Board.md @@ -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