forked from nearform/reviewbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1042c6a
commit b89e875
Showing
20 changed files
with
11,392 additions
and
5,626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const promptEngine = { | ||
build() {}, | ||
}; | ||
|
||
export default promptEngine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
}); | ||
}; |
Oops, something went wrong.