Skip to content
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

Review #7

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 0 additions & 12 deletions .dockerignore

This file was deleted.

8 changes: 0 additions & 8 deletions Dockerfile

This file was deleted.

23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
# ChatGPT ProBot

A ChatGPT-based GitHub APP. Type `/chatgpt` to chat with robot 🤖️
[![Release Version](https://img.shields.io/github/release/oceanlvr/ChatGPTBot.svg)](https://github.com/oceanlvr/ChatGPTBot/releases/latest) ![Twitter](https://img.shields.io/twitter/follow/AdaMeta1?style=social)

[![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/apps/chatgptbot) [![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/oceanlvr/ChatGPTBot)

A ChatGPT-based GitHub APP. Type `/chatgpt` to chat with robot 🤖️.

![hello](./assets/Hi.jpg)

Powered by [Probot](https://github.com/probot/probot) & [chatgpt-api](https://github.com/transitive-bullshit/chatgpt-api)

## Deploy your own APP
## Usage

**Try on [issue#1](https://github.com/oceanlvr/ChatGPT-ProBot/issues/1)**

[![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/oceanlvr/ChatGPTBot)
**Try Review/Refactor on [PR#7](https://github.com/oceanlvr/ChatGPT-ProBot/pull/7)**

| event | description | example |
| ----------- | --------------------------------- | --------------------------------------- |
| `/ping` | ping robot status | |
| `/chatgpt` | chat with bot on issue/PR comment | /chatgpt who are you? |
| `/review` | auto review code in the PR | /review fix the callback hell problem |
| `/refactor` | refactor the code | /refactor fix the callback hell problem |

## Deploy your own APP

1. [Install & Configure the GitHub App](https://github.com/apps/chatgptbot)
2. Create `.env` file following `example.env`, please check config section in your [GitHub apps page](https://github.com/settings/apps)
1. `APP_ID/PRIVATE_KEY/GITHUB_CLIENT_SECRET/GITHUB_CLIENT_ID` is required, please check [chatgptbot settings](https://github.com/settings/apps/chatgptbot) and fill them.
2. **`PRIVATE_KEY` is required, it should be encoded by `base64`**.(`console.log(Buffer.from(<PRIVATE_KEY>).toString('base64'))`).
3. `SESSION_TOKEN` is required, it is generated by `ChatGPT` [website](https://chat.openai.com/chat). You can get it following [this step](https://github.com/transitive-bullshit/chatgpt-api#how-it-works).
3. Vercel Deploy (**recommend**), click [![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/oceanlvr/ChatGPTBot) to clone deploy. Copy `.env` file environment to vercel app [environment-variables](https://vercel.com/docs/concepts/projects/environment-variables) in setting page (for me it's `https://vercel.com/oceanlvr/chatgptbot/settings/environment-variables`)
4. Edit the webhooks URL to `${vercelAPPURL}/api/github/webhooks`. For me it's https://chatgptbot.vercel.app/api/github/webhooks
4. Edit the webhooks URL to `${vercelAPPURL}/api/github/webhooks`. For me it's <https://chatgptbot.vercel.app/api/github/webhooks>
5. Type `/chatgpt` in an issue, chat with the bot

*step4: update webhook URL to your vercel app domain.*
Expand Down
2 changes: 1 addition & 1 deletion app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ default_events:
# - project_card
# - project_column
# - public
# - pull_request
- pull_request
- pull_request_review
- pull_request_review_comment
# - push
Expand Down
Binary file added assets/review.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions example/case.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// callback hell example
app.get("/details", function (req, res) {
var name = req.query.name;
console.log(name);

Scopus.find({ name: name },
{ '_id': 0, 'authorId': 1 },
function (err, result) {
if (err) { }
else {
var searchResult = result[0]["authorId"];
console.log(searchResult);
var options = {
url: "https://api.elsevier.com/content/author/author_id/"
+ searchResult + "?apiKey",
headers: { 'Accept': 'application/json' }
};
request(options, function (error, response, body) {
if (error) {

// Print the error if one occurred
console.error('error in Authors :', error);

// Print the response status code if a response was received
console.log('statusCode:', response && response.statusCode);
res.send("error")
}
else if (!error) {
var jsonObj = JSON.parse(body);
if (jsonObj['author-retrieval-response'] == undefined) {
res.send("No details");
}
else {
var reqData = jsonObj['author-retrieval-response'][0];
var authprofile = reqData["author-profile"]
var names = authprofile["preferred-name"]["indexed-name"]
console.log(names);
var citation = reqData["coredata"]["citation-count"];
var query = { authorId: searchResult };

Scopus.findOneAndUpdate(query, {
name: names,
citationCount: citation
}, function (err, doc, res) {
if (err) {
console.log("error");
}
else {
console.log("success");
}
})
res.render("details", { data: reqData });
}
}
});
}
})
});
oceanlvr marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 42 additions & 0 deletions example/react.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useState } from 'react'
import { Button } from '@mui/material'
import reactLogo from '@/assets/react.svg'
import '@/App.css'

function App() {
const [count, setCount] = useState(0)

return (
<div className="App">
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" className="logo" alt="Vite logo" />
</a>
<a href="https://reactjs.org" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React + Redux + RTK + Rect-router + Typescript + MUI 5</h1>
<Button color="secondary">Secondary</Button>
<Button variant="contained" color="success">
Success
</Button>
<Button variant="outlined" color="error">
Error
</Button>
<div className="card">
<button onClick={() => setCount(count => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</div>
)
}

export default App
63 changes: 34 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
const search = require('./src/client.js')
const { search, review, refactor } = require('./src/client.js')
const commands = require('probot-commands-pro')

module.exports = (app) => {
commands(app, 'ping', async (context) => {
const issueComment = context.issue({
body: 'pong',
body: '🤖️: pong',
})
return await context.octokit.issues.createComment(issueComment)
})

app.on(['issues.opened', 'issues.edited'], async (context) => {
commands(app, 'chatgpt', async (context) => {
if (context.isBot)
return
const { issue } = context.payload
// if the robot is mentioned in the issue body, reponse with a greeting
if (
issue
&& issue.body
&& issue.body.includes(`/chatgpt`)
) {
const response = await search(issue.body)
const issueComment = context.issue({
body: response,
})
return await context.octokit.issues.createComment(issueComment)
}
const { comment, issue, sender } = context.payload
const { body } = comment || issue
const prompt = body.replace('/chatgpt', '').trim()
const response = await search(prompt)
const issueComment = context.issue({
body: `@${sender.login} 🤖️: ${response}`,
})
return await context.octokit.issues.createComment(issueComment)
})
app.on(['issue_comment.created'], async (context) => {

// WIP: review code from code & add test
// https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue
//['issue_comment.created', 'issue_comment.edited', 'issues.opened', 'issues.edited']

// configure something
app.on(['installation'], async (context) => { })

app.on(['pull_request_review_comment.created'], async (context) => {
if (context.isBot)
return
const { comment } = context.payload
// if the robot is mentioned in the issue body, reponse with a greeting
if (
comment
&& comment.body
&& comment.body.includes(`/chatgpt`)
) {
const response = await search(comment.body)
const issueComment = context.issue({
body: response,
})
return await context.octokit.issues.createComment(issueComment)
const { comment, sender } = context.payload
const { body, diff_hunk } = comment
const eventHandlerMap = {
'/review': review,
'/refactor': refactor,
}
const event = Object.keys(eventHandlerMap).find((key) => body.includes(key))
if (!event) return

const prompt = body.replace(event, '').trim()
const response = await eventHandlerMap[event]({ prompt, lang: 'javascript', code: diff_hunk })
const issueComment = context.issue({
body: `@${sender.login} 🤖️: ${response}`,
})
return await context.octokit.issues.createComment(issueComment)
})
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@antfu/eslint-config": "^0.33.1",
"@rollup/plugin-commonjs": "^23.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.2.0",
"eslint": "^8.29.0",
"jest": "^29.0.0",
"nock": "^13.0.5",
Expand Down
Loading