mirror of
				https://github.com/freeedcom/ai-codereviewer.git
				synced 2025-10-31 22:20:53 +00:00 
			
		
		
		
	Merge pull request #14 from arunsnt/CICO-111286
CICO-111286: Fix error and more logs
This commit is contained in:
		
				commit
				
					
						14d4fe7bb3
					
				
			
		
					 3 changed files with 60 additions and 40 deletions
				
			
		
							
								
								
									
										23
									
								
								dist/index.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								dist/index.js
									
										
									
									
										vendored
									
									
								
							|  | @ -467,7 +467,7 @@ function createComment(file, chunk, aiResponses) { | |||
|         }; | ||||
|     }); | ||||
| } | ||||
| function createReviewComment(owner, repo, pull_number, comments) { | ||||
| function createReviewComment(owner, repo, pull_number, comments, commit_id) { | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
|         const validComments = comments.filter(comment => comment.path && comment.line > 0 && comment.body.trim() !== ""); | ||||
|         if (validComments.length === 0) { | ||||
|  | @ -475,13 +475,17 @@ function createReviewComment(owner, repo, pull_number, comments) { | |||
|             return; | ||||
|         } | ||||
|         console.log("Attempting to create review comments:", JSON.stringify(validComments, null, 2)); | ||||
|         for (const comment of validComments) { | ||||
|             try { | ||||
|             yield octokit.pulls.createReview({ | ||||
|                 yield octokit.pulls.createReviewComment({ | ||||
|                     owner, | ||||
|                     repo, | ||||
|                     pull_number, | ||||
|                 comments: validComments, | ||||
|                 event: "COMMENT", | ||||
|                     body: comment.body, | ||||
|                     path: comment.path, | ||||
|                     line: comment.line, | ||||
|                     side: 'RIGHT', | ||||
|                     commit_id, // Include commit_id in the request
 | ||||
|                 }); | ||||
|             } | ||||
|             catch (error) { | ||||
|  | @ -490,10 +494,11 @@ function createReviewComment(owner, repo, pull_number, comments) { | |||
|                     owner, | ||||
|                     repo, | ||||
|                     pull_number, | ||||
|                 comments: validComments, | ||||
|                 event: "COMMENT", | ||||
|                     comment, | ||||
|                     commit_id, | ||||
|                 }); | ||||
|             } | ||||
|         } | ||||
|     }); | ||||
| } | ||||
| function main() { | ||||
|  | @ -502,8 +507,10 @@ function main() { | |||
|         const prDetails = yield getPRDetails(); | ||||
|         let diff; | ||||
|         const eventData = JSON.parse((0, fs_1.readFileSync)((_a = process.env.GITHUB_EVENT_PATH) !== null && _a !== void 0 ? _a : "", "utf8")); | ||||
|         let commit_id; | ||||
|         if (eventData.action === "opened") { | ||||
|             diff = yield getDiff(prDetails.owner, prDetails.repo, prDetails.pull_number); | ||||
|             commit_id = eventData.pull_request.head.sha; | ||||
|         } | ||||
|         else if (eventData.action === "synchronize") { | ||||
|             const newBaseSha = eventData.before; | ||||
|  | @ -518,6 +525,7 @@ function main() { | |||
|                 head: newHeadSha, | ||||
|             }); | ||||
|             diff = String(response.data); | ||||
|             commit_id = newHeadSha; | ||||
|         } | ||||
|         else { | ||||
|             console.log("Unsupported event:", process.env.GITHUB_EVENT_NAME); | ||||
|  | @ -539,7 +547,8 @@ function main() { | |||
|         const existingComments = yield getExistingComments(prDetails.owner, prDetails.repo, prDetails.pull_number); | ||||
|         const comments = yield analyzeCode(filteredDiff, prDetails, existingComments); | ||||
|         if (comments.length > 0) { | ||||
|             yield createReviewComment(prDetails.owner, prDetails.repo, prDetails.pull_number, comments); | ||||
|             yield createReviewComment(prDetails.owner, prDetails.repo, prDetails.pull_number, comments, commit_id // Pass commit_id to the function
 | ||||
|             ); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										2
									
								
								dist/index.js.map
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js.map
									
										
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										25
									
								
								src/main.ts
									
										
									
									
									
								
							
							
						
						
									
										25
									
								
								src/main.ts
									
										
									
									
									
								
							|  | @ -474,7 +474,8 @@ async function createReviewComment( | |||
|     owner: string, | ||||
|     repo: string, | ||||
|     pull_number: number, | ||||
|     comments: Array<{ body: string; path: string; line: number }> | ||||
|     comments: Array<{ body: string; path: string; line: number }>, | ||||
|     commit_id: string | ||||
| ): Promise<void> { | ||||
|   const validComments = comments.filter(comment => comment.path && comment.line > 0 && comment.body.trim() !== ""); | ||||
| 
 | ||||
|  | @ -485,13 +486,17 @@ async function createReviewComment( | |||
| 
 | ||||
|   console.log("Attempting to create review comments:", JSON.stringify(validComments, null, 2)); | ||||
| 
 | ||||
|   for (const comment of validComments) { | ||||
|     try { | ||||
|     await octokit.pulls.createReview({ | ||||
|       await octokit.pulls.createReviewComment({ | ||||
|         owner, | ||||
|         repo, | ||||
|         pull_number, | ||||
|       comments: validComments, | ||||
|       event: "COMMENT", | ||||
|         body: comment.body, | ||||
|         path: comment.path, | ||||
|         line: comment.line, | ||||
|         side: 'RIGHT', // Ensure the comment is on the right side of the diff
 | ||||
|         commit_id, // Include commit_id in the request
 | ||||
|       }); | ||||
|     } catch (error) { | ||||
|       console.error("Error creating review comment:", error); | ||||
|  | @ -499,10 +504,11 @@ async function createReviewComment( | |||
|         owner, | ||||
|         repo, | ||||
|         pull_number, | ||||
|       comments: validComments, | ||||
|       event: "COMMENT", | ||||
|         comment, | ||||
|         commit_id, | ||||
|       }); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| async function main() { | ||||
|  | @ -512,12 +518,15 @@ async function main() { | |||
|       readFileSync(process.env.GITHUB_EVENT_PATH ?? "", "utf8") | ||||
|   ); | ||||
| 
 | ||||
|   let commit_id: string; | ||||
| 
 | ||||
|   if (eventData.action === "opened") { | ||||
|     diff = await getDiff( | ||||
|         prDetails.owner, | ||||
|         prDetails.repo, | ||||
|         prDetails.pull_number | ||||
|     ); | ||||
|     commit_id = eventData.pull_request.head.sha; | ||||
|   } else if (eventData.action === "synchronize") { | ||||
|     const newBaseSha = eventData.before; | ||||
|     const newHeadSha = eventData.after; | ||||
|  | @ -533,6 +542,7 @@ async function main() { | |||
|     }); | ||||
| 
 | ||||
|     diff = String(response.data); | ||||
|     commit_id = newHeadSha; | ||||
|   } else { | ||||
|     console.log("Unsupported event:", process.env.GITHUB_EVENT_NAME); | ||||
|     return; | ||||
|  | @ -570,7 +580,8 @@ async function main() { | |||
|         prDetails.owner, | ||||
|         prDetails.repo, | ||||
|         prDetails.pull_number, | ||||
|         comments | ||||
|         comments, | ||||
|         commit_id // Pass commit_id to the function
 | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue