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

make a rough draft of identifying if the bot already commented #364

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions utils/actions/detectConsoleLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,33 @@ export default async function detectConsoleLogs({
},
],
})
.then((result) => {
.then(async (result) => {
const openAIResult =
result.data.choices[0].message.content.split(",");

const addtionsHaveConsoleLog = openAIResult[0];
const individualLine = openAIResult[1];

if (addtionsHaveConsoleLog === "true") {
// Fetch all comments on the PR
const comments = await octokit.request(
"GET /repos/{owner}/{repo}/issues/{issue_number}/comments?sort=created&direction=desc",
{
owner,
repo,
issue_number,
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
}
);

const existingCommentsByBot = comments.data.filter(comment => {
return comment.path === file.filename &&
comment.position === getConsoleLogPosition &&
comment.user.login === "watermelon-copilot-for-code-review";
});

if (addtionsHaveConsoleLog === "true" && existingCommentsByBot.length === 0) {
const commentFileDiff = () => {

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.

return octokit
.request("GET /repos/{owner}/{repo}/pulls/{pull_number}", {
Expand Down Expand Up @@ -179,7 +198,7 @@ export default async function detectConsoleLogs({
{
path: file.filename,
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.",
body: "existingCommentsByBot - This file contains at least one console log. Please remove any present.",
},
],
}
Expand Down