@@ -40,13 +40,17 @@ export class ArtifactsHandler extends Handler {
4040 const file = files . data . find ( ( { filename } ) => filename . includes ( 'package.json' ) )
4141
4242 if ( ! file ) {
43+ console . log ( 'No package.json found in PR' )
44+
4345 response = await this . updateStatus ( body , payload . success )
4446
4547 return callback ( null , response )
4648 }
4749
4850 const refMatch = file . contents_url . match ( / r e f = ( [ a - z 0 - 9 ] + ) / )
4951 if ( ! refMatch ?. [ 1 ] ) {
52+ console . log ( 'no ref in package.json diff url?' )
53+
5054 response = await this . updateStatus ( body , payload . success )
5155
5256 return callback ( null , response )
@@ -59,13 +63,32 @@ export class ArtifactsHandler extends Handler {
5963 ref : refMatch [ 1 ] ,
6064 } )
6165
62- const match = Buffer . from ( content . data . content . toString ( 'utf8' ) , 'base64' )
63- . toString ( 'ascii' )
64- . match ( this . artifactsRegex )
66+ let packageJson = ''
67+ try {
68+ packageJson = JSON . parse (
69+ Buffer . from ( content . data . content . toString ( 'utf8' ) , 'base64' ) . toString ( 'ascii' )
70+ )
71+ } catch ( e ) {
72+ response = await this . updateStatus ( body , payload . success )
73+ console . log ( 'Parsing package.json failed:' , e )
74+
75+ return callback ( null , response )
76+ }
77+
78+ const deps = {
79+ dependencies : packageJson . dependencies || { } ,
80+ devDependencies : packageJson . devDependencies || { } ,
81+ }
82+
83+ const match = JSON . stringify ( deps ) . match ( this . artifactsRegex )
6584
6685 if ( match === null ) {
86+ console . log ( 'No match, success.' )
87+
6788 response = await this . updateStatus ( body , payload . success )
6889 } else {
90+ console . log ( 'Match found, failure.' )
91+
6992 response = await this . updateStatus ( body , payload . failure )
7093 }
7194
0 commit comments