1
- const search = require ( './src/client.js' )
1
+ const { search, review , refactor } = require ( './src/client.js' )
2
2
const commands = require ( 'probot-commands-pro' )
3
3
4
4
module . exports = ( app ) => {
@@ -9,38 +9,52 @@ module.exports = (app) => {
9
9
return await context . octokit . issues . createComment ( issueComment )
10
10
} )
11
11
12
- app . on ( [ 'issues.opened' , 'issues.edited' ] , async ( context ) => {
12
+ commands ( app , 'chatgpt' , async ( context ) => {
13
13
if ( context . isBot )
14
14
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 )
28
23
} )
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 ) => {
30
33
if ( context . isBot )
31
34
return
32
35
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 )
45
45
} )
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
+ // })
46
60
} ;
0 commit comments