π OpenHands: AI-Driven Development
fix(ci): accept h2 readiness sections (#17011)
Graham Neubig74c224fb5af7
diff --git a/.github/scripts/check_issue_readiness.py b/.github/scripts/check_issue_readiness.pyindex dfd1409813..7c5e3a911b 100644--- a/.github/scripts/check_issue_readiness.py+++ b/.github/scripts/check_issue_readiness.py@@ -13,9 +13,9 @@ The criteria are type-specific:one checklist item.GitHub issue forms render each field as an `### <Label>` (h3) heading followed-by the field text, with empty optional fields rendered as `_No response_`. This-parser splits the body on those headings so each criterion is checked against-the right field rather than the whole body.+by the field text, with empty optional fields rendered as `_No response_`. The+parser also accepts `## <Label>` headings used by hand-edited and free-form+issues, and checks each criterion against the corresponding section.Local usage:@@ -39,10 +39,21 @@ from markdown_sections import find_headingsBUG_LABEL = "bug"ENHANCEMENT_LABEL = "enhancement"-# Issue-form fields render as `### Label` h3 headings. Match case-insensitively-# and tolerate trailing whitespace/colons. `^###\s+` is specific enough because-# h1/h2 are not produced by issue forms.-HEADING_RE = re.compile(r"(?m)^###\s+(.+?)\s*$")+# Issue-form fields render as h3 headings, while hand-edited and free-form+# issues commonly use h2. Capture the level so nested h3 headings can remain+# part of an h2 section.+HEADING_RE = re.compile(r"(?m)^(?P<level>#{2,3})\s+(?P<title>.+?)\s*$")++READINESS_SECTION_LABELS = {+ "steps to reproduce",+ "reproduction",+ "actual behavior",+ "actual",+ "desired behavior",+ "desired",+ "acceptance criteria",+ "acceptance",+}# `_No response_` is what GitHub writes for an empty optional form field.NO_RESPONSE = "_No response_"@@ -104,18 +115,30 @@ def visible_text(text: str) -> str:def extract_sections(body: str) -> dict[str, str]:- """Split the body into a {heading: text} map using `### <heading>` boundaries.+ """Split the body into a {heading: text} map using h2 or h3 boundaries.- Issue forms render every field this way. Free-form issues (not created via a- form) may still use `###` headings; if they don't, the map is empty and the- caller falls back to whole-body checks.+ Issue forms render fields as h3 headings. Free-form and hand-edited issues+ may use h2 headings instead, including a mix of both levels."""matches = find_headings(body, HEADING_RE)+ has_h2 = any(match.group("level") == "##" for match in matches)+ boundaries = [+ match+ for match in matches+ if match.group("level") == "##"+ or not has_h2+ or match.group("title").strip().lower() in READINESS_SECTION_LABELS+ ]+sections: dict[str, str] = {}- for index, match in enumerate(matches):+ for index, match in enumerate(boundaries):start = match.end()- end = matches[index + 1].start() if index + 1 < len(matches) else len(body)- sections[match.group(1).strip().lower()] = body[start:end]+ end = (+ boundaries[index + 1].start()+ if index + 1 < len(boundaries)+ else len(body)+ )+ sections[match.group("title").strip().lower()] = body[start:end]return sectionsdiff --git a/.github/scripts/tests/test_issue_readiness.py b/.github/scripts/tests/test_issue_readiness.pyindex cc56a9b12d..1dd6961fc2 100644--- a/.github/scripts/tests/test_issue_readiness.py+++ b/.github/scripts/tests/test_issue_readiness.py@@ -257,6 +257,57 @@ def test_extract_sections():assert "Text 1" in sections["title one"]assert "Text 2" in sections["title two"]++def test_bug_ready_with_h2_sections():+ body = BUG_BODY_READY.replace("### ", "## ")+ result = evaluate_readiness(body, [BUG_LABEL])+ assert result.ready, result.reasons+++def test_enhancement_ready_with_mixed_h2_h3_sections():+ body = ENHANCEMENT_BODY_READY.replace(+ "### Desired Behavior", "## Desired Behavior"+ )+ result = evaluate_readiness(body, [ENHANCEMENT_LABEL])+ assert result.ready, result.reasons+++def test_extract_sections_excludes_h1_and_h4_headings():+ body = "# Document Title\nintro\n#### Nested Detail\ntext"+ assert extract_sections(body) == {}+++def test_nested_h3_stays_inside_h2_readiness_section():+ body = """## Steps to Reproduce+Run `npm run dev`.++## Actual Behavior+The page is broken.++### Screenshot+++## Acceptance Criteria+- [ ] The page works+"""+ result = evaluate_readiness(body, [BUG_LABEL])+ assert result.ready, result.reasons+ assert "### Screenshot" in extract_sections(body)["actual behavior"]+++def test_extract_sections_ignores_h2_heading_inside_fence():+ body = """## Notes+The template says:++```markdown+## Acceptance Criteria+- [ ] Add criteria here+```+"""+ sections = extract_sections(body)+ assert set(sections) == {"notes"}++def test_extract_sections_ignores_heading_inside_fence():body = """### NotesThe template says:diff --git a/.pr/17010-readiness-heading-evidence.png b/.pr/17010-readiness-heading-evidence.pngnew file mode 100644index 0000000000..fb7edc7b0aBinary files /dev/null and b/.pr/17010-readiness-heading-evidence.png differ