Skip to content

Commit

Permalink
feat: add skeleton backend
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemccoll committed Mar 10, 2023
1 parent 1042c6a commit b89e875
Show file tree
Hide file tree
Showing 20 changed files with 11,392 additions and 5,626 deletions.
32 changes: 7 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
# reviewbot

> A GitHub App to assist with code reviews via AI.
A bot that assists with code reviews, using AI.

## Setup
## Usage

```sh
# Install dependencies
npm install

# Run the bot
npm start
Install the Github app and use the following command:
```

## Docker

```sh
# 1. Build container
docker build -t reviewbot .

# 2. Start container
docker run -e APP_ID=<app-id> -e PRIVATE_KEY=<pem-value> reviewbot
/reviewbot review
```

## Contributing

If you have suggestions for how reviewbot could be improved, or want to report a bug, open an issue! We'd love all and any contributions.

For more, check out the [Contributing Guide](CONTRIBUTING.md).

## License
## Services

[ISC](LICENSE) © 2023 richiemccoll
- `backend` (contains the reviewbot service + transformer API interactions)
- `github-app` (contains the probot service that interacts with Github + `backend`)
17 changes: 17 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Fastify from "fastify";

function app() {
const fastify = Fastify({
logger: {
transport: {
target: "pino-pretty",
},
},
});

fastify.register(import("./routes/review.js"));

return fastify;
}

export default app;
23 changes: 23 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "backend",
"version": "1.0.0",
"description": "Reviewbot backend service",
"type": "module",
"main": "index.js",
"scripts": {
"dev": "node --watch server.js &"
},
"repository": {
"type": "git",
"url": "git+https://github.com/richiemccoll/reviewbot.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/richiemccoll/reviewbot/issues"
},
"homepage": "https://github.com/richiemccoll/reviewbot#readme",
"dependencies": {
"fastify": "^4.14.1"
}
}
29 changes: 29 additions & 0 deletions backend/routes/review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import promptEngine from "../services/prompt-engine.js";
import suggestions from "../services/suggestions.js";

export default async function review(fastify) {
fastify.post(
"/review",
{
schema: {
response: {
200: {
description: "Success Response",
type: "object",
properties: {
message: { type: "string" },
},
},
},
},
},
async (request) => {
const dynamicPrompt = promptEngine.build(request.body);
const response = await suggestions.create({
transformerType: "chatGPT",
payload: dynamicPrompt,
});
return response;
}
);
}
5 changes: 5 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import app from "./index.js";

const fastify = app();

await fastify.listen({ port: 4000 });
5 changes: 5 additions & 0 deletions backend/services/prompt-engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const promptEngine = {
build() {},
};

export default promptEngine;
12 changes: 12 additions & 0 deletions backend/services/suggestions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const suggestions = {
async create({ transformerType, payload }) {
switch (transformerType) {
case "chatGPT": {
// handle ChatGPT
console.log("handle chat gpt");
}
}
},
};

export default suggestions;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions github-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# reviewbot

> A GitHub App to assist with code reviews via AI.
## Setup

```sh
# Install dependencies
npm install

# Run the bot
npm start
```

## Docker

```sh
# 1. Build container
docker build -t reviewbot .

# 2. Start container
docker run -e APP_ID=<app-id> -e PRIVATE_KEY=<pem-value> reviewbot
```

## Contributing

If you have suggestions for how reviewbot could be improved, or want to report a bug, open an issue! We'd love all and any contributions.

For more, check out the [Contributing Guide](CONTRIBUTING.md).

## License

[ISC](LICENSE) © 2023 richiemccoll
File renamed without changes.
69 changes: 69 additions & 0 deletions github-app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* This is the main entrypoint to the Probot app
* @param {import('probot').Probot} app
*/
module.exports = async (app) => {
app.log.info("[reviewbot] - server started");

/* For the MVP, it's fine to just listen for this event.
In the future, we would want to handle different scenarios such as:
- issue_comment.edited
- pull_request_review_comment.created
- pull_request_review_comment.edited */

app.on("issue_comment.created", async (context) => {
if (context.payload.sender.login === "reviewbot-ai[bot]") {
return;
}

try {
const issue = context.issue();
const { body } = context.payload.comment;

const botCall = "/reviewbot review";
if (body.indexOf(botCall) === -1) {
return;
}

app.log.info("[reviewbot] - getting git diff for files changed");

const pullRequest = context.pullRequest();
const { data } = await context.octokit.pulls.listFiles({
owner: issue.owner,
repo: issue.repo,
pull_number: pullRequest.pull_number,
});

app.log.info("[reviewbot] - ack author comment");

await context.octokit.reactions.createForIssueComment({
content: "eyes",
comment_id: context.payload.comment.id,
owner: issue.owner,
repo: issue.repo,
});

app.log.info("[reviewbot] - scheduling review request");

// Create a review request
const payload = data.map((file) => ({
filename: file.filename,
patch: file.patch,
}));

const response = await fetch(process.env.REVIEWBOT_SERVICE, {
method: "POST",
body: JSON.stringify(payload),
});

if (response.status !== 200) {
app.log.error("[reviewbot] - error scheduling review request");
throw new Error(
`received status code ${response.status} instead of 201`
);
}
} catch (error) {
app.log.error(`[reviewbot] - encountered an error - ${error.message}`);
}
});
};
Loading

0 comments on commit b89e875

Please sign in to comment.