add support for PR sequence diagram in description markers

This commit is contained in:
Abhinav Kumar
2025-07-02 18:07:54 +05:30
parent 9e20373cb0
commit df8290a290
4 changed files with 11 additions and 2 deletions

View File

@ -177,9 +177,12 @@ pr_agent:summary
## PR Walkthrough:
pr_agent:walkthrough
## PR Diagram:
pr_agent:diagram
```
The marker `pr_agent:type` will be replaced with the PR type, `pr_agent:summary` will be replaced with the PR summary, and `pr_agent:walkthrough` will be replaced with the PR walkthrough.
The marker `pr_agent:type` will be replaced with the PR type, `pr_agent:summary` will be replaced with the PR summary, `pr_agent:walkthrough` will be replaced with the PR walkthrough, and `pr_agent:diagram` will be replaced with the sequence diagram (if enabled).
![Describe markers before](https://codium.ai/images/pr_agent/describe_markers_before.png){width=512}
@ -191,6 +194,7 @@ becomes
- `use_description_markers`: if set to true, the tool will use markers template. It replaces every marker of the form `pr_agent:marker_name` with the relevant content. Default is false.
- `include_generated_by_header`: if set to true, the tool will add a dedicated header: 'Generated by PR Agent at ...' to any automatic content. Default is true.
- `diagram`: if present as a marker, will be replaced by the PR sequence diagram (if enabled).
## Custom labels

View File

@ -81,6 +81,7 @@ the tool will replace every marker of the form `pr_agent:marker_name` in the PR
- `type`: the PR type.
- `summary`: the PR summary.
- `walkthrough`: the PR walkthrough.
- `diagram`: the PR sequence diagram (if enabled).
Note that when markers are enabled, if the original PR description does not contain any markers, the tool will not alter the description at all.

View File

@ -48,7 +48,7 @@ class PRDescription(BaseModel):
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_pr_diagram %}
changes_diagram: str = Field(description="a horizontal diagram that represents the main PR changes, in the format of a valid mermaid LR flowchart. The diagram should be concise and easy to read. Leave empty if no diagram is relevant. To create robust Mermaid diagrams, follow this two-step process: (1) Declare the nodes: nodeID["node description"]. (2) Then define the links: nodeID1 -- "link text" --> nodeID2. Node description must always be surrounded with quotation marks.")
changes_diagram: str = Field(description="a horizontal diagram that represents the main PR changes, in the format of a valid mermaid LR flowchart. The diagram should be concise and easy to read. Leave empty if no diagram is relevant. To create robust Mermaid diagrams, follow this two-step process: (1) Declare the nodes: nodeID[\"node description\"]. (2) Then define the links: nodeID1 -- \"link text\" --> nodeID2. Node description must always be surrounded with quotation marks. This field is used for the pr_agent:diagram marker if markers are enabled.")
{%- 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.")

View File

@ -538,6 +538,10 @@ class PRDescription:
get_logger().error(f"Failing to process walkthrough {self.pr_id}: {e}")
body = body.replace('pr_agent:walkthrough', "")
ai_diagram = self.data.get('changes_diagram')
if ai_diagram and not re.search(r'<!--\s*pr_agent:diagram\s*-->', body):
body = body.replace('pr_agent:diagram', ai_diagram)
return title, body, walkthrough_gfm, pr_file_changes
def _prepare_pr_answer(self) -> Tuple[str, str, str, List[dict]]: