mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 04:40:38 +08:00
refactor + add description options
This commit is contained in:
@ -304,3 +304,18 @@ def try_fix_yaml(review_text: str) -> dict:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
async def set_custom_labels(variables):
|
||||||
|
labels = get_settings().custom_labels
|
||||||
|
if not labels:
|
||||||
|
# set default labels
|
||||||
|
labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other']
|
||||||
|
labels_list = "\n - ".join(labels) if labels else ""
|
||||||
|
labels_list = f" - {labels_list}" if labels_list else ""
|
||||||
|
variables["custom_labels"] = labels_list
|
||||||
|
return
|
||||||
|
final_labels = ""
|
||||||
|
for k, v in labels.items():
|
||||||
|
final_labels += f" - {k} ({v['description']})\n"
|
||||||
|
variables["custom_labels"] = final_labels
|
||||||
|
@ -38,7 +38,24 @@ extra_instructions = ""
|
|||||||
use_description_markers=false
|
use_description_markers=false
|
||||||
include_generated_by_header=true
|
include_generated_by_header=true
|
||||||
|
|
||||||
custom_labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other']
|
[custom_labels."Bug fix"]
|
||||||
|
description = "Fixes a bug in the code"
|
||||||
|
[custom_labels."Tests"]
|
||||||
|
description = "Adds or modifies tests"
|
||||||
|
[custom_labels."Bug fix with tests"]
|
||||||
|
description = "Fixes a bug in the code and adds or modifies tests"
|
||||||
|
[custom_labels."Refactoring"]
|
||||||
|
description = "Refactors the code without changing its functionality"
|
||||||
|
[custom_labels."Enhancement"]
|
||||||
|
description = "Adds new features or functionality"
|
||||||
|
[custom_labels."Documentation"]
|
||||||
|
description = "Adds or modifies documentation"
|
||||||
|
[custom_labels."SQL modifications"]
|
||||||
|
description = "Adds or modifies SQL queries"
|
||||||
|
[custom_labels."Other"]
|
||||||
|
description = "Other changes that do not fit in any of the above categories"
|
||||||
|
|
||||||
|
#custom_labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other']
|
||||||
|
|
||||||
[pr_questions] # /ask #
|
[pr_questions] # /ask #
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ PR Title:
|
|||||||
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
|
type: array
|
||||||
|
description: One or more labels that describe the PR type. Don't output the description in the parentheses.
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
enum:
|
enum:
|
||||||
|
@ -7,7 +7,7 @@ from jinja2 import Environment, StrictUndefined
|
|||||||
from pr_agent.algo.ai_handler import AiHandler
|
from pr_agent.algo.ai_handler import AiHandler
|
||||||
from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models
|
from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models
|
||||||
from pr_agent.algo.token_handler import TokenHandler
|
from pr_agent.algo.token_handler import TokenHandler
|
||||||
from pr_agent.algo.utils import load_yaml
|
from pr_agent.algo.utils import load_yaml, set_custom_labels
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers import get_git_provider
|
from pr_agent.git_providers import get_git_provider
|
||||||
from pr_agent.git_providers.git_provider import get_main_pr_language
|
from pr_agent.git_providers.git_provider import get_main_pr_language
|
||||||
@ -44,7 +44,6 @@ class PRDescription:
|
|||||||
"extra_instructions": get_settings().pr_description.extra_instructions,
|
"extra_instructions": get_settings().pr_description.extra_instructions,
|
||||||
"commit_messages_str": self.git_provider.get_commit_messages(),
|
"commit_messages_str": self.git_provider.get_commit_messages(),
|
||||||
"custom_labels": ""
|
"custom_labels": ""
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.user_description = self.git_provider.get_user_description()
|
self.user_description = self.git_provider.get_user_description()
|
||||||
@ -142,7 +141,7 @@ class PRDescription:
|
|||||||
variables["diff"] = self.patches_diff # update diff
|
variables["diff"] = self.patches_diff # update diff
|
||||||
|
|
||||||
environment = Environment(undefined=StrictUndefined)
|
environment = Environment(undefined=StrictUndefined)
|
||||||
await self.set_custom_labels(variables)
|
await set_custom_labels(variables)
|
||||||
system_prompt = environment.from_string(get_settings().pr_description_prompt.system).render(variables)
|
system_prompt = environment.from_string(get_settings().pr_description_prompt.system).render(variables)
|
||||||
user_prompt = environment.from_string(get_settings().pr_description_prompt.user).render(variables)
|
user_prompt = environment.from_string(get_settings().pr_description_prompt.user).render(variables)
|
||||||
|
|
||||||
@ -159,15 +158,6 @@ class PRDescription:
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def set_custom_labels(self, variables):
|
|
||||||
labels = get_settings().pr_description.custom_labels
|
|
||||||
if not labels:
|
|
||||||
# set default labels
|
|
||||||
labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other']
|
|
||||||
labels_list = "\n - ".join(labels) if labels else ""
|
|
||||||
labels_list = f" - {labels_list}" if labels_list else ""
|
|
||||||
variables["custom_labels"] = labels_list
|
|
||||||
|
|
||||||
def _prepare_data(self):
|
def _prepare_data(self):
|
||||||
# Load the AI prediction data into a dictionary
|
# Load the AI prediction data into a dictionary
|
||||||
self.data = load_yaml(self.prediction.strip())
|
self.data = load_yaml(self.prediction.strip())
|
||||||
|
@ -9,7 +9,7 @@ from yaml import SafeLoader
|
|||||||
from pr_agent.algo.ai_handler import AiHandler
|
from pr_agent.algo.ai_handler import AiHandler
|
||||||
from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models
|
from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models
|
||||||
from pr_agent.algo.token_handler import TokenHandler
|
from pr_agent.algo.token_handler import TokenHandler
|
||||||
from pr_agent.algo.utils import convert_to_markdown, load_yaml, try_fix_yaml
|
from pr_agent.algo.utils import convert_to_markdown, load_yaml, try_fix_yaml, set_custom_labels
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers import get_git_provider
|
from pr_agent.git_providers import get_git_provider
|
||||||
from pr_agent.git_providers.git_provider import IncrementalPR, get_main_pr_language
|
from pr_agent.git_providers.git_provider import IncrementalPR, get_main_pr_language
|
||||||
@ -150,7 +150,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)
|
||||||
await self.set_custom_labels(variables)
|
await 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)
|
||||||
|
|
||||||
@ -313,12 +313,3 @@ class PRReviewer:
|
|||||||
break
|
break
|
||||||
|
|
||||||
return question_str, answer_str
|
return question_str, answer_str
|
||||||
|
|
||||||
async def set_custom_labels(self, variables):
|
|
||||||
labels = get_settings().pr_description.custom_labels
|
|
||||||
if not labels:
|
|
||||||
# set default labels
|
|
||||||
labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other']
|
|
||||||
labels_list = "\n - ".join(labels) if labels else ""
|
|
||||||
labels_list = f" - {labels_list}" if labels_list else ""
|
|
||||||
variables["custom_labels"] = labels_list
|
|
Reference in New Issue
Block a user