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

Feature/comment specific line diffs #331

Merged
merged 13 commits into from
Oct 26, 2023
Merged
6 changes: 6 additions & 0 deletions test_hello_worlds/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.data.head.sha

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present. - additions.length


int main() {
std::cout << "Hello World!";
return 0;
}
3 changes: 3 additions & 0 deletions test_hello_worlds/hello.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this console log - recent sha

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log - todays sha hardcoded filenmae

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log - todays sha hardcoded filenmae

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log - todays sha hardcoded filenmae

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log - todays sha hardcoded filenmae

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log - c1a toString

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.data.head.sha

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this console log

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present. - additions.length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more information here, and fix this typo.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No body - Please add more information here, and fix this typo.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

head.sha - This file contains at least one console log. Please remove any present.

EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
println!("Hello World!");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getConsoleLogPosition - This file contains at least one console log. Please remove any present.

1 change: 1 addition & 0 deletions test_hello_worlds/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("hello world");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.data.head.sha

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this console log

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present. - additions.length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more information here, and fix this typo.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No body - Please add more information here, and fix this typo.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

head.sha - This file contains at least one console log. Please remove any present.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getConsoleLogPosition - This file contains at least one console log. Please remove any present.

EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions test_hello_worlds/python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("This line will be printed.")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this console log - old sha

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this console log - old sha

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console log - c1a toString

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.data.head.sha

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this console log

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present. - additions.length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more information here, and fix this typo.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

head.sha - This file contains at least one console log. Please remove any present.

EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
76 changes: 64 additions & 12 deletions utils/actions/detectConsoleLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
missingParamsResponse,
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
} from "../../utils/api/responses";
import validateParams from "../../utils/api/validateParams";
import { Octokit } from "octokit";

const configuration = new Configuration({
apiKey: process.env.OPEN_AI_KEY,
Expand Down Expand Up @@ -67,6 +68,22 @@ function getAdditions(filePatch: string) {
return lines.join("\n");
}

function getConsoleLogPosition(filePatchAndIndividualLine: any) {
let positionInDiff = 1;
const { filePatch, individualLine } = filePatchAndIndividualLine;

// get the position of the indiviudalLine in th filePatch
const lines = filePatch.split("\n");
for (let i = 0; i < lines.length; i++) {
if (lines[i].includes(individualLine)) {
positionInDiff = i + 1;
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}

return positionInDiff;
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
}

export default async function detectConsoleLogs({
installationId,
owner,
Expand Down Expand Up @@ -107,7 +124,10 @@ export default async function detectConsoleLogs({
Python comments start with #.
Other console functions such as console.info() shouldn't be counted as console logs.
Ignore code comments from this analysis.
If there is a console log, print "true", else print "false"`;
If there is a console log, return "true", else return "false".
If you return true, return an object that that has 2 props: result and line.
The line value, is the actual line in the file that contains the console log.
For example: { result: true, line: console.log("hello world");}`;

// detect if the additions contain console logs or not
try {
Expand All @@ -122,19 +142,51 @@ export default async function detectConsoleLogs({
],
})
.then((result) => {
const addtionsHaveConsoleLog = result.data.choices[0].message.content;
const openAIResult = result.data.choices[0].message.content;
const addtionsHaveConsoleLog = openAIResult.result;
const indiviudalLine = openAIResult.line;

console.log("additionsHaveConsoleLog", addtionsHaveConsoleLog);
console.log("indiviudalLine", indiviudalLine);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getConsoleLogPosition - This file contains at least one console log. Please remove any present.


if (addtionsHaveConsoleLog === "true") {
// comment detailing which file has the console log detected
return octokit.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
{
owner,
repo,
issue_number,
body: `This PR contains console logs in file ${file.filename}. Please remove them.`,
}
);
const commentFileDiff = () => {
return octokit
.request("GET /repos/{owner}/{repo}/pulls/{pull_number}", {
owner,
repo,
pull_number: issue_number,
})
.then((result) => {
const latestCommitHash = result.data.head.sha;

let individualLine = "";

return octokit.request(
"POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews",
{
owner,
repo,
pull_number: issue_number,
commit_id: result.data.head.sha,
event: "REQUEST_CHANGES",
EstebanDalelR marked this conversation as resolved.
Show resolved Hide resolved
path: file.filename,
comments: [
{
path: file.filename,
position: getConsoleLogPosition({
filePatch: file.patch ?? "",
individualLine
}) || 1, // comment at the beggining of the file by default
body: "getConsoleLogPosition - This file contains at least one console log. Please remove any present.",
},
],
}
);
});
};

commentFileDiff();
}
});
} catch {}
Expand Down