mirror of
				https://github.com/freeedcom/ai-codereviewer.git
				synced 2025-10-31 06:00:53 +00:00 
			
		
		
		
	Merge pull request #7 from arunsnt/use-gpt-3-5
Fix the bot to add review comments
This commit is contained in:
		
				commit
				
					
						28b461dd62
					
				
			
		
					 3 changed files with 38 additions and 11 deletions
				
			
		
							
								
								
									
										19
									
								
								dist/index.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								dist/index.js
									
										
									
									
										vendored
									
									
								
							|  | @ -128,8 +128,7 @@ Git diff to review: | ||||||
| \`\`\`diff
 | \`\`\`diff
 | ||||||
| ${chunk.content} | ${chunk.content} | ||||||
| ${chunk.changes | ${chunk.changes | ||||||
|         // @ts-expect-error - ln and ln2 exists where needed
 |         .map((c) => `${'ln' in c ? c.ln : 'ln2' in c ? c.ln2 : ''} ${c.content}`) | ||||||
|         .map((c) => `${c.ln ? c.ln : c.ln2} ${c.content}`) |  | ||||||
|         .join("\n")} |         .join("\n")} | ||||||
| \`\`\` | \`\`\` | ||||||
| `;
 | `;
 | ||||||
|  | @ -182,10 +181,24 @@ function createComment(file, chunk, aiResponses) { | ||||||
|         if (!file.to) { |         if (!file.to) { | ||||||
|             return []; |             return []; | ||||||
|         } |         } | ||||||
|  |         const lineNumber = Number(aiResponse.lineNumber); | ||||||
|  |         // Find the matching change in the chunk
 | ||||||
|  |         const change = chunk.changes.find((c) => { | ||||||
|  |             if ("ln" in c && c.ln === lineNumber) | ||||||
|  |                 return true; | ||||||
|  |             if ("ln2" in c && c.ln2 === lineNumber) | ||||||
|  |                 return true; | ||||||
|  |             return false; | ||||||
|  |         }); | ||||||
|  |         if (!change) { | ||||||
|  |             console.error(`Line number ${aiResponse.lineNumber} not found in the diff for file ${file.to}`); | ||||||
|  |             return []; | ||||||
|  |         } | ||||||
|  |         const commentLine = "ln" in change ? change.ln : "ln2" in change ? change.ln2 : 0; | ||||||
|         return { |         return { | ||||||
|             body: aiResponse.reviewComment, |             body: aiResponse.reviewComment, | ||||||
|             path: file.to, |             path: file.to, | ||||||
|             line: Number(aiResponse.lineNumber), |             line: commentLine, | ||||||
|         }; |         }; | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								dist/index.js.map
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js.map
									
										
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										28
									
								
								src/main.ts
									
										
									
									
									
								
							
							
						
						
									
										28
									
								
								src/main.ts
									
										
									
									
									
								
							|  | @ -2,7 +2,7 @@ import { readFileSync } from "fs"; | ||||||
| import * as core from "@actions/core"; | import * as core from "@actions/core"; | ||||||
| import OpenAI from "openai"; | import OpenAI from "openai"; | ||||||
| import { Octokit } from "@octokit/rest"; | import { Octokit } from "@octokit/rest"; | ||||||
| import parseDiff, { Chunk, File } from "parse-diff"; | import parseDiff, { Chunk, File, Change } from "parse-diff"; | ||||||
| import minimatch from "minimatch"; | import minimatch from "minimatch"; | ||||||
| 
 | 
 | ||||||
| const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN"); | const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN"); | ||||||
|  | @ -87,9 +87,7 @@ function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string { | ||||||
| - Use the given description only for the overall context and only comment the code. | - Use the given description only for the overall context and only comment the code. | ||||||
| - IMPORTANT: NEVER suggest adding comments to the code. | - IMPORTANT: NEVER suggest adding comments to the code. | ||||||
| 
 | 
 | ||||||
| Review the following code diff in the file "${ | Review the following code diff in the file "${file.to}" and take the pull request title and description into account when writing the response. | ||||||
|     file.to |  | ||||||
|   }" and take the pull request title and description into account when writing the response. |  | ||||||
|    |    | ||||||
| Pull request title: ${prDetails.title} | Pull request title: ${prDetails.title} | ||||||
| Pull request description: | Pull request description: | ||||||
|  | @ -103,8 +101,7 @@ Git diff to review: | ||||||
| \`\`\`diff
 | \`\`\`diff
 | ||||||
| ${chunk.content} | ${chunk.content} | ||||||
| ${chunk.changes | ${chunk.changes | ||||||
|   // @ts-expect-error - ln and ln2 exists where needed
 |   .map((c) => `${'ln' in c ? c.ln : 'ln2' in c ? c.ln2 : ''} ${c.content}`) | ||||||
|   .map((c) => `${c.ln ? c.ln : c.ln2} ${c.content}`) |  | ||||||
|   .join("\n")} |   .join("\n")} | ||||||
| \`\`\` | \`\`\` | ||||||
| `;
 | `;
 | ||||||
|  | @ -173,10 +170,27 @@ function createComment( | ||||||
|     if (!file.to) { |     if (!file.to) { | ||||||
|       return []; |       return []; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     const lineNumber = Number(aiResponse.lineNumber); | ||||||
|  | 
 | ||||||
|  |     // Find the matching change in the chunk
 | ||||||
|  |     const change = chunk.changes.find((c) => { | ||||||
|  |       if ("ln" in c && c.ln === lineNumber) return true; | ||||||
|  |       if ("ln2" in c && c.ln2 === lineNumber) return true; | ||||||
|  |       return false; | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     if (!change) { | ||||||
|  |       console.error(`Line number ${aiResponse.lineNumber} not found in the diff for file ${file.to}`); | ||||||
|  |       return []; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const commentLine = "ln" in change ? change.ln : "ln2" in change ? change.ln2 : 0; | ||||||
|  | 
 | ||||||
|     return { |     return { | ||||||
|       body: aiResponse.reviewComment, |       body: aiResponse.reviewComment, | ||||||
|       path: file.to, |       path: file.to, | ||||||
|       line: Number(aiResponse.lineNumber), |       line: commentLine, | ||||||
|     }; |     }; | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue