@@ -85,15 +85,49 @@ module.exports = async ({github, context}) => {
8585 for ( const test of tests ) {
8686 const commentMarker = `<!-- test-failure: ${ test . test_name } -->` ;
8787 const ciLinks = test . jobs . map ( j => ` - \`${ j . job } \`: [CI link](${ j . url } )` ) . join ( '\n' ) ;
88- const historyEntry = `- ${ today } :\n ${ ciLinks } ` ;
88+ const envNames = test . jobs . map ( j => j . job ) ;
8989
9090 const existingComment = comments . find ( c => c . body . includes ( commentMarker ) ) ;
9191
9292 if ( existingComment ) {
93- const updatedComment = existingComment . body . replace (
94- / ( \n - - - \n \* A u t o - t r a c k e d ) / ,
95- `\n${ historyEntry } $1`
96- ) ;
93+ // Parse existing values
94+ const occMatch = existingComment . body . match ( / \* \* O c c u r r e n c e s : \* \* \s * ( \d + ) / ) ;
95+ const occurrences = occMatch ? parseInt ( occMatch [ 1 ] ) + 1 : 2 ;
96+
97+ const envMatch = existingComment . body . match ( / \* \* A f f e c t e d e n v i r o n m e n t s : \* \* \s * ( .+ ) / ) ;
98+ const envInner = envMatch ? envMatch [ 1 ] . match ( / ` ( [ ^ ` ] + ) ` / g) : null ;
99+ const existingEnvs = envInner ? envInner . map ( e => e . replace ( / ` / g, '' ) ) : [ ] ;
100+ const allEnvs = [ ...new Set ( [ ...existingEnvs , ...envNames ] ) ] ;
101+
102+ // Keep first seen and first CI unchanged — extract them
103+ const firstSeenMatch = existingComment . body . match ( / \* \* F i r s t s e e n : \* \* \s * ( .+ ) / ) ;
104+ const firstSeen = firstSeenMatch ? firstSeenMatch [ 1 ] . trim ( ) : today ;
105+
106+ const firstCIMatch = existingComment . body . match ( / \* \* F i r s t C I : \* \* \n ( [ \s \S ] * ?) \n \* \* L a s t s e e n : / ) ;
107+ const firstCI = firstCIMatch ? firstCIMatch [ 1 ] . trim ( ) : ciLinks ;
108+
109+ const updatedComment = [
110+ commentMarker ,
111+ `**Test:** \`${ test . test_name } \`` ,
112+ `` ,
113+ `**Error:**` ,
114+ '```' ,
115+ test . error || 'N/A' ,
116+ '```' ,
117+ `` ,
118+ `**First seen:** ${ firstSeen } ` ,
119+ `**First CI:**` ,
120+ firstCI ,
121+ `**Last seen:** ${ today } ` ,
122+ `**Occurrences:** ${ occurrences } ` ,
123+ `**Affected environments:** ${ allEnvs . map ( e => '`' + e + '`' ) . join ( ', ' ) } ` ,
124+ `**Latest CI:**` ,
125+ ciLinks ,
126+ `` ,
127+ `---` ,
128+ `*Auto-tracked by Test Failure Detector*` ,
129+ ] . join ( '\n' ) ;
130+
97131 await github . rest . issues . updateComment ( {
98132 owner : context . repo . owner ,
99133 repo : context . repo . repo ,
@@ -102,6 +136,7 @@ module.exports = async ({github, context}) => {
102136 } ) ;
103137 console . log ( ` Updated comment for test: ${ test . test_name } ` ) ;
104138 } else {
139+ // Create new comment for this test
105140 await github . rest . issues . createComment ( {
106141 owner : context . repo . owner ,
107142 repo : context . repo . repo ,
@@ -115,8 +150,14 @@ module.exports = async ({github, context}) => {
115150 test . error || 'N/A' ,
116151 '```' ,
117152 `` ,
118- `**Failure history:**` ,
119- historyEntry ,
153+ `**First seen:** ${ today } ` ,
154+ `**First CI:**` ,
155+ ciLinks ,
156+ `**Last seen:** ${ today } ` ,
157+ `**Occurrences:** 1` ,
158+ `**Affected environments:** ${ envNames . map ( e => '`' + e + '`' ) . join ( ', ' ) } ` ,
159+ `**Latest CI:**` ,
160+ ciLinks ,
120161 `` ,
121162 `---` ,
122163 `*Auto-tracked by Test Failure Detector*` ,
@@ -127,6 +168,7 @@ module.exports = async ({github, context}) => {
127168 }
128169
129170 } else {
171+ // Create new issue for this test file
130172 console . log ( `Creating issue for ${ testFile } ` ) ;
131173 const issue = await github . rest . issues . create ( {
132174 owner : context . repo . owner ,
@@ -144,9 +186,11 @@ module.exports = async ({github, context}) => {
144186 ] . join ( '\n' ) ,
145187 } ) ;
146188
189+ // Create one comment per failing test
147190 for ( const test of tests ) {
148191 const commentMarker = `<!-- test-failure: ${ test . test_name } -->` ;
149192 const ciLinks = test . jobs . map ( j => ` - \`${ j . job } \`: [CI link](${ j . url } )` ) . join ( '\n' ) ;
193+ const envNames = test . jobs . map ( j => j . job ) ;
150194
151195 await github . rest . issues . createComment ( {
152196 owner : context . repo . owner ,
@@ -161,8 +205,13 @@ module.exports = async ({github, context}) => {
161205 test . error || 'N/A' ,
162206 '```' ,
163207 `` ,
164- `**Failure history:**` ,
165- `- ${ today } :` ,
208+ `**First seen:** ${ today } ` ,
209+ `**First CI:**` ,
210+ ciLinks ,
211+ `**Last seen:** ${ today } ` ,
212+ `**Occurrences:** 1` ,
213+ `**Affected environments:** ${ envNames . map ( e => '`' + e + '`' ) . join ( ', ' ) } ` ,
214+ `**Latest CI:**` ,
166215 ciLinks ,
167216 `` ,
168217 `---` ,
0 commit comments