Skip to content

Line by line comments #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jul 27, 2023
Merged

Line by line comments #37

merged 28 commits into from
Jul 27, 2023

Conversation

lizacullis
Copy link
Contributor

No description provided.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 25, 2023

LOGAF Level 3 - /home/runner/work/code-review-gpt/code-review-gpt/src/test/run/runTest.ts

  1. The function runTest throws an error if no similar reviews are found for a test case. This could potentially stop the execution of the remaining test cases. Consider handling this case differently, for example by returning a failed test result.
if (similarityResponse.length === 0) {
  return { success: false, reason: "No similar reviews found" };
}
  1. The function runTests catches an error for each test case but then continues with the next test case. This could potentially lead to incomplete test results. Consider stopping the execution of the test cases if an error occurs.
for (const testCase of testCases) {
  const result = await runTest(
    testCase,
    modelName,
    maxPromptLength,
    vectorStore
  );
  testResults[testCase.name] = result;
  if (!result.success) {
    throw new Error(`Test case ${testCase.name} failed: ${result.reason}`);
  }
}

LOGAF Level 3 - /home/runner/work/code-review-gpt/code-review-gpt/src/args.ts

  1. The function handleNoCommand imports the inquirer module inside the function. This could potentially slow down the function execution as the module is imported every time the function is called. Consider moving the import statement to the top of the file.
import inquirer from "inquirer";

const handleNoCommand = async () => {
  // rest of the code
};
  1. The function getYargs throws an error if argv.shouldCommentPerFile is true and argv.isCi is false. However, shouldCommentPerFile is not a defined property in the ReviewArgs interface or in the yargs options. This could potentially lead to an undefined error. Make sure to define this property if it's necessary.
export interface ReviewArgs {
  // other properties
  shouldCommentPerFile: boolean;
}

// in getYargs function
.option("shouldCommentPerFile", {
  description: "Enables feedback to be made on a file-by-file basis.",
  type: "boolean",
  default: false,
})

LOGAF Level 3 - /home/runner/work/code-review-gpt/code-review-gpt/src/common/ci/utils.ts

  1. The function getRelativePath returns the original absolute path if the repo name is not in the absolute path. This could potentially lead to incorrect paths. Consider throwing an error or handling this case differently.
if (repoIndex !== -1) {
  return fileName.slice(repoIndex + repoName.length + 1);
} else {
  throw new Error("Repo name not found in the absolute path");
}
  1. The function commentOnFile catches an error but then throws it again. This could lead to unhandled promise rejections. Consider handling the error or removing the try-catch block if the error is meant to be propagated.
try {
  // code
} catch (error) {
  console.error(
    `Failed to comment on PR for feedback: ${data.feedback.details}. Error: ${error}`
  );
}

🚀🔧🔀


Powered by Code Review GPT

@github-actions
Copy link
Contributor

github-actions bot commented Jul 25, 2023

Test results summary:

✅ [PASS] - Test case: Bad variable name
✅ [PASS] - Test case: Exposed secret
✅ [PASS] - Test case: Too many nested loops
✅ [PASS] - Test case: Unawaited Promise

SUMMARY: ✅ PASS: 4 - ⚠️ WARN: 0 - ❌ FAIL: 0


Tests Powered by Code Review GPT

@lizacullis lizacullis force-pushed the line-by-line-comments branch 4 times, most recently from 472c9d1 to cb2accd Compare July 25, 2023 13:36
Repository owner deleted a comment from github-actions bot Jul 25, 2023
Repository owner deleted a comment from github-actions bot Jul 25, 2023
Repository owner deleted a comment from github-actions bot Jul 25, 2023
Repository owner deleted a comment from github-actions bot Jul 25, 2023
@lizacullis lizacullis force-pushed the line-by-line-comments branch 2 times, most recently from d2cbc16 to 153a43b Compare July 25, 2023 14:15
@lizacullis lizacullis force-pushed the line-by-line-comments branch from 153a43b to 8296a94 Compare July 25, 2023 14:25
@lizacullis lizacullis force-pushed the line-by-line-comments branch from b6ed9ae to baa67de Compare July 26, 2023 08:24
Copy link
Contributor

@github-actions github-actions bot Jul 26, 2023

