mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-06 22:00:40 +08:00
Merge pull request #495 from Codium-ai/tr/review_protection
Enhanced Exception Handling and Code Suggestion Formatting
This commit is contained in:
5
Usage.md
5
Usage.md
@ -233,7 +233,7 @@ To use a different model than the default (GPT-4), you need to edit [configurati
|
|||||||
For models and environments not from OPENAI, you might need to provide additional keys and other parameters. See below for instructions.
|
For models and environments not from OPENAI, you might need to provide additional keys and other parameters. See below for instructions.
|
||||||
|
|
||||||
#### Azure
|
#### Azure
|
||||||
To use Azure, set in your .secrets.toml:
|
To use Azure, set in your `.secrets.toml` (working from CLI), or in the GitHub `Settings > Secrets and variables` (working from GitHub App or GitHub Action):
|
||||||
```
|
```
|
||||||
api_key = "" # your azure api key
|
api_key = "" # your azure api key
|
||||||
api_type = "azure"
|
api_type = "azure"
|
||||||
@ -242,12 +242,11 @@ api_base = "" # The base URL for your Azure OpenAI resource. e.g. "https://<you
|
|||||||
openai.deployment_id = "" # The deployment name you chose when you deployed the engine
|
openai.deployment_id = "" # The deployment name you chose when you deployed the engine
|
||||||
```
|
```
|
||||||
|
|
||||||
and
|
and set in your configuration file:
|
||||||
```
|
```
|
||||||
[config]
|
[config]
|
||||||
model="" # the OpenAI model you've deployed on Azure (e.g. gpt-3.5-turbo)
|
model="" # the OpenAI model you've deployed on Azure (e.g. gpt-3.5-turbo)
|
||||||
```
|
```
|
||||||
in the configuration.toml
|
|
||||||
|
|
||||||
#### Huggingface
|
#### Huggingface
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@ class GithubProvider(GitProvider):
|
|||||||
get_logger().info(f"Skipping merge commit {commit.commit.message}")
|
get_logger().info(f"Skipping merge commit {commit.commit.message}")
|
||||||
continue
|
continue
|
||||||
self.file_set.update({file.filename: file for file in commit.files})
|
self.file_set.update({file.filename: file for file in commit.files})
|
||||||
|
else:
|
||||||
|
raise ValueError("No previous review found")
|
||||||
|
|
||||||
def get_commit_range(self):
|
def get_commit_range(self):
|
||||||
last_review_time = self.previous_review.created_at
|
last_review_time = self.previous_review.created_at
|
||||||
|
@ -251,7 +251,16 @@ class PRCodeSuggestions:
|
|||||||
def publish_summarizes_suggestions(self, data: Dict):
|
def publish_summarizes_suggestions(self, data: Dict):
|
||||||
try:
|
try:
|
||||||
data_markdown = "## PR Code Suggestions\n\n"
|
data_markdown = "## PR Code Suggestions\n\n"
|
||||||
|
|
||||||
|
language_extension_map_org = get_settings().language_extension_map_org
|
||||||
|
extension_to_language = {}
|
||||||
|
for language, extensions in language_extension_map_org.items():
|
||||||
|
for ext in extensions:
|
||||||
|
extension_to_language[ext] = language
|
||||||
|
|
||||||
for s in data['Code suggestions']:
|
for s in data['Code suggestions']:
|
||||||
|
try:
|
||||||
|
extension_s = s['relevant file'].rsplit('.')[-1]
|
||||||
code_snippet_link = self.git_provider.get_line_link(s['relevant file'], s['relevant lines start'],
|
code_snippet_link = self.git_provider.get_line_link(s['relevant file'], s['relevant lines start'],
|
||||||
s['relevant lines end'])
|
s['relevant lines end'])
|
||||||
data_markdown += f"\n💡 Suggestion:\n\n**{s['suggestion content']}**\n\n"
|
data_markdown += f"\n💡 Suggestion:\n\n**{s['suggestion content']}**\n\n"
|
||||||
@ -262,11 +271,16 @@ class PRCodeSuggestions:
|
|||||||
if self.git_provider.is_supported("gfm_markdown"):
|
if self.git_provider.is_supported("gfm_markdown"):
|
||||||
data_markdown += "<details> <summary> Example code:</summary>\n\n"
|
data_markdown += "<details> <summary> Example code:</summary>\n\n"
|
||||||
data_markdown += f"___\n\n"
|
data_markdown += f"___\n\n"
|
||||||
data_markdown += f"Existing code:\n```{self.main_language}\n{s['existing code']}\n```\n"
|
language_name = "python"
|
||||||
data_markdown += f"Improved code:\n```{self.main_language}\n{s['improved code']}\n```\n"
|
if extension_s and (extension_s in extension_to_language):
|
||||||
|
language_name = extension_to_language[extension_s]
|
||||||
|
data_markdown += f"Existing code:\n```{language_name}\n{s['existing code']}\n```\n"
|
||||||
|
data_markdown += f"Improved code:\n```{language_name}\n{s['improved code']}\n```\n"
|
||||||
if self.git_provider.is_supported("gfm_markdown"):
|
if self.git_provider.is_supported("gfm_markdown"):
|
||||||
data_markdown += "</details>\n"
|
data_markdown += "</details>\n"
|
||||||
data_markdown += "\n___\n\n"
|
data_markdown += "\n___\n\n"
|
||||||
|
except Exception as e:
|
||||||
|
get_logger().error(f"Could not parse suggestion: {s}, error: {e}")
|
||||||
self.git_provider.publish_comment(data_markdown)
|
self.git_provider.publish_comment(data_markdown)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().info(f"Failed to publish summarized code suggestions, error: {e}")
|
get_logger().info(f"Failed to publish summarized code suggestions, error: {e}")
|
||||||
|
Reference in New Issue
Block a user