Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion scripts/langchain/issue_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,29 @@ def _formatted_output_valid(text: str) -> bool:
return all(section in text for section in required)


def _select_code_fence(text: str) -> str:
runs = [len(match.group(0)) for match in re.finditer(r"`+", text)]
fence_len = max(3, max(runs, default=0) + 1)
return "`" * fence_len


def _append_raw_issue_section(formatted: str, issue_body: str) -> str:
raw = issue_body.strip()
if not raw:
return formatted
marker = "<summary>Original Issue</summary>"
if marker in formatted:
Comment on lines +299 to +300

Copilot AI Jan 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplicate detection check only looks for the exact marker string in the formatted output. However, if the original raw issue body contains the text "<summary>Original Issue</summary>" (which could happen if someone is discussing HTML or documenting this feature), the function would incorrectly skip appending the raw issue section when it should still be added. Consider checking for the complete details block structure or using a more unique marker pattern.

Suggested change
marker = "<summary>Original Issue</summary>"
if marker in formatted:
# Avoid appending a duplicate "Original Issue" details block by checking for
# an existing <details>...</details> section with this exact summary.
if re.search(
r"<details>\s*<summary>Original Issue</summary>.*?</details>",
formatted,
flags=re.DOTALL,
):

Copilot uses AI. Check for mistakes.
return formatted
fence = _select_code_fence(raw)
details = (
"\n\n<details>\n"
"<summary>Original Issue</summary>\n\n"
f"{fence}text\n{raw}\n{fence}\n"

Copilot AI Jan 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code fence uses text as the language identifier, which may not provide optimal rendering for issue content that contains markdown formatting. Consider using markdown instead of text or leaving it empty to allow the original issue's markdown formatting to be properly displayed. This would improve readability when viewing the collapsed details section.

Suggested change
f"{fence}text\n{raw}\n{fence}\n"
f"{fence}markdown\n{raw}\n{fence}\n"

Copilot uses AI. Check for mistakes.
"</details>"
)
return f"{formatted.rstrip()}{details}\n"
Comment on lines +289 to +309

Copilot AI Jan 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new functions _select_code_fence and _append_raw_issue_section lack test coverage. Since this repository has comprehensive test coverage for other modules (as seen in the tests directory), these new functions should have corresponding unit tests to verify:

  • Fence selection with various backtick patterns in the input
  • Handling of empty issue bodies
  • Duplicate marker detection
  • Proper HTML details block formatting

Copilot uses AI. Check for mistakes.


def format_issue_body(issue_body: str, *, use_llm: bool = True) -> dict[str, Any]:
if not issue_body:
issue_body = ""
Expand All @@ -306,13 +329,14 @@ def format_issue_body(issue_body: str, *, use_llm: bool = True) -> dict[str, Any
content = getattr(response, "content", None) or str(response)
formatted = content.strip()
if _formatted_output_valid(formatted):
formatted = _append_raw_issue_section(formatted, issue_body)
return {
"formatted_body": formatted,
"provider_used": provider,
"used_llm": True,
}

formatted = _format_issue_fallback(issue_body)
formatted = _append_raw_issue_section(_format_issue_fallback(issue_body), issue_body)
return {
"formatted_body": formatted,
"provider_used": None,
Expand Down
Loading