@@ -24,7 +24,7 @@ describe('config file fetching', () => {
2424 expect ( content ) . toBe ( configString )
2525 } )
2626
27- test ( 'fetch from main branch if the event is pull_request and file is not modified' , async ( ) => {
27+ test ( 'fetch from main branch if the event is PR relevant and file is not modified or added ' , async ( ) => {
2828 let configString = `
2929 mergeable:
3030 issues:
@@ -43,14 +43,24 @@ describe('config file fetching', () => {
4343 days: 20
4444 message: Issue test
4545 `
46- let context = createMockGhConfig ( configString , prConfig , { files : [ 'someFile' ] } )
46+ let context = createMockGhConfig (
47+ configString ,
48+ prConfig ,
49+ { files : [ { filename : 'someFile' , status : 'modified' } ] }
50+ )
51+
4752 context . event = 'pull_request'
4853 let file = await Configuration . fetchConfigFile ( context )
49- const content = Buffer . from ( file . data . content , 'base64' ) . toString ( )
54+ let content = Buffer . from ( file . data . content , 'base64' ) . toString ( )
55+ expect ( content ) . toBe ( configString )
56+
57+ context . event = 'pull_request_review'
58+ file = await Configuration . fetchConfigFile ( context )
59+ content = Buffer . from ( file . data . content , 'base64' ) . toString ( )
5060 expect ( content ) . toBe ( configString )
5161 } )
5262
53- test ( 'fetch from head branch if the event is pull_request and file is modified' , async ( ) => {
63+ test ( 'fetch from head branch if the event is relevant to PR and file is modified or added ' , async ( ) => {
5464 let configString = `
5565 mergeable:
5666 issues:
@@ -60,19 +70,35 @@ describe('config file fetching', () => {
6070 pull_requests:
6171 stale:
6272 days: 20
63- message: PR test
73+ message: from HEAD
6474 `
6575 let prConfig = `
6676 mergeable:
6777 issues:
6878 stale:
6979 days: 20
70- message: Issue test
80+ message: From PR Config
7181 `
72- let context = createMockGhConfig ( configString , prConfig , { files : [ '.github/mergeable.yml' ] } )
82+ let files = { files : [
83+ { filename : '.github/mergeable.yml' , status : 'modified' }
84+ ] }
85+ let context = createMockGhConfig ( configString , prConfig , files )
7386 context . event = 'pull_request'
7487 let file = await Configuration . fetchConfigFile ( context )
75- const content = Buffer . from ( file . data . content , 'base64' ) . toString ( )
88+ let content = Buffer . from ( file . data . content , 'base64' ) . toString ( )
89+ expect ( content ) . toBe ( prConfig )
90+
91+ context . event = 'pull_request_review'
92+ file = await Configuration . fetchConfigFile ( context )
93+ content = Buffer . from ( file . data . content , 'base64' ) . toString ( )
94+ expect ( content ) . toBe ( prConfig )
95+
96+ files = { files : [
97+ { file : '.github/mergeable.yml' , status : 'added' }
98+ ] }
99+ context = createMockGhConfig ( configString , prConfig , files )
100+ context . event = 'pull_request'
101+ content = Buffer . from ( file . data . content , 'base64' ) . toString ( )
76102 expect ( content ) . toBe ( prConfig )
77103 } )
78104} )
@@ -340,7 +366,7 @@ const createMockGhConfig = (json, prConfig, options) => {
340366 } ,
341367 pullRequests : {
342368 getFiles : ( ) => {
343- return { data : options . files && options . files . map ( file => ( { filename : file , status : 'modified' } ) ) }
369+ return { data : options . files }
344370 }
345371 }
346372 }
0 commit comments