@@ -89,6 +89,8 @@ function analyzeCode(parsedDiff, prDetails) {
8989 return __awaiter(this, void 0, void 0, function* () {
9090 const comments = [];
9191 for (const file of parsedDiff) {
92+ if (file.to === "/dev/null")
93+ continue; // Ignore deleted files
9294 for (const chunk of file.chunks) {
9395 const prompt = createPrompt(file, chunk, prDetails);
9496 const aiResponse = yield getAIResponse(prompt);
@@ -103,12 +105,25 @@ function analyzeCode(parsedDiff, prDetails) {
103105 return comments;
104106 });
105107}
108+ function getBaseAndHeadShas(owner, repo, pull_number) {
109+ return __awaiter(this, void 0, void 0, function* () {
110+ const prResponse = yield octokit.pulls.get({
111+ owner,
112+ repo,
113+ pull_number,
114+ });
115+ return {
116+ baseSha: prResponse.data.base.sha,
117+ headSha: prResponse.data.head.sha,
118+ };
119+ });
120+ }
106121function createPrompt(file, chunk, prDetails) {
107122 return `- Provide the response in following JSON format: [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]
108123- Do not give positive comments or compliments.
109- - Do not recommend adding comments to the code.
124+ - NEVER suggest adding a comment explaining the code.
110125- Provide comments and suggestions ONLY if there is something to improve, otherwise return an empty array.
111- - Write the comment in GitHub markdown .
126+ - Write the comment in GitHub Markdown format .
112127- Use the given description only for the overall context and only comment the code.
113128
114129Review the following code diff in the file "${file.to}" and take the pull request title and description into account when writing the response.
@@ -181,10 +196,34 @@ function createReviewComment(owner, repo, pull_number, comments) {
181196 });
182197 });
183198}
184- (function main() {
199+ function main() {
200+ var _a;
185201 return __awaiter(this, void 0, void 0, function* () {
186202 const prDetails = yield getPRDetails();
187- const diff = yield getDiff(prDetails.owner, prDetails.repo, prDetails.pull_number);
203+ let diff;
204+ const eventData = JSON.parse((0, fs_1.readFileSync)((_a = process.env.GITHUB_EVENT_PATH) !== null && _a !== void 0 ? _a : "", "utf8"));
205+ if (eventData.action === "opened") {
206+ diff = yield getDiff(prDetails.owner, prDetails.repo, prDetails.pull_number);
207+ }
208+ else if (eventData.action === "synchronize") {
209+ const newBaseSha = eventData.before;
210+ const newHeadSha = eventData.after;
211+ const response = yield octokit.repos.compareCommits({
212+ owner: prDetails.owner,
213+ repo: prDetails.repo,
214+ base: newBaseSha,
215+ head: newHeadSha,
216+ });
217+ diff = response.data.diff_url
218+ ? yield octokit
219+ .request({ url: response.data.diff_url })
220+ .then((res) => res.data)
221+ : null;
222+ }
223+ else {
224+ console.log("Unsupported event:", process.env.GITHUB_EVENT_NAME);
225+ return;
226+ }
188227 if (!diff) {
189228 console.log("No diff found");
190229 return;
@@ -202,7 +241,8 @@ function createReviewComment(owner, repo, pull_number, comments) {
202241 yield createReviewComment(prDetails.owner, prDetails.repo, prDetails.pull_number, comments);
203242 }
204243 });
205- })().catch((error) => {
244+ }
245+ main().catch((error) => {
206246 console.error("Error:", error);
207247 process.exit(1);
208248});
0 commit comments