1
1
// @ts -expect-error it's a js library
2
2
import cfLogs from 'cf-logs' ;
3
3
4
+ // eslint-disable-next-line import/no-unresolved
4
5
import { DeprecatedImageDto } from './deprecated-image.dto' ;
5
6
6
7
const logger = cfLogs . Logger ( 'codefresh:containerLogger' ) ;
@@ -22,33 +23,22 @@ class DeprecatedImagesCollector {
22
23
}
23
24
24
25
catchDeprecatedImage ( logText : string ) {
25
- if ( logText . includes ( '[DEPRECATION NOTICE]' ) ) {
26
- const imageName = this . _parseImageName ( logText ) ;
27
-
28
- if ( imageName === null ) {
29
- logger . error ( `detected pulling of the deprecated image but failed to parse the image name. The original log text: '${ logText } '` ) ;
30
- } else {
31
- logger . warn ( `detected pulling of the deprecated image '${ imageName } '. The original log text: '${ logText } '` ) ;
32
-
33
- this . push ( {
34
- image : imageName ,
35
- } ) ;
36
- }
37
- }
38
- }
39
-
40
- private _parseImageName ( logText : string ) {
41
- const startMarker = 'Suggest the author of ' ;
42
- const endMarker = ' to upgrade the image' ;
26
+ const imageName = this . _parseImageName ( logText ) ;
43
27
44
- const startIndex = logText . indexOf ( startMarker ) ;
45
- const endIndex = logText . indexOf ( endMarker ) ;
28
+ if ( imageName !== null ) {
29
+ logger . warn ( `detected pulling of the deprecated image ' ${ imageName } '. The original log text: ' ${ logText } '` ) ;
46
30
47
- if ( startIndex > - 1 && endIndex > - 1 && endIndex > startIndex ) {
48
- return logText . substring ( startIndex + startMarker . length , endIndex ) ;
31
+ this . push ( {
32
+ image : imageName ,
33
+ } ) ;
49
34
}
35
+ }
50
36
51
- return null ;
37
+ private _parseImageName ( logText : string ) {
38
+ // eslint-disable-next-line no-control-regex
39
+ const regex = / ^ \u001b \[ 3 1 m \u001b \[ 1 m \[ D E P R E C A T I O N N O T I C E ] .+ ?S u g g e s t t h e a u t h o r o f (?< image > .+ ?) t o / ;
40
+ const match = logText . match ( regex ) ;
41
+ return match ?. groups ?. image ?? null ;
52
42
}
53
43
}
54
44
0 commit comments