Choose a reason for hiding this comment

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

  1. The askAI function could be simplified by removing the verbose parameter and always logging the 'Asking the experts...' message. This would make the function easier to use and understand.

  2. Consider handling the error in a more user-friendly way. Instead of just logging the error, you could throw it or handle it in a way that the user can understand what went wrong.


Powered by Code Review GPT

Copy link
Contributor

@github-actions github-actions bot Jul 26, 2023

Choose a reason for hiding this comment

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

  1. The function commentPerFile() is not handling any errors that may occur during the execution of commentOnFile(). Consider adding error handling to ensure that the application can recover gracefully from errors.

Example:

try {
  await commentOnFile(octokit, {
    feedback,
    signOff,
    owner,
    repo,
    pull_number,
    commit_id,
  });
} catch (error) {
  console.error('Failed to comment on file:', error);
}
  1. The function commentPerFile() is doing too many things. Consider breaking it down into smaller functions to improve readability and maintainability.

Powered by Code Review GPT

@lizacullis lizacullis force-pushed the line-by-line-comments branch from 2358f1c to 883be0c Compare July 26, 2023 11:37
Copy link
Contributor

@github-actions github-actions bot Jul 26, 2023

Choose a reason for hiding this comment

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

  1. Consider adding error handling for the case where yargs.model is not a string. This could potentially cause a runtime error if yargs.model is not a string.
const modelName = typeof yargs.model === 'string' ? yargs.model : 'defaultModelName';
  1. Consider adding a default case for when neither isCi && !shouldCommentPerFile nor isCi && shouldCommentPerFile are true. This could help prevent unexpected behavior.
if (isCi && !shouldCommentPerFile) {
  await commentOnPR(response, signOff);
} else if (isCi && shouldCommentPerFile) {
  await commentPerFile(feedbacks, signOff);
} else {
  // Default case
}

Powered by Code Review GPT

@lizacullis lizacullis marked this pull request as ready for review July 26, 2023 12:32
@mattzcarey
Copy link
Owner

Would be great to document this flag in the readme. Looks great :)

@lizacullis lizacullis force-pushed the line-by-line-comments branch from 1265efc to 51bc1a1 Compare July 27, 2023 08:33
Copy link
Collaborator

@fabienzucchet fabienzucchet left a comment

Choose a reason for hiding this comment

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

What's the default behaviour we want for new people running the setup script?
I see 3 possibilities:

  • still setup the CI to have 1 big comment
  • enable per file comment by default
  • make people choose

fabienzucchet
fabienzucchet previously approved these changes Jul 27, 2023
@fabienzucchet fabienzucchet self-requested a review July 27, 2023 10:21
Copy link
Owner

@mattzcarey mattzcarey left a comment

Choose a reason for hiding this comment

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

Please not enable this by default. It should sit behind a flag till we add some more refined functionality :)

package.json Outdated
@@ -9,7 +9,7 @@
"types": "dist/index.d.ts",
"scripts": {
"start": "ts-node ./src/index.ts review",
"start-ci": "ts-node ./src/index.ts review --ci",
"start-ci": "ts-node ./src/index.ts review --ci --commentPerFile",
Copy link
Owner

Choose a reason for hiding this comment

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

Better to add this to its own script


// Comment all feedback line by line
for (const feedback of feedbacks) {
try {
Copy link
Owner

Choose a reason for hiding this comment

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

Nested try catch blocks are not necessary

@fabienzucchet fabienzucchet dismissed their stale review July 27, 2023 10:21

need to decide on default behavior first

_: (string | number)[];
$0: string;
}

export const review = async (yargs: ReviewArgs) => {
const isCi = yargs.ci;
const shouldCommentPerFile = yargs.commentPerFile;
if (shouldCommentPerFile && !isCi) {
Copy link
Owner

Choose a reason for hiding this comment

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

This should happen in the yargs file

package.json Outdated
@@ -9,7 +9,8 @@
"types": "dist/index.d.ts",
"scripts": {
"start": "ts-node ./src/index.ts review",
"start-ci": "ts-node ./src/index.ts review --ci",
"start-ci": "ts-node ./src/index.ts review --ci --commentPerFile",
Copy link
Owner

Choose a reason for hiding this comment

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

please remove this flag from here.

@lizacullis lizacullis force-pushed the line-by-line-comments branch from 9a54324 to a032baa Compare July 27, 2023 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants