okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
f57c0adcb
main
1'use strict' ; 2// Format check for issues and pull requests (see CONTRIBUTING.md and .github/ISSUE_TEMPLATE/*.yml). 3// Pure functions only: no network, no filesystem. Used by intake.yml and reopen.yml through reset-bot.js. 4 5const AREAS = [ 'Engine' , 'GUI' , 'TUI' , 'Benchmark' , 'Docs' , 'Other' ]; 6const TITLE_RE = new RegExp ( '^\\[(' + AREAS . join ( '|' ) + ')\\] \\S' ); 7const NO_ANSWER = / ^ ( _no response_ | none | n\/a | na | - | todo | tbd | \. | \? ) $ / i ; 8const NOT_RUN_LABELS = / ^\*\* ( passed | failed | not run ) \s * : ? \*\*\s * : ?/ gim ; 9 10// Version the reopened work must be tested on. 11const CURRENT_VERSION_RE = / \b0\.2\.\d +| 0\.2\.0-beta / i ; 12// Any version or commit. 13const ANY_VERSION_RE = / \bv ? \d + \.\d + ( \.\d + ) * ( - [ a - z0 - 9. ] + ) ? \b | \b [ 0 - 9a - f ]{ 7 , 40 } \b | \bcommit\b / i ; 14const HARDWARE_RE = / \b ( rtx | gtx | geforce | quadro | tesla | radeon | rx ? \d | instinct | arc | a\d { 3 , 4 } | b\d { 2 , 3 } | apple | m [ 1 - 5 ]( pro | max | ultra ) ?| nvidia | amd | intel | gpu | cpu | vram | \d + ? gb | ram | windows | linux | ubuntu | debian | fedora | arch | macos | mac os | wsl ) \b / i ; 15const REVISION_RE = / 0\.2\.\d | beta | \bmain\b | \b [ 0 - 9a - f ]{ 7 , 40 } \b / i ; 16 17function stripComments ( text ) { 18return String ( text || '' ). replace ( / <!-- [ \s\S ] * ?--> / g , '' ); 19} 20 21function hasAreaPrefix ( title ) { 22return TITLE_RE . test ( String ( title || '' )); 23} 24 25// Issue forms render as "### Label\n\nvalue". Returns { label: value } for those headings. 26function parseSections ( body ) { 27const out = {}; 28let cur = null ; 29for ( const line of stripComments ( body ). split ( / \r ? \n / )) { 30const m = / ^# { 1 , 6 } \s + ( . + ? ) \s * # * \s * $ / . exec ( line ); 31if ( m ) { 32cur = m [ 1 ]. trim (); 33out [ cur ] = '' ; 34} else if ( cur !== null ) { 35out [ cur ] += line + '\n' ; 36} 37} 38for ( const k of Object . keys ( out )) out [ k ] = out [ k ]. trim (); 39return out ; 40} 41 42function realText ( value ) { 43const t = String ( value || '' ). replace ( NOT_RUN_LABELS , '' ). replace ( / \s +/ g , ' ' ). trim (); 44return NO_ANSWER . test ( t ) ?'' :t ; 45} 46 47function findSection ( sections , re ) { 48for ( const k of Object . keys ( sections )) if ( re . test ( k )) return { key :k , value :sections [ k ] }; 49return null ; 50} 51 52// Required parts of each issue form: [display name, heading regex, minimum characters of real text]. 53const FORMS = { 54bug :{ 55detect :/ what happened / i , 56parts :[ 57[ 'Area' , / ^area$ / i , 2 ], 58[ 'Desktop app, Terminal or source?' , / desktop app, terminal or source / i , 2 ], 59[ 'What happened' , / what happened / i , 20 ], 60[ 'Reproduction status' , / reproduction status / i , 2 ], 61[ 'Strata version' , / strata version / i , 3 ], 62[ 'Graphics card, memory and system' , / graphics card | memory and system / i , 3 ], 63], 64needsCurrentVersion :'Strata version' , 65}, 66feature :{ 67detect :/ what do you want to do / i , 68parts :[ 69[ 'Area' , / ^area$ / i , 2 ], 70[ 'What do you want to do?' , / what do you want to do / i , 20 ], 71], 72}, 73question :{ 74detect :/ your question / i , 75parts :[ 76[ 'Area' , / ^area$ / i , 2 ], 77[ 'Your question' , / your question / i , 15 ], 78], 79}, 80benchmark :{ 81detect :/ what did you measure / i , 82parts :[ 83[ 'What did you measure, or what went wrong' , / what did you measure / i , 30 ], 84[ 'Reproduction status' , / reproduction status / i , 2 ], 85], 86needsCurrentVersionInBody :true , 87}, 88}; 89 90function checkIssue ({ title, body, labels= [], mode= 'intake' }) { 91const missing = []; 92if ( ! hasAreaPrefix ( title )) { 93missing . push ( 'Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".' ); 94} 95const text = stripComments ( body ); 96const sections = parseSections ( text ); 97const labelSet = new Set ( labels . map (( l ) => String ( l ). toLowerCase ())); 98const needCurrent = mode === 'reopen' ; 99 100let formKey = null ; 101for ( const [ key , f ] of Object . entries ( FORMS )) { 102if ( findSection ( sections , f . detect )) { formKey = key ; break ; } 103} 104 105if ( formKey ) { 106const form = FORMS [ formKey ]; 107for ( const [ name , re , min ] of form . parts ) { 108const s = findSection ( sections , re ); 109if ( ! s || realText ( s . value ). length < min ) missing . push ( 'Fill in "' + name + '".' ); 110} 111if ( needCurrent && form . needsCurrentVersion ) { 112const s = findSection ( sections , / strata version / i ); 113if ( s && realText ( s . value ) && ! CURRENT_VERSION_RE . test ( s . value )) { 114missing . push ( 'Re-test on Strata 0.2.0-beta and put that version in "' + form . needsCurrentVersion + '". If it no longer happens, say so in a comment instead.' ); 115} 116} 117if ( needCurrent && form . needsCurrentVersionInBody && ! CURRENT_VERSION_RE . test ( text )) { 118missing . push ( 'Say which Strata version you measured on. Re-measure on 0.2.0-beta if you can.' ); 119} 120return { ok :missing . length === 0 , missing, kind :formKey }; 121} 122 123// Free-form text (older issues, blank issues). 124const plain = realText ( text ); 125const lenient = labelSet . has ( 'enhancement' ) || labelSet . has ( 'question' ); 126if ( plain . length < ( lenient ?40 :80 )) { 127missing . push ( 'Describe it in the issue body: what happened, what you expected, and the exact error if there is one. The issue forms (New issue > Bug report) list what to include.' ); 128} 129if ( ! lenient ) { 130if ( ! ANY_VERSION_RE . test ( text )) missing . push ( 'Add the Strata version (Settings > About, or `strata --version`).' ); 131else if ( needCurrent && ! CURRENT_VERSION_RE . test ( text )) missing . push ( 'Re-test on Strata 0.2.0-beta and name that version in the issue. If it no longer happens, say so in a comment instead.' ); 132if ( ! HARDWARE_RE . test ( text )) missing . push ( 'Add your graphics card with its VRAM, your RAM and your operating system.' ); 133} 134return { ok :missing . length === 0 , missing, kind :'free-form' }; 135} 136 137function checkPull ({ title, body, mode= 'intake' }) { 138const missing = []; 139if ( ! hasAreaPrefix ( title )) { 140missing . push ( 'Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] fix decode stop on long prompts".' ); 141} 142const text = stripComments ( body ); 143const sections = parseSections ( text ); 144const problem = findSection ( sections , / problem | result | summary | what. * change / i ); 145const validation = findSection ( sections , / validation | testing | tests ? \b | how. * tested / i ); 146 147let valText = '' ; 148if ( problem || validation ) { 149if ( ! problem || realText ( problem . value ). length < 20 ) missing . push ( 'Fill in "Problem and result": what triggered the change, and how it behaves before and after.' ); 150if ( ! validation || realText ( validation . value ). length < 20 ) { 151missing . push ( 'Fill in "Validation": the exact commands, the revision and environment tested, what you saw. Keep Passed, Failed and Not run apart.' ); 152} else { 153valText = validation . value ; 154} 155} else { 156const plain = realText ( text ); 157if ( plain . length < 150 ) { 158missing . push ( 'Describe the pull request: the problem and the result. The pull request template shows the parts (Problem and result, Related discussion, Approach, Validation, Limits).' ); 159} 160if ( ! / ( problem | result | before | after | fix | because | bug ) / i . test ( plain )) missing . push ( 'Add "Problem and result": what triggered the change, and how it behaves before and after.' ); 161if ( ! / ( validat | tested | passed | ran | built | build | not run ) / i . test ( plain )) missing . push ( 'Add "Validation": the exact commands, the revision and environment tested, and what you saw.' ); 162valText = plain ; 163} 164if ( mode === 'reopen' && valText && ! REVISION_RE . test ( valText )) { 165missing . push ( 'Say in Validation which revision you tested: rebase on main (or 0.2.0-beta) and re-run your checks.' ); 166} 167return { ok :missing . length === 0 , missing, kind :'pull' }; 168} 169 170function checkItem ({ isPull, ...rest }) { 171return isPull ?checkPull ( rest ) :checkIssue ( rest ); 172} 173 174function checklist ( missing ) { 175return missing . map (( m ) => '- [ ] ' + m ). join ( '\n' ); 176} 177 178const CONTRIB = 'https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md' ; 179 180function intakeComment ( isPull , missing ) { 181return [ 182'Thanks for the ' + ( isPull ?'pull request' :'issue' ) + '. To keep the tracker readable, every item needs an area prefix in the title and the parts of the ' + ( isPull ?'pull request template' :'issue form' ) + ' filled in. This one is missing:' , 183'' , 184checklist ( missing ), 185'' , 186'Edit the ' + ( isPull ?'pull request' :'issue' ) + ' (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`.' , 187'' , 188'Details: [CONTRIBUTING.md](' + CONTRIB + ')' , 189]. join ( '\n' ); 190} 191 192function reopenMissingComment ( isPull , missing ) { 193return [ 194'Not reopened yet. Still missing:' , 195'' , 196checklist ( missing ), 197'' , 198'Edit the ' + ( isPull ?'pull request' :'issue' ) + ' and comment `/reopen` again. Details: [CONTRIBUTING.md](' + CONTRIB + ')' , 199]. join ( '\n' ); 200} 201 202function reopenOkComment ( isPull ) { 203return 'Reopened, thank you. A maintainer will pick it up from here.' + ( isPull ?' If it conflicts with main, rebase it first; that speeds up review.' :'' ); 204} 205 206function staleComment ( isPull ) { 207return [ 208'Closing this ' + ( isPull ?'pull request' :'issue' ) + ' because it still did not follow the format after 5 days. That is housekeeping, not a rejection.' , 209'' , 210'To bring it back: fix the title (area prefix) and the missing parts, then comment `/reopen`. A check runs and reopens it, or tells you what is still missing. See [CONTRIBUTING.md](' + CONTRIB + ').' , 211]. join ( '\n' ); 212} 213 214module . exports = { 215AREAS , TITLE_RE , hasAreaPrefix, parseSections, stripComments, realText, 216 checkIssue, checkPull, checkItem, checklist, 217 intakeComment, reopenMissingComment, reopenOkComment, staleComment, 218};