-
Notifications
You must be signed in to change notification settings - Fork 12
Feature/comment specific line diffs #331
Changes from 8 commits
7a0e1a2
c1a3152
bae6af8
96b341b
4104c95
9712d3a
86c6f71
7473a1a
b50c65d
b229e09
753f96b
8a164cb
268cf9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <iostream> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this console log - recent sha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console log - todays sha hardcoded filenmae There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console log - todays sha hardcoded filenmae There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console log - todays sha hardcoded filenmae There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console log - todays sha hardcoded filenmae There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console log - c1a toString There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. response.data.head.sha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this console log There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add more information here, and fix this typo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No body - Please add more information here, and fix this typo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file contains at least one console log. Please remove any present. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("hello world"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. response.data.head.sha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this console log There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add more information here, and fix this typo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No body - Please add more information here, and fix this typo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file contains at least one console log. Please remove any present. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print("This line will be printed.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this console log - old sha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this console log - old sha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove console log - c1a toString There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. response.data.head.sha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this console log There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add more information here, and fix this typo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file contains at least one console log. Please remove any present. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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 { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response.data.head.sha