@@ -31,9 +31,11 @@ const BUILD_FAILURE = 'BUILD_FAILURE';
3131const JS_TEST_FAILURE = 'JS_TEST_FAILURE' ;
3232const CC_TEST_FAILURE = 'CC_TEST_FAILURE' ;
3333const JENKINS_FAILURE = 'JENKINS_FAILURE' ;
34+ const GIT_FAILURE = 'GIT_FAILURE' ;
3435
3536const FAILURE_TYPES = {
36- BUILD_FAILURE , JS_TEST_FAILURE , CC_TEST_FAILURE , JENKINS_FAILURE
37+ BUILD_FAILURE , JS_TEST_FAILURE , CC_TEST_FAILURE ,
38+ JENKINS_FAILURE , GIT_FAILURE
3739} ;
3840
3941class CIResult {
@@ -83,14 +85,22 @@ class JenkinsFailure extends CIResult {
8385 }
8486}
8587
86- function buildFailureMatcher ( patterns , ctx , text ) {
88+ // Usually need a fix to the build scripts or in workers
89+ class GitFailure extends CIResult {
90+ constructor ( ctx , reason ) {
91+ super ( ctx , reason ) ;
92+ this . type = GIT_FAILURE ;
93+ }
94+ }
95+
96+ function failureMatcher ( Failure , patterns , ctx , text ) {
8797 for ( const pattern of patterns ) {
8898 const matches = text . match ( pattern . pattern ) ;
8999 if ( ! matches ) {
90100 continue ;
91101 }
92- const reason = pickContext ( matches , text , pattern . context ) ;
93- return [ new BuildFailure ( ctx , reason ) ] ;
102+ const reason = pickContext ( matches , text , pattern . context ) . trim ( ) ;
103+ return [ new Failure ( ctx , reason ) ] ;
94104 }
95105 return null ;
96106}
@@ -114,52 +124,52 @@ const FAILURE_FILTERS = [{
114124 }
115125} , {
116126 filter ( ctx , text ) {
117- const pattern = / \[ { 2 } F A I L E D { 2 } \] .+ / g;
118- const matches = text . match ( pattern ) ;
119- if ( ! matches ) {
120- return null ;
121- }
122- const reason = pickContext ( matches , text , {
123- index : 0 , contextBefore : 5 , contextAfter : 0
124- } ) ;
125- return [ new CCTestFailure ( ctx , reason ) ] ;
127+ const patterns = [ {
128+ pattern : / \[ { 2 } F A I L E D { 2 } \] .+ / g,
129+ context : { index : 0 , contextBefore : 5 , contextAfter : 0 }
130+ } ] ;
131+ return failureMatcher ( CCTestFailure , patterns , ctx , text ) ;
126132 }
127133} , {
128134 // VS compilation error
129135 filter ( ctx , text ) {
130- const pattern = / e r r o r C \d + : / mg;
131- const matches = text . match ( pattern ) ;
132- if ( ! matches ) {
133- return null ;
134- }
135- const reason = pickContext ( matches , text , {
136- index : 0 , contextBefore : 0 , contextAfter : 5
137- } ) ;
138- return [ new BuildFailure ( ctx , reason ) ] ;
136+ const patterns = [ {
137+ pattern : / e r r o r C \d + : / mg,
138+ context : { index : 0 , contextBefore : 0 , contextAfter : 5 }
139+ } ] ;
140+ return failureMatcher ( BuildFailure , patterns , ctx , text ) ;
139141 }
140142} , {
141143 filter ( ctx , text ) {
142- const pattern = / j a v a \. i o \. I O E x c e p t i o n .+ / g;
143- const matches = text . match ( pattern ) ;
144- if ( ! matches ) {
145- return null ;
146- }
147- const reason = pickContext ( matches , text , {
148- index : - 1 , contextBefore : 0 , contextAfter : 5
149- } ) ;
150- return [ new JenkinsFailure ( ctx , reason ) ] ;
144+ const patterns = [ {
145+ pattern : / j a v a \. i o \. I O E x c e p t i o n .+ / g,
146+ context : { index : - 1 , contextBefore : 0 , contextAfter : 5 }
147+ } , {
148+ pattern : / B u i l d t i m e d o u t / g,
149+ context : { index : 0 , contextBefore : 0 , contextAfter : 1 }
150+ } ] ;
151+ return failureMatcher ( JenkinsFailure , patterns , ctx , text ) ;
151152 }
152153} , {
153154 filter ( ctx , text ) {
154- const pattern = / h u d s o n \. p l u g i n s \. g i t \. G i t E x c e p t i o n + / g;
155+ const pattern =
156+ / C h a n g e s n o t s t a g e d f o r c o m m i t : [ \s \S ] + n o c h a n g e s a d d e d t o c o m m i t / mg;
155157 const matches = text . match ( pattern ) ;
156158 if ( ! matches ) {
157159 return null ;
158160 }
159- const reason = pickContext ( matches , text , {
160- index : 0 , contextBefore : 2 , contextAfter : 5
161- } ) . trim ( ) ;
162- return [ new JenkinsFailure ( ctx , reason ) ] ;
161+ return new GitFailure ( ctx , matches [ 0 ] ) ;
162+ }
163+ } , {
164+ filter ( ctx , text ) {
165+ const patterns = [ {
166+ pattern : / h u d s o n \. p l u g i n s \. g i t \. G i t E x c e p t i o n + / g,
167+ context : { index : 0 , contextBefore : 2 , contextAfter : 5 }
168+ } , {
169+ pattern : / C a n n o t r e b a s e : .+ / g,
170+ context : { index : 0 , contextBefore : 0 , contextAfter : 1 }
171+ } ] ;
172+ return failureMatcher ( GitFailure , patterns , ctx , text ) ;
163173 }
164174} , {
165175 filter ( ctx , text ) {
@@ -172,7 +182,7 @@ const FAILURE_FILTERS = [{
172182 pattern : / E r r o r : .+ / g,
173183 context : { index : 0 , contextBefore : 0 , contextAfter : 5 }
174184 } ] ;
175- return buildFailureMatcher ( patterns , ctx , text ) ;
185+ return failureMatcher ( BuildFailure , patterns , ctx , text ) ;
176186 }
177187} , {
178188 filter ( ctx , text ) {
@@ -187,6 +197,9 @@ const FAILURE_FILTERS = [{
187197} , {
188198 filter ( ctx , text ) {
189199 const patterns = [ {
200+ pattern : / b a s h : l i n e / g,
201+ context : { index : 0 , contextBefore : 0 , contextAfter : 1 }
202+ } , {
190203 pattern : / F A T A L : .+ / g,
191204 context : { index : - 1 , contextBefore : 0 , contextAfter : 5 }
192205 } , {
@@ -204,17 +217,8 @@ const FAILURE_FILTERS = [{
204217 } , {
205218 pattern : / w a r n i n g : f a i l e d .+ / g,
206219 context : { index : 0 , contextBefore : 0 , contextAfter : 3 }
207- } , {
208- pattern : / B u i l d t i m e d o u t / g,
209- context : { index : 0 , contextBefore : 0 , contextAfter : 1 }
210- } , {
211- pattern : / b a s h : l i n e / g,
212- context : { index : 0 , contextBefore : 0 , contextAfter : 1 }
213- } , {
214- pattern : / C a n n o t r e b a s e : Y o u h a v e u n s t a g e d c h a n g e s / g,
215- context : { index : 0 , contextBefore : 0 , contextAfter : 1 }
216220 } ] ;
217- return buildFailureMatcher ( patterns , ctx , text ) ;
221+ return failureMatcher ( BuildFailure , patterns , ctx , text ) ;
218222 }
219223} ] ;
220224
@@ -242,7 +246,8 @@ CIFailureParser.FAILURE_CONSTRUCTORS = {
242246 BUILD_FAILURE : BuildFailure ,
243247 JENKINS_FAILURE : JenkinsFailure ,
244248 JS_TEST_FAILURE : JSTestFailure ,
245- CC_TEST_FAILURE : CCTestFailure
249+ CC_TEST_FAILURE : CCTestFailure ,
250+ GIT_FAILURE : GitFailure
246251} ;
247252CIFailureParser . CIResult = CIResult ;
248253module . exports = CIFailureParser ;
0 commit comments