@@ -89,29 +89,45 @@ else {
89
89
const trunctationSuffix = `\n:error: Truncated - see log for full output :error:` ;
90
90
91
91
// GH caps the maximum body length, so paginate if necessary
92
+ const maxCommentLength = 65535 ;
93
+
92
94
const bodyChunks : string [ ] = [ ] ;
93
95
let chunk = initialHeader ;
94
- for ( const output of outputs ) {
95
- if ( chunk . length + output . length + closeDetails . length > 65535 ) {
96
- if ( chunk === initialHeader || chunk === continuationHeader ) {
97
- // output is too long and bumping it to the next comment won't help
98
- console . log ( "Truncating output to fit in GH comment" ) ;
99
- chunk += output . substring ( 0 , 65535 - chunk . length - closeDetails . length - trunctationSuffix . length ) ;
100
- chunk += trunctationSuffix ;
101
- chunk += closeDetails ;
102
- bodyChunks . push ( chunk ) ;
103
- chunk = continuationHeader ;
104
- continue ; // Specifically, don't append output below
105
- }
106
96
97
+ for ( let i = 0 ; i < outputs . length ; ) {
98
+ const output = outputs [ i ] ;
99
+ if ( ( chunk . length + output . length + closeDetails . length ) < maxCommentLength ) {
100
+ // Output still fits within chunk; add and continue.
101
+ chunk += output ;
102
+ i ++ ;
103
+ continue ;
104
+ }
105
+
106
+ // The output is too long to fit in the current chunk.
107
+
108
+ if ( chunk === initialHeader || chunk === continuationHeader ) {
109
+ // We only have a header, but the output still doesn't fit. Truncate and continue.
110
+ console . log ( "Truncating output to fit in GH comment" ) ;
111
+ chunk += output . slice ( 0 , maxCommentLength - chunk . length - closeDetails . length - trunctationSuffix . length ) ;
112
+ chunk += trunctationSuffix ;
107
113
chunk += closeDetails ;
108
114
bodyChunks . push ( chunk ) ;
109
115
chunk = continuationHeader ;
116
+ i ++ ;
117
+ continue ;
110
118
}
111
- chunk += output ;
119
+
120
+ // Close the chunk and try the same output again.
121
+ chunk += closeDetails ;
122
+ bodyChunks . push ( chunk ) ;
123
+ chunk = continuationHeader ;
124
+ }
125
+
126
+ if ( chunk !== initialHeader && chunk !== continuationHeader ) {
127
+ chunk += closeDetails ;
128
+ bodyChunks . push ( chunk ) ;
112
129
}
113
- chunk += closeDetails ;
114
- bodyChunks . push ( chunk ) ;
130
+
115
131
116
132
for ( const chunk of bodyChunks ) {
117
133
console . log ( `Chunk of size ${ chunk . length } ` ) ;
0 commit comments