Skip to content
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

feat: update comments #9

Merged
merged 2 commits into from
Jul 11, 2023
Merged

feat: update comments #9

merged 2 commits into from
Jul 11, 2023

Conversation

mattzcarey
Copy link
Owner

No description provided.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2023

File: /home/runner/work/code-review-gpt/code-review-gpt/src/askAI.ts

  1. The callModel function is not handling any potential errors that might occur during the API call. It would be better to wrap the model.call(prompt) inside a try-catch block to handle any potential errors.
const callModel = async (prompt: string): Promise<string> => {
  try {
    return await model.call(prompt);
  } catch (error) {
    console.error(`Error in calling model with prompt ${prompt}`, error);
    throw error;
  }
};
  1. In the askAI function, the feedbacks array is being populated inside the collectAndLogFeedback function which is called inside Promise.allSettled. This could potentially lead to race conditions where the order of feedbacks might not be the same as the order of prompts. Instead, you could use Promise.all which will return an array of results maintaining the order of the original promises.
export const askAI = async (prompts: string[]): Promise<string> => {
  console.info("Asking the experts...");

  const feedbackPromises = prompts.map((prompt) => callModel(prompt));

  try {
    const feedbacks = await Promise.all(feedbackPromises);
    const summary = await createSummary(feedbacks);

    return feedbacks.join("\n---\n") + "\n---\n" + summary;
  } catch (error) {
    console.error(`Error in processing prompts`, error);
    throw error;
  }
};

File: /home/runner/work/code-review-gpt/code-review-gpt/src/commentOnPR.ts

  1. The getToken function throws an error if the GITHUB_TOKEN is not set. However, this function is called inside a try-catch block in the commentOnPR function. This means that if the GITHUB_TOKEN is not set, the error will be caught and the function will return without any further action. It would be better to check for the GITHUB_TOKEN outside the try-catch block and throw an error if it's not set. This way, the error will not be caught and the function will not proceed without a valid token.
export const commentOnPR = async (comment: string) => {
  const githubToken = getToken();
  if (!githubToken) {
    throw new Error("GITHUB_TOKEN is not set");
  }

  try {
    // rest of the code
  } catch (error) {
    console.error(`Failed to comment on PR: ${error}`);
    throw error;
  }
};

These changes will improve error handling and maintain the order of feedbacks in the askAI function.

🔒🔄🐛

Powered by Code Review GPT

@mattzcarey mattzcarey merged commit c13c3fc into main Jul 11, 2023
This was referenced Aug 7, 2023
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.

1 participant