Skip to content

Commit ba7e27a

Browse files
committed
refactor: review code
1 parent 73e781d commit ba7e27a

10 files changed

+315
-65
lines changed

.dockerignore

-12
This file was deleted.

Dockerfile

-8
This file was deleted.

app.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ default_events:
3535
# - project_card
3636
# - project_column
3737
# - public
38-
# - pull_request
38+
- pull_request
3939
- pull_request_review
4040
- pull_request_review_comment
4141
# - push

example/case.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// callback hell example
2+
app.get("/details", function (req, res) {
3+
var name = req.query.name;
4+
console.log(name);
5+
6+
Scopus.find({ name: name },
7+
{ '_id': 0, 'authorId': 1 },
8+
function (err, result) {
9+
if (err) { }
10+
else {
11+
var searchResult = result[0]["authorId"];
12+
console.log(searchResult);
13+
var options = {
14+
url: "https://api.elsevier.com/content/author/author_id/"
15+
+ searchResult + "?apiKey",
16+
headers: { 'Accept': 'application/json' }
17+
};
18+
request(options, function (error, response, body) {
19+
if (error) {
20+
21+
// Print the error if one occurred
22+
console.error('error in Authors :', error);
23+
24+
// Print the response status code if a response was received
25+
console.log('statusCode:', response && response.statusCode);
26+
res.send("error")
27+
}
28+
else if (!error) {
29+
var jsonObj = JSON.parse(body);
30+
if (jsonObj['author-retrieval-response'] == undefined) {
31+
res.send("No details");
32+
}
33+
else {
34+
var reqData = jsonObj['author-retrieval-response'][0];
35+
var authprofile = reqData["author-profile"]
36+
var names = authprofile["preferred-name"]["indexed-name"]
37+
console.log(names);
38+
var citation = reqData["coredata"]["citation-count"];
39+
var query = { authorId: searchResult };
40+
41+
Scopus.findOneAndUpdate(query, {
42+
name: names,
43+
citationCount: citation
44+
}, function (err, doc, res) {
45+
if (err) {
46+
console.log("error");
47+
}
48+
else {
49+
console.log("success");
50+
}
51+
})
52+
res.render("details", { data: reqData });
53+
}
54+
}
55+
});
56+
}
57+
})
58+
});

example/react.tsx

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { useState } from 'react'
2+
import { Button } from '@mui/material'
3+
import reactLogo from '@/assets/react.svg'
4+
import '@/App.css'
5+
6+
function App() {
7+
const [count, setCount] = useState(0)
8+
9+
return (
10+
<div className="App">
11+
<div>
12+
<a href="https://vitejs.dev" target="_blank">
13+
<img src="/vite.svg" className="logo" alt="Vite logo" />
14+
</a>
15+
<a href="https://reactjs.org" target="_blank">
16+
<img src={reactLogo} className="logo react" alt="React logo" />
17+
</a>
18+
</div>
19+
<h1>Vite + React + Redux + RTK + Rect-router + Typescript + MUI 5</h1>
20+
<Button color="secondary">Secondary</Button>
21+
<Button variant="contained" color="success">
22+
Success
23+
</Button>
24+
<Button variant="outlined" color="error">
25+
Error
26+
</Button>
27+
<div className="card">
28+
<button onClick={() => setCount(count => count + 1)}>
29+
count is {count}
30+
</button>
31+
<p>
32+
Edit <code>src/App.tsx</code> and save to test HMR
33+
</p>
34+
</div>
35+
<p className="read-the-docs">
36+
Click on the Vite and React logos to learn more
37+
</p>
38+
</div>
39+
)
40+
}
41+
42+
export default App

index.js

+42-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const search = require('./src/client.js')
1+
const { search, review, refactor } = require('./src/client.js')
22
const commands = require('probot-commands-pro')
33

44
module.exports = (app) => {
@@ -9,38 +9,52 @@ module.exports = (app) => {
99
return await context.octokit.issues.createComment(issueComment)
1010
})
1111

12-
app.on(['issues.opened', 'issues.edited'], async (context) => {
12+
commands(app, 'chatgpt', async (context) => {
1313
if (context.isBot)
1414
return
15-
const { issue } = context.payload
16-
// if the robot is mentioned in the issue body, reponse with a greeting
17-
if (
18-
issue
19-
&& issue.body
20-
&& issue.body.includes(`/chatgpt`)
21-
) {
22-
const response = await search(issue.body)
23-
const issueComment = context.issue({
24-
body: response,
25-
})
26-
return await context.octokit.issues.createComment(issueComment)
27-
}
15+
const { comment, issue } = context.payload
16+
const { body } = comment || issue
17+
const prompt = body.replace('/chatgpt', '').trim()
18+
const response = await search(prompt)
19+
const issueComment = context.issue({
20+
body: response,
21+
})
22+
return await context.octokit.issues.createComment(issueComment)
2823
})
29-
app.on(['issue_comment.created'], async (context) => {
24+
25+
// wip: review code from code & add test
26+
// https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue
27+
app.on('issues.opened', async (context) => { })
28+
// configure something
29+
app.on(['installation'], async (context) => { })
30+
31+
// add test && review && refactor
32+
app.on(['pull_request_review_comment'], async (context) => {
3033
if (context.isBot)
3134
return
3235
const { comment } = context.payload
33-
// if the robot is mentioned in the issue body, reponse with a greeting
34-
if (
35-
comment
36-
&& comment.body
37-
&& comment.body.includes(`/chatgpt`)
38-
) {
39-
const response = await search(comment.body)
40-
const issueComment = context.issue({
41-
body: response,
42-
})
43-
return await context.octokit.issues.createComment(issueComment)
44-
}
36+
const { body, diff_hunk } = comment || issue
37+
38+
if (!body.includes(`/review`)) return
39+
const prompt = body.replace('/review', '').trim()
40+
const response = await review({ prompt, lang: 'javascript', code: diff_hunk })
41+
const issueComment = context.issue({
42+
body: response,
43+
})
44+
return await context.octokit.issues.createComment(issueComment)
4545
})
46+
47+
// app.on(['issue_comment.created', 'issue_comment.edited', 'issues.opened', 'issues.edited'], async (context) => {
48+
// if (context.isBot)
49+
// return
50+
// const { comment, issue } = context.payload
51+
// const { body } = comment || issue
52+
// if (!body.includes(`/chatgpt`)) return
53+
// const prompt = body.replace('/chatgpt', '').trim()
54+
// const response = await search(prompt)
55+
// const issueComment = context.issue({
56+
// body: response,
57+
// })
58+
// return await context.octokit.issues.createComment(issueComment)
59+
// })
4660
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@antfu/eslint-config": "^0.33.1",
2929
"@rollup/plugin-commonjs": "^23.0.3",
3030
"@rollup/plugin-node-resolve": "^15.0.1",
31+
"@rollup/plugin-terser": "^0.2.0",
3132
"eslint": "^8.29.0",
3233
"jest": "^29.0.0",
3334
"nock": "^13.0.5",

0 commit comments

Comments
 (0)