Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Fix indexing issue for the single line file border-case (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
baristaGeek authored Oct 30, 2023
1 parent 78eac4c commit 8d8c315
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 12 additions & 0 deletions app/api/actions/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,18 @@ export async function POST(request: Request) {
});
textToWrite += randomText();

// Detect console.logs and its equivalent in other languages
await detectConsoleLogs({
prTitle: title,
businessLogicSummary,
repo,
owner,
issue_number: number,
installationId,
reqUrl: request.url,
reqEmail: req.email,
});

// Make Watermelon Review the PR's business logic here by comparing the title with the AI-generated summary
await labelPullRequest({
prTitle: title,
Expand Down
14 changes: 8 additions & 6 deletions utils/actions/detectConsoleLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ function getConsoleLogPosition(filePatchAndIndividualLine: any) {

// get the position of the indiviudalLine in th filePatch
const lines = filePatch.split("\n");
for (let i = 0; i < lines.length; i++) {
for (let i = 1; i < lines.length; i++) {
if (lines[i].includes(individualLine)) {
positionInDiff = i + 1;
positionInDiff = i;
break;
}
}
Expand Down Expand Up @@ -159,6 +159,11 @@ export default async function detectConsoleLogs({
.then((result) => {
const latestCommitHash = result.data.head.sha;

const consoleLogPosition = getConsoleLogPosition({
filePatch: file.patch ?? "",
individualLine
})

return octokit.request(
"POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews",
{
Expand All @@ -171,10 +176,7 @@ export default async function detectConsoleLogs({
comments: [
{
path: file.filename,
position: getConsoleLogPosition({
filePatch: file.patch ?? "",
individualLine
}) || 1, // comment at the beggining of the file by default
position: consoleLogPosition || 1, // comment at the beggining of the file by default
body: "This file contains at least one console log. Please remove any present.",
},
],
Expand Down

0 comments on commit 8d8c315

Please sign in to comment.