Skip to content

Commit

Permalink
commitable_code_suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrT23 committed Apr 17, 2024
1 parent e2e0bea commit b076c33
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pr_agent.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ enable_auto_approval = true


[pr_code_suggestions]
summarize=true
commitable_code_suggestions=false
6 changes: 3 additions & 3 deletions docs/docs/tools/improve.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ The tool can be triggered automatically every time a new PR is [opened](../usage

### 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}

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}

Expand Down Expand Up @@ -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.
- `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.
- `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
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/usage-guide/automations_and_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Specifically, set the following values:
[bitbucket_app]
pr_commands = [
"/review --pr_reviewer.num_code_suggestions=0",
"/improve --pr_code_suggestions.summarize=false",
"/improve --pr_code_suggestions.commitable_code_suggestions=true",
]
```

Expand Down
8 changes: 4 additions & 4 deletions pr_agent/settings/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ enable_help_text=true
[pr_code_suggestions] # /improve #
max_context_tokens=8000
num_code_suggestions=4
summarize = true
commitable_code_suggestions = false
extra_instructions = ""
rank_suggestions = false
enable_help_text=true
Expand Down Expand Up @@ -150,7 +150,7 @@ handle_pr_actions = ['opened', 'reopened', 'ready_for_review']
pr_commands = [
"/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true",
"/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
handle_push_trigger = false
Expand All @@ -171,13 +171,13 @@ url = "https://gitlab.com" # URL to the gitlab service
pr_commands = [
"/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true",
"/review --pr_reviewer.num_code_suggestions=0",
"/improve --pr_code_suggestions.summarize=true",
"/improve",
]

[bitbucket_app]
pr_commands = [
"/review --pr_reviewer.num_code_suggestions=0",
"/improve --pr_code_suggestions.summarize=false",
"/improve --pr_code_suggestions.commitable_code_suggestions=true",
]


Expand Down
8 changes: 4 additions & 4 deletions pr_agent/tools/pr_code_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, pr_url: str, cli_mode=False, args: list = None,
"language": self.main_language,
"diff": "", # empty diff for initial calculation
"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,
"commit_messages_str": self.git_provider.get_commit_messages(),
}
Expand Down Expand Up @@ -105,7 +105,7 @@ async def run(self):

if get_settings().config.publish_output:
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
pr_body = self.generate_summarized_suggestions(data)
Expand Down Expand Up @@ -197,7 +197,7 @@ def _prepare_pr_code_suggestions(self) -> Dict:
one_sentence_summary_list = []
for i, suggestion in enumerate(data['code_suggestions']):
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:
get_logger().debug(f"Skipping suggestion {i + 1}, because it is invalid: {suggestion}")
continue
Expand All @@ -213,7 +213,7 @@ def _prepare_pr_code_suggestions(self) -> Dict:
if ('existing_code' in suggestion) and ('improved_code' in suggestion) and (
suggestion['existing_code'] != suggestion['improved_code']):
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'])
suggestion_list.append(suggestion)
else:
Expand Down

0 comments on commit b076c33

Please sign in to comment.