66// ---------------------------------------------------------------------------
77
88/**
9- * Strip HTML comments, "No response" placeholders, and trim whitespace.
9+ * True when the entire meaningful value is a placeholder-only token.
10+ * Supports harmless Markdown emphasis/code markers and trailing punctuation.
11+ * Sentences that merely contain a placeholder phrase are not matches.
12+ */
13+ const PLACEHOLDER_ONLY_RE =
14+ / ^ [ \s _ * ~ ` ] * (?: n o \s + r e s p o n s e | n \/ ? a | n o t \s + a p p l i c a b l e | n o t \s + a v a i l a b l e | n o n e | t o d o | t b d ) [ \s _ * ~ ` ] * [ . ! ? ] * $ / i;
15+
16+ /**
17+ * If `text` is exactly one enclosing fenced code block (``` or ~~~), return the
18+ * inner body; otherwise null. Real multi-statement fences are left alone by
19+ * the placeholder matcher after unwrap.
20+ */
21+ function unwrapSingleEnclosingFence ( text ) {
22+ const trimmed = text . trim ( ) ;
23+ const match = trimmed . match ( / ^ ( ` ` ` | ~ ~ ~ ) [ ^ \n ] * \r ? \n ( [ \s \S ] * ?) \r ? \n \1[ \t ] * $ / ) ;
24+ if ( ! match ) return null ;
25+ return match [ 2 ] ;
26+ }
27+
28+ function isPlaceholderOnlyValue ( raw ) {
29+ if ( typeof raw !== "string" ) return false ;
30+ let value = raw . replace ( / < ! - - [ \s \S ] * ?- - > / g, "" ) . trim ( ) ;
31+ if ( ! value ) return false ;
32+
33+ // A lone fenced block whose entire body is a placeholder is still placeholder
34+ // text (e.g. ```text\nN/A\n```), not a real example.
35+ const unwrapped = unwrapSingleEnclosingFence ( value ) ;
36+ if ( unwrapped !== null ) {
37+ value = unwrapped . trim ( ) ;
38+ if ( ! value ) return false ;
39+ }
40+
41+ return PLACEHOLDER_ONLY_RE . test ( value ) ;
42+ }
43+
44+ /**
45+ * Strip HTML comments, placeholder-only values, and trim whitespace.
1046 */
1147function clean ( raw ) {
1248 if ( typeof raw !== "string" ) return "" ;
1349 let s = raw . replace ( / < ! - - [ \s \S ] * ?- - > / g, "" ) ;
14- // Treat GitHub's "No response" placeholder as empty.
15- s = s . replace ( / ^ [ \s _ * ] * N o r e s p o n s e [ \s _ * ] * $ / gim, "" ) ;
50+ // Whole-value placeholders first (including a single enclosing fence), so
51+ // line-by-line stripping cannot leave bare fence markers behind.
52+ if ( isPlaceholderOnlyValue ( s ) ) return "" ;
53+ // Treat placeholder-only lines (GitHub "No response", N/A, etc.) as empty.
54+ s = s
55+ . split ( "\n" )
56+ . map ( ( line ) => ( isPlaceholderOnlyValue ( line ) ? "" : line ) )
57+ . join ( "\n" ) ;
58+ if ( isPlaceholderOnlyValue ( s ) ) return "" ;
1659 return s . trim ( ) ;
1760}
1861
@@ -329,29 +372,52 @@ function allRepeatTitle(sections, title) {
329372}
330373
331374function isPlaceholder ( text ) {
375+ return isPlaceholderOnlyValue ( text ) ;
376+ }
377+
378+ const CJK_RE =
379+ / [ \p{ Script= Han} \p{ Script= Hiragana} \p{ Script= Katakana} \p{ Script= Hangul} ] / gu;
380+
381+ function countWords ( text ) {
382+ const c = clean ( text ) ;
383+ if ( ! c ) return 0 ;
384+
385+ // Count each CJK character as one unit, and non-CJK scripts as Unicode
386+ // word tokens. Mixing one CJK glyph into a Latin/Cyrillic word must not
387+ // inflate the count to letter-length.
388+ const cjkChars = c . match ( CJK_RE ) || [ ] ;
389+ const nonCjkText = c . replace ( CJK_RE , " " ) ;
390+ const nonCjkTokens = nonCjkText . match ( / [ \p{ L} \p{ N} ' ] + / gu) || [ ] ;
391+
392+ return cjkChars . length + nonCjkTokens . length ;
393+ }
394+
395+ function hasConcreteDetail ( text ) {
332396 const c = clean ( text ) ;
333- if ( ! c ) return true ;
334- const lower = c . toLowerCase ( ) ;
397+ if ( ! c ) return false ;
335398 return (
336- lower === "no response" ||
337- lower === "n/a" ||
338- lower === "none" ||
339- lower === "todo" ||
340- lower === "tbd" ||
341- / ^ _ n o r e s p o n s e _ $ / i. test ( c )
399+ / \d / . test ( c ) ||
400+ / [ ` { } \[ \] < > / \\ ] / . test ( c ) ||
401+ / \b ( o c x | c o n f i g | a p i | c l i | d a s h b o a r d | p r o v i d e r | p r o x y | r o u t e | e n d p o i n t | w o r k f l o w | c o m m a n d ) \b / i. test ( c )
342402 ) ;
343403}
344404
405+ function isTooTerseFeatureSection ( text ) {
406+ if ( isEmpty ( text ) || isPlaceholder ( text ) ) return false ;
407+ const words = countWords ( text ) ;
408+ if ( words >= 8 ) return false ;
409+ if ( words >= 6 && hasConcreteDetail ( text ) ) return false ;
410+ return true ;
411+ }
412+
345413/**
346- * Check if raw section text is a GitHub "No response" placeholder variant
347- * without stripping it first. Used to distinguish intentionally blank optional
348- * fields from actively cleared required fields.
414+ * Check if raw section text is a placeholder-only variant without relying on
415+ * clean() first. Used to distinguish intentionally blank optional fields
416+ * (legacy "No response" / N/A) from actively cleared required fields.
349417 */
350418function isRawPlaceholder ( raw ) {
351419 if ( raw === null ) return false ;
352- const trimmed = raw . trim ( ) ;
353- if ( ! trimmed ) return false ;
354- return / ^ [ \s _ * ] * n o r e s p o n s e [ \s _ * ] * $ / i. test ( trimmed ) ;
420+ return isPlaceholderOnlyValue ( raw ) ;
355421}
356422
357423/**
@@ -386,7 +452,12 @@ function validateIssue(issue) {
386452 // On the legacy / translated forms these sections may be absent (null).
387453 if ( blocker !== null && isEmpty ( blocker ) ) emptyCore . push ( "current limitation" ) ;
388454 if ( isEmpty ( behaviour ) ) emptyCore . push ( "expected behaviour" ) ;
389- if ( example !== null && isEmpty ( example ) ) emptyCore . push ( "example usage" ) ;
455+ if ( example !== null && isPlaceholder ( example ) ) {
456+ reasons . push ( "Example usage or interface contains placeholder text instead of a concrete example." ) ;
457+ guidance . push ( "Add a real CLI command, config snippet, API exchange, or before/after workflow example." ) ;
458+ } else if ( example !== null && isEmpty ( example ) ) {
459+ emptyCore . push ( "example usage" ) ;
460+ }
390461
391462 const mappedHeadingPresent =
392463 goal !== null || blocker !== null || behaviour !== null || example !== null ;
@@ -421,6 +492,15 @@ function validateIssue(issue) {
421492 guidance . push ( "Replace placeholder text with your actual proposal." ) ;
422493 }
423494 }
495+
496+ const terseSections = [ ] ;
497+ if ( goal !== null && isTooTerseFeatureSection ( goal ) ) terseSections . push ( "goal / problem" ) ;
498+ if ( blocker !== null && isTooTerseFeatureSection ( blocker ) ) terseSections . push ( "current limitation" ) ;
499+ if ( behaviour !== null && isTooTerseFeatureSection ( behaviour ) ) terseSections . push ( "expected behaviour" ) ;
500+ if ( terseSections . length > 0 ) {
501+ reasons . push ( `Required sections are too vague to act on: ${ terseSections . join ( ", " ) } .` ) ;
502+ guidance . push ( "Describe the workflow, limitation, and expected behaviour with enough detail for someone to implement or evaluate the request." ) ;
503+ }
424504 }
425505
426506 if ( kind === "bug" ) {
@@ -587,6 +667,47 @@ function shouldReopen(botState, issue, maintainerOverride) {
587667 return true ;
588668}
589669
670+ /**
671+ * workflow_dispatch accepts a bare issue number, but GitHub reuses the same
672+ * number namespace for issues and pull requests. Reject PR targets before any
673+ * validation or mutation runs.
674+ *
675+ * @param {{ pull_request?: unknown } } issue
676+ * @param {number|string } issueNumber
677+ * @param {string } eventName
678+ * @returns {string|null }
679+ */
680+ function rejectsWorkflowDispatchPullRequest ( issue , issueNumber , eventName ) {
681+ if ( eventName !== "workflow_dispatch" ) return null ;
682+ if ( ! issue ?. pull_request ) return null ;
683+ return `#${ issueNumber } is a pull request. This workflow only accepts issue numbers.` ;
684+ }
685+
686+ /**
687+ * workflow_dispatch can be started from a selected branch. Reject runs whose
688+ * selected ref is not the repository default branch so untrusted branch code
689+ * cannot drive issue mutations with issues:write.
690+ *
691+ * @param {string } eventName
692+ * @param {string|null|undefined } ref
693+ * @param {string|null|undefined } defaultBranch
694+ * @returns {string|null }
695+ */
696+ function rejectsWorkflowDispatchNonDefaultBranch ( eventName , ref , defaultBranch ) {
697+ if ( eventName !== "workflow_dispatch" ) return null ;
698+ if ( ! defaultBranch || typeof defaultBranch !== "string" ) {
699+ return "workflow_dispatch requires repository.default_branch to be available." ;
700+ }
701+ const expected = `refs/heads/${ defaultBranch } ` ;
702+ if ( ref !== expected ) {
703+ return (
704+ `workflow_dispatch must run from the default branch (${ defaultBranch } ); ` +
705+ `selected ref was ${ ref || "(empty)" } .`
706+ ) ;
707+ }
708+ return null ;
709+ }
710+
590711// ---------------------------------------------------------------------------
591712// Exports
592713// ---------------------------------------------------------------------------
@@ -601,8 +722,14 @@ module.exports = {
601722 validateIssue,
602723 shouldReopen,
603724 shouldEnforceClosure,
725+ isPlaceholderOnlyValue,
726+ isPlaceholder,
604727 isRawPlaceholder,
728+ countWords,
729+ hasConcreteDetail,
605730 labelForKind,
606731 KIND_TO_LABEL ,
607732 hasSubstantialStructuredContent,
733+ rejectsWorkflowDispatchPullRequest,
734+ rejectsWorkflowDispatchNonDefaultBranch,
608735} ;
0 commit comments