Merge pull request #431 from Codium-ai/hl/type_vs_labels

Refactoring PR Labels Handling and Display
This commit is contained in:
mrT23
2023-11-06 02:10:38 -08:00
committed by GitHub
6 changed files with 26 additions and 26 deletions

View File

@ -38,6 +38,7 @@ add_original_user_description=false
keep_original_user_title=false keep_original_user_title=false
use_bullet_points=true use_bullet_points=true
extra_instructions = "" extra_instructions = ""
enable_pr_type=true
# markers # markers
use_description_markers=false use_description_markers=false

View File

@ -39,7 +39,6 @@ PR Type:
{{ custom_labels_examples }} {{ custom_labels_examples }}
{%- else %} {%- else %}
- Bug fix - Bug fix
- Tests
{%- endif %} {%- endif %}
``` ```

View File

@ -19,22 +19,22 @@ PR Title:
type: string type: string
description: an informative title for the PR, describing its main theme description: an informative title for the PR, describing its main theme
PR Type: PR Type:
type: array
{%- if enable_custom_labels %}
description: One or more labels that describe the PR type. Don't output the description in the parentheses.
{%- endif %}
items:
type: string type: string
enum: enum:
{%- if enable_custom_labels %}
{{ custom_labels }}
{%- else %}
- Bug fix - Bug fix
- Tests - Tests
- Refactoring - Refactoring
- Enhancement - Enhancement
- Documentation - Documentation
- Other - Other
{%- if enable_custom_labels %}
PR Labels:
type: array
description: One or more labels that describe the PR labels. Don't output the description in the parentheses.
items:
type: string
enum:
{{ custom_labels }}
{%- endif %} {%- endif %}
PR Description: PR Description:
type: string type: string
@ -60,10 +60,10 @@ Example output:
PR Title: |- PR Title: |-
... ...
PR Type: PR Type:
...
{%- if enable_custom_labels %} {%- if enable_custom_labels %}
PR Labels:
{{ custom_labels_examples }} {{ custom_labels_examples }}
{%- else %}
- Bug fix
{%- endif %} {%- endif %}
PR Description: |- PR Description: |-
... ...

View File

@ -51,22 +51,13 @@ PR Analysis:
description: summary of the PR in 2-3 sentences. description: summary of the PR in 2-3 sentences.
Type of PR: Type of PR:
type: string type: string
{%- if enable_custom_labels %}
description: One or more labels that describe the PR type. Don't output the description in the parentheses.
{%- endif %}
items:
type: string
enum: enum:
{%- if enable_custom_labels %}
{{ custom_labels }}
{%- else %}
- Bug fix - Bug fix
- Tests - Tests
- Refactoring - Refactoring
- Enhancement - Enhancement
- Documentation - Documentation
- Other - Other
{%- endif %}
{%- if require_score %} {%- if require_score %}
Score: Score:
type: int type: int

View File

@ -172,12 +172,16 @@ class PRDescription:
pr_types = [] pr_types = []
# If the 'PR Type' key is present in the dictionary, split its value by comma and assign it to 'pr_types' # If the 'PR Type' key is present in the dictionary, split its value by comma and assign it to 'pr_types'
if 'PR Type' in self.data: if 'PR Labels' in self.data:
if type(self.data['PR Labels']) == list:
pr_types = self.data['PR Labels']
elif type(self.data['PR Labels']) == str:
pr_types = self.data['PR Labels'].split(',')
elif 'PR Type' in self.data:
if type(self.data['PR Type']) == list: if type(self.data['PR Type']) == list:
pr_types = self.data['PR Type'] pr_types = self.data['PR Type']
elif type(self.data['PR Type']) == str: elif type(self.data['PR Type']) == str:
pr_types = self.data['PR Type'].split(',') pr_types = self.data['PR Type'].split(',')
return pr_types return pr_types
def _prepare_pr_answer_with_markers(self) -> Tuple[str, str]: def _prepare_pr_answer_with_markers(self) -> Tuple[str, str]:
@ -223,6 +227,11 @@ class PRDescription:
# Iterate over the dictionary items and append the key and value to 'markdown_text' in a markdown format # Iterate over the dictionary items and append the key and value to 'markdown_text' in a markdown format
markdown_text = "" markdown_text = ""
# Don't display 'PR Labels'
if 'PR Labels' in self.data:
self.data.pop('PR Labels')
if not get_settings().pr_description.enable_pr_type:
self.data.pop('PR Type')
for key, value in self.data.items(): for key, value in self.data.items():
markdown_text += f"## {key}\n\n" markdown_text += f"## {key}\n\n"
markdown_text += f"{value}\n\n" markdown_text += f"{value}\n\n"

View File

@ -156,7 +156,7 @@ class PRReviewer:
variables["diff"] = self.patches_diff # update diff variables["diff"] = self.patches_diff # update diff
environment = Environment(undefined=StrictUndefined) environment = Environment(undefined=StrictUndefined)
set_custom_labels(variables) # set_custom_labels(variables)
system_prompt = environment.from_string(get_settings().pr_review_prompt.system).render(variables) system_prompt = environment.from_string(get_settings().pr_review_prompt.system).render(variables)
user_prompt = environment.from_string(get_settings().pr_review_prompt.user).render(variables) user_prompt = environment.from_string(get_settings().pr_review_prompt.user).render(variables)