diff --git a/CHANGELOG.md b/CHANGELOG.md index a13d91ed0..dbe86a54c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- The GitHub issue fetch finds the acceptance criteria under a `##`, `###` or `####` heading. The section ends at the next heading of the same level or a higher level (#808). + --- ## [3.20.0] - 2026-11-23 diff --git a/src/assets/mds/tracker/_github.mds b/src/assets/mds/tracker/_github.mds index 450e3d27c..047c7b67d 100644 --- a/src/assets/mds/tracker/_github.mds +++ b/src/assets/mds/tracker/_github.mds @@ -122,7 +122,7 @@ gh issue view "$ISSUE_NUMBER" \ BODY=$(gh issue view "$ISSUE" --json body -q '.body') # Extract acceptance criteria -CRITERIA=$(printf '%s\n' "$BODY" | tr -d '\r' | awk 'tolower($0) ~ /^##[[:blank:]]*acceptance criteria:?[[:blank:]]*$/ {f=1; next} /^##[[:blank:]]/ {f=0} f' | grep -E '^[[:space:]]*([-*]|[0-9]+[.)])[[:space:]]+[^[:space:]]' || true) +CRITERIA=$(printf '%s\n' "$BODY" | tr -d '\r' | awk '/^[[:blank:]]*([`][`][`]|~~~)/ {c=!c} {h=0; if (!c && match($0, /^#+/)) h=RLENGTH; t=tolower(substr($0, h+1))} f && h && h<=lvl && (t=="" || t ~ /^[[:blank:]]/) {f=0} !f && h>=2 && h<=4 && t ~ /^[[:blank:]]*acceptance criteria:?[[:blank:]]*$/ {f=1; lvl=h; next} f' | grep -E '^[[:space:]]*([-*]|[0-9]+[.)])[[:space:]]+[^[:space:]]' || true) # Extract dependencies DEPENDS_ON=$(echo "$BODY" | grep -oE '(depends on|blocked by) #[0-9]+' | grep -oE '#[0-9]+' || true) diff --git a/tests/tracker/setup-task-common.test.ts b/tests/tracker/setup-task-common.test.ts index ca7d14bfa..9e289deaa 100644 --- a/tests/tracker/setup-task-common.test.ts +++ b/tests/tracker/setup-task-common.test.ts @@ -262,8 +262,14 @@ function runRecipe(recipe: string, body: string): { status: number | null; crite const RETIRED_RECIPE = `CRITERIA=$(echo "$BODY" | sed -n '/## Acceptance Criteria/,/^##/p' | grep -E '^\\s*-\\s*\\[' || true)` +/** The level-2-only recipe #808 replaced — a known-bad sample for `###` headings. */ +const LEVEL_2_ONLY_RECIPE = + `CRITERIA=$(printf '%s\\n' "$BODY" | tr -d '\\r' | awk 'tolower($0) ~ /^##[[:blank:]]*acceptance criteria:?[[:blank:]]*$/ {f=1; next} /^##[[:blank:]]/ {f=0} f' | grep -E '^[[:space:]]*([-*]|[0-9]+[.)])[[:space:]]+[^[:space:]]' || true)` + const NUMBERED_LOWERCASE = '## acceptance criteria:\n1. first item\n2) second item\n\n## Notes\n- [ ] not a criterion\n' +const LEVEL_3 = '### Cause\nText.\n\n### Acceptance criteria\n\n- [ ] AC-1: one\n- [ ] AC-2: two\n' + describe('fetch-issue: the acceptance-criteria recipe, executed', () => { const recipe = collectCriteriaRecipe(requireRef('tracker/github/fetch-issue.md')) @@ -282,6 +288,21 @@ describe('fetch-issue: the acceptance-criteria recipe, executed', () => { }, { label: 'CRLF line endings', body: '## Acceptance Criteria\r\n- [ ] one\r\n- two\r\n', expected: '- [ ] one\n- two' }, { label: 'no heading', body: 'Nothing here\n- [ ] stray\n', expected: '' }, + { label: 'a ### heading starts the section', body: LEVEL_3, expected: '- [ ] AC-1: one\n- [ ] AC-2: two' }, + { + label: 'a #### heading with a colon, a nested ##### stays inside, a following ### ends it', + body: '#### acceptance criteria:\n- a\n##### Detail\n- b\n### Notes\n- [ ] c\n', + expected: '- a\n- b', + }, + { label: 'a higher-level # heading ends a ### section', body: '### Acceptance criteria\n- a\n# Top\n- c\n', expected: '- a' }, + { label: 'a # or ##### heading starts no section', body: '# Acceptance criteria\n- a\n##### Acceptance criteria\n- b\n', expected: '' }, + { label: 'a second ### heading ends a ### section', body: '### Acceptance criteria\n- a\n### Notes\n- c\n', expected: '- a' }, + { + label: 'a # comment inside a code fence does not end the section', + body: '## Acceptance criteria\n- [ ] AC-1 one\n\n```bash\n# build it\n## step\nnpm run build\n```\n\n~~~\n#\n~~~\n- [ ] AC-2 two\n## Notes\n- c\n', + expected: '- [ ] AC-1 one\n- [ ] AC-2 two', + }, + { label: 'no space after the hashes, trailing blanks', body: '##Acceptance criteria \t\n- a\n## Notes\n- c\n', expected: '- a' }, ] for (const { label, body, expected } of cases) { @@ -294,6 +315,7 @@ describe('fetch-issue: the acceptance-criteria recipe, executed', () => { it('known-bad probe: the retired recipe misses the numbered, lowercase section', () => { expect(runRecipe(RETIRED_RECIPE, NUMBERED_LOWERCASE).criteria).toBe('') + expect(runRecipe(LEVEL_2_ONLY_RECIPE, LEVEL_3).criteria).toBe('') expect(collectCriteriaRecipe('BODY=$(x)\n# nothing\n')).toBeNull() }) })