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

file is null causing fail, if null skipping file #5

Merged
merged 2 commits into from
Apr 27, 2023

Conversation

JC1738
Copy link
Contributor

@JC1738 JC1738 commented Apr 25, 2023

Description

This pull request aims to resolve the issue of file being null causing failure in the system. Changes have been made in cmd/description/main.go to include a condition that checks if the file patch is null to prevent errors. If the file patch is not null, then the function prompt will be executed to describe changes in the file. The pull request title and body have also been included in the OverallDescribeCompletion string. Additionally, changes have been made in cmd/review/main.go to fix a bug that previously caused the prompt to exceed the maximum character limit of 4096 and resulted in a crash. The issue where the prompt was still being generated even if the file's patch was null has also been resolved. Changes have been made to clean up the code and ensure that irrelevant files are skipped during the review process. Finally, the code patches for openai/openai.go have been updated to modify the PromptReview and PromptOverallReview prompts. The updated prompts now request code reviews in English and welcome any bug risks and improvement suggestions.

Changes

  • Added a condition in main.go to check if file patch is nil
  • Fixed the issue where the prompt exceeded the maximum character limit in main.go
  • Fixed the issue where the prompt was generated even if the file's patch was nil in main.go
  • Cleaned up code and ensured irrelevant files were skipped in main.go
  • Modified PromptReview and PromptOverallReview prompts to request for code reviews in English and welcome bug risks and improvement suggestions in openai.go.

if file.Patch == nil {
continue
}

prompt := fmt.Sprintf(oAIClient.PromptDescribeChanges, *file.Patch)

if len(prompt) > 4096 {
Copy link
Owner

Choose a reason for hiding this comment

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

The code patch looks fine overall. The addition of a check for file.Patch being nil and continuing the loop if true is good to prevent any potential errors. Possible improvements could be to utilize error handling for any potential errors that could occur during the code execution. Additionally, using constants for hard-coded values such as the prompt length limit could improve code readability and maintainability. Overall, there doesn't seem to be any major bug risk.

if file.Patch == nil {
continue
}

prompt := fmt.Sprintf(oAIClient.PromptReview, *file.Patch)

if len(prompt) > 4096 {
Copy link
Owner

Choose a reason for hiding this comment

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

This code patch seems to be checking if the file has a patch before prompting for review. This could be helpful in avoiding unnecessary prompts and saving resources. However, without seeing the surrounding code, it's unclear if this is the best way to handle this scenario.

One potential improvement suggestion could be to provide more detailed error messages or debug logging to help diagnose any issues that arise during the run function. Additionally, adding some comments to the code can help make it more understandable to others who may review or work on it in the future.

PromptReview = "Bellow is the code patch, please help me do a brief code review,Answer me in English, if any bug risk and improvement suggestion are welcome\n%s\n"
PromptOverallReview = "Bellow comments are generated by AI, please help me do a brief code review,Answer me in English, if any bug risk and improvement suggestion are welcome\n%s\n"
PromptReview = "Bellow is the code patch, please help me do a brief code review, Answer me in English, if any bug risk and improvement suggestion are welcome\n%s\n"
PromptOverallReview = "Bellow comments are generated by AI, please help me do a brief code review, Answer me in English, if any bug risk and improvement suggestion are welcome\n%s\n"
)

type Client struct {
Copy link
Owner

Choose a reason for hiding this comment

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

This code patch includes changes to the prompts in the import section, as well as adding a space after the word "review" in the PromptReview and PromptOverallReview constants.

As it is a small change, there is not much bug risk involved. However, it is always important to test the changes after they are made to ensure that they do not cause any issues.

As for improvement suggestions, it may be helpful to have clearer prompts for the user to know what is expected of them when reviewing code or generating pull request descriptions. This could potentially save time and confusion in the long run.

Copy link
Owner

@ravilushqa ravilushqa left a comment

Choose a reason for hiding this comment

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

@JC1738 thanks for contribution!

@ravilushqa ravilushqa merged commit 76855cf into ravilushqa:main Apr 27, 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.

2 participants