commitable_code_suggestions

This commit is contained in:
mrT23
2024-04-17 15:32:45 +03:00
parent e2e0bea8fd
commit b076c33351
5 changed files with 13 additions and 13 deletions

View File

@ -4,4 +4,4 @@ enable_auto_approval = true
[pr_code_suggestions] [pr_code_suggestions]
summarize=true commitable_code_suggestions=false

View File

@ -7,11 +7,11 @@ The tool can be triggered automatically every time a new PR is [opened](../usage
### Summarized vs committable code suggestions ### Summarized vs committable code suggestions
The code suggestions can be presented as a single comment (via `pr_code_suggestions.summarize=true`): The code suggestions can be presented as a single comment
![code suggestions as comment](https://codium.ai/images/pr_agent/code_suggestions_as_comment.png){width=512} ![code suggestions as comment](https://codium.ai/images/pr_agent/code_suggestions_as_comment.png){width=512}
Or as a separate commitable code comment for each suggestion: Or as a separate commitable code comment for each suggestion (via `pr_code_suggestions.commitable_code_suggestions=true`)::
![imporove](https://codium.ai/images/pr_agent/improve.png){width=512} ![imporove](https://codium.ai/images/pr_agent/improve.png){width=512}
@ -58,7 +58,7 @@ To edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agen
- `num_code_suggestions_per_chunk`: number of code suggestions provided by the 'improve' tool, per chunk. Default is 5. - `num_code_suggestions_per_chunk`: number of code suggestions provided by the 'improve' tool, per chunk. Default is 5.
- `rank_extended_suggestions`: if set to true, the tool will rank the suggestions, based on importance. Default is true. - `rank_extended_suggestions`: if set to true, the tool will rank the suggestions, based on importance. Default is true.
- `max_number_of_calls`: maximum number of chunks. Default is 5. - `max_number_of_calls`: maximum number of chunks. Default is 5.
- `final_clip_factor`: factor to remove suggestions with low confidence. Default is 0.9. - `final_clip_factor`: factor to remove suggestions with low confidence. Default is 0.9.;
## Usage Tips ## Usage Tips

View File

@ -170,7 +170,7 @@ Specifically, set the following values:
[bitbucket_app] [bitbucket_app]
pr_commands = [ pr_commands = [
"/review --pr_reviewer.num_code_suggestions=0", "/review --pr_reviewer.num_code_suggestions=0",
"/improve --pr_code_suggestions.summarize=false", "/improve --pr_code_suggestions.commitable_code_suggestions=true",
] ]
``` ```

View File

@ -80,7 +80,7 @@ enable_help_text=true
[pr_code_suggestions] # /improve # [pr_code_suggestions] # /improve #
max_context_tokens=8000 max_context_tokens=8000
num_code_suggestions=4 num_code_suggestions=4
summarize = true commitable_code_suggestions = false
extra_instructions = "" extra_instructions = ""
rank_suggestions = false rank_suggestions = false
enable_help_text=true enable_help_text=true
@ -150,7 +150,7 @@ handle_pr_actions = ['opened', 'reopened', 'ready_for_review']
pr_commands = [ pr_commands = [
"/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true", "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true",
"/review --pr_reviewer.num_code_suggestions=0", "/review --pr_reviewer.num_code_suggestions=0",
"/improve --pr_code_suggestions.summarize=true", "/improve",
] ]
# settings for "pull_request" event with "synchronize" action - used to detect and handle push triggers for new commits # settings for "pull_request" event with "synchronize" action - used to detect and handle push triggers for new commits
handle_push_trigger = false handle_push_trigger = false
@ -171,13 +171,13 @@ url = "https://gitlab.com" # URL to the gitlab service
pr_commands = [ pr_commands = [
"/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true", "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true",
"/review --pr_reviewer.num_code_suggestions=0", "/review --pr_reviewer.num_code_suggestions=0",
"/improve --pr_code_suggestions.summarize=true", "/improve",
] ]
[bitbucket_app] [bitbucket_app]
pr_commands = [ pr_commands = [
"/review --pr_reviewer.num_code_suggestions=0", "/review --pr_reviewer.num_code_suggestions=0",
"/improve --pr_code_suggestions.summarize=false", "/improve --pr_code_suggestions.commitable_code_suggestions=true",
] ]

View File

@ -57,7 +57,7 @@ class PRCodeSuggestions:
"language": self.main_language, "language": self.main_language,
"diff": "", # empty diff for initial calculation "diff": "", # empty diff for initial calculation
"num_code_suggestions": num_code_suggestions, "num_code_suggestions": num_code_suggestions,
"summarize_mode": get_settings().pr_code_suggestions.summarize, "commitable_code_suggestions_mode": get_settings().pr_code_suggestions.commitable_code_suggestions,
"extra_instructions": get_settings().pr_code_suggestions.extra_instructions, "extra_instructions": get_settings().pr_code_suggestions.extra_instructions,
"commit_messages_str": self.git_provider.get_commit_messages(), "commit_messages_str": self.git_provider.get_commit_messages(),
} }
@ -105,7 +105,7 @@ class PRCodeSuggestions:
if get_settings().config.publish_output: if get_settings().config.publish_output:
self.git_provider.remove_initial_comment() self.git_provider.remove_initial_comment()
if get_settings().pr_code_suggestions.summarize and self.git_provider.is_supported("gfm_markdown"): if (not get_settings().pr_code_suggestions.commitable_code_suggestions) and self.git_provider.is_supported("gfm_markdown"):
# generate summarized suggestions # generate summarized suggestions
pr_body = self.generate_summarized_suggestions(data) pr_body = self.generate_summarized_suggestions(data)
@ -197,7 +197,7 @@ class PRCodeSuggestions:
one_sentence_summary_list = [] one_sentence_summary_list = []
for i, suggestion in enumerate(data['code_suggestions']): for i, suggestion in enumerate(data['code_suggestions']):
try: try:
if get_settings().pr_code_suggestions.summarize: if not get_settings().pr_code_suggestions.commitable_code_suggestions:
if not suggestion or 'one_sentence_summary' not in suggestion or 'label' not in suggestion or 'relevant_file' not in suggestion: if not suggestion or 'one_sentence_summary' not in suggestion or 'label' not in suggestion or 'relevant_file' not in suggestion:
get_logger().debug(f"Skipping suggestion {i + 1}, because it is invalid: {suggestion}") get_logger().debug(f"Skipping suggestion {i + 1}, because it is invalid: {suggestion}")
continue continue
@ -213,7 +213,7 @@ class PRCodeSuggestions:
if ('existing_code' in suggestion) and ('improved_code' in suggestion) and ( if ('existing_code' in suggestion) and ('improved_code' in suggestion) and (
suggestion['existing_code'] != suggestion['improved_code']): suggestion['existing_code'] != suggestion['improved_code']):
suggestion = self._truncate_if_needed(suggestion) suggestion = self._truncate_if_needed(suggestion)
if get_settings().pr_code_suggestions.summarize: if not get_settings().pr_code_suggestions.commitable_code_suggestions:
one_sentence_summary_list.append(suggestion['one_sentence_summary']) one_sentence_summary_list.append(suggestion['one_sentence_summary'])
suggestion_list.append(suggestion) suggestion_list.append(suggestion)
else: else: