1- const search = require ( './src/client.js' )
1+ const { search, review , refactor } = require ( './src/client.js' )
22const commands = require ( 'probot-commands-pro' )
33
44module . 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} ;
0 commit comments