fix: ensure proper formatting of changes_diagram in PR description output

This commit is contained in:
mrT23
2025-05-25 14:32:12 +03:00
parent 946657a6d1
commit f3cb4e8384
2 changed files with 20 additions and 18 deletions

View File

@ -46,12 +46,12 @@ class PRDescription(BaseModel):
type: List[PRType] = Field(description="one or more types that describe the PR content. Return the label member value (e.g. 'Bug fix', not 'bug_fix')")
description: str = Field(description="summarize the PR changes in up to four bullet points, each up to 8 words. For large PRs, add sub-bullets if needed. Order bullets by importance, with each bullet highlighting a key change group.")
title: str = Field(description="a concise and descriptive title that captures the PR's main theme")
{%- if enable_semantic_files_types %}
pr_files: List[FileDescription] = Field(max_items=20, description="a list of all the files that were changed in the PR, and summary of their changes. Each file must be analyzed regardless of change size.")
{%- endif %}
{%- if enable_pr_diagram %}
changes_diagram: str = Field(description="a horizontal diagram that represents the main PR changes, in the format of a mermaid flowchart. The diagram should be concise and easy to read. Leave empty if no diagram is relevant.")
{%- endif %}
{%- if enable_semantic_files_types %}
pr_files: List[FileDescription] = Field(max_items=20, description="a list of all the files that were changed in the PR, and summary of their changes. Each file must be analyzed regardless of change size.")
{%- endif %}
=====
@ -65,6 +65,12 @@ description: |
...
title: |
...
{%- if enable_pr_diagram %}
changes_diagram: |
```mermaid
...
```
{%- endif %}
{%- if enable_semantic_files_types %}
pr_files:
- filename: |
@ -79,12 +85,6 @@ pr_files:
label_key_1
...
{%- endif %}
{%- if enable_pr_diagram %}
changes_diagram: |
```mermaid
...
```
{%- endif %}
```
Answer should be a valid YAML, and nothing else. Each YAML output MUST be after a newline, with proper indent, and block scalar indicator ('|')
@ -152,6 +152,12 @@ description: |
...
title: |
...
{%- if enable_pr_diagram %}
changes_diagram: |
```mermaid
...
```
{%- endif %}
{%- if enable_semantic_files_types %}
pr_files:
- filename: |
@ -166,12 +172,6 @@ pr_files:
label_key_1
...
{%- endif %}
{%- if enable_pr_diagram %}
changes_diagram: |
```mermaid
...
```
{%- endif %}
```
(replace '...' with the actual values)
{%- endif %}

View File

@ -458,9 +458,11 @@ class PRDescription:
if 'description' in self.data:
self.data['description'] = self.data.pop('description')
if 'changes_diagram' in self.data:
changes_diagram = self.data.pop('changes_diagram')
if changes_diagram.strip():
self.data['changes_diagram'] = changes_diagram
changes_diagram = self.data.pop('changes_diagram').strip()
if changes_diagram.startswith('```'):
if not changes_diagram.endswith('```'): # fallback for missing closing
changes_diagram += '\n```'
self.data['changes_diagram'] = '\n'+ changes_diagram
if 'pr_files' in self.data:
self.data['pr_files'] = self.data.pop('pr_files')