Skip to content

Commit

Permalink
refactor: review code
Browse files Browse the repository at this point in the history
  • Loading branch information
oceanlvr committed Dec 7, 2022
1 parent 73e781d commit ba7e27a
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 65 deletions.
12 changes: 0 additions & 12 deletions .dockerignore

This file was deleted.

8 changes: 0 additions & 8 deletions Dockerfile

This file was deleted.

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
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 });
}
}
});
}
})
});
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
70 changes: 42 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const search = require('./src/client.js')
const { search, review, refactor } = require('./src/client.js')
const commands = require('probot-commands-pro')

module.exports = (app) => {
Expand All @@ -9,38 +9,52 @@ module.exports = (app) => {
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 } = context.payload
const { body } = comment || issue
const prompt = body.replace('/chatgpt', '').trim()
const response = await search(prompt)
const issueComment = context.issue({
body: 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
app.on('issues.opened', async (context) => { })
// configure something
app.on(['installation'], async (context) => { })

// add test && review && refactor
app.on(['pull_request_review_comment'], 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 { body, diff_hunk } = comment || issue

if (!body.includes(`/review`)) return
const prompt = body.replace('/review', '').trim()
const response = await review({ prompt, lang: 'javascript', code: diff_hunk })
const issueComment = context.issue({
body: response,
})
return await context.octokit.issues.createComment(issueComment)
})

// app.on(['issue_comment.created', 'issue_comment.edited', 'issues.opened', 'issues.edited'], async (context) => {
// if (context.isBot)
// return
// const { comment, issue } = context.payload
// const { body } = comment || issue
// if (!body.includes(`/chatgpt`)) return
// const prompt = body.replace('/chatgpt', '').trim()
// const response = await search(prompt)
// const issueComment = context.issue({
// body: 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

0 comments on commit ba7e27a

Please sign in to comment.