@@ -119,6 +119,36 @@ describe('setResult', () => {
119119
120120 setResult ( diffs , false , logger ) ;
121121
122+ stdoutCalledWith ( mockStdout , [
123+ '::group::Dump output' ,
124+ '' ,
125+ '::set-output name=diff::test1 test2 test4' ,
126+ '"diff: test1 test2 test4"' ,
127+ '' ,
128+ '::set-output name=filtered_diff::test1 test2' ,
129+ '"filtered_diff: test1 test2"' ,
130+ '' ,
131+ '::set-output name=matched_files::test4' ,
132+ '"matched_files: test4"' ,
133+ '' ,
134+ '::set-output name=count::3' ,
135+ '"count: 3"' ,
136+ '::endgroup::' ,
137+ ] ) ;
138+ exportVariableCalledWith ( mockEnv , [
139+ { name : 'GIT_DIFF' , val : 'test1 test2 test4' } ,
140+ { name : 'GIT_DIFF_FILTERED' , val : 'test1 test2' } ,
141+ { name : 'MATCHED_FILES' , val : 'test4' } ,
142+ ] ) ;
143+ } ) ;
144+
145+ it ( 'should set result with file diff' , ( ) => {
146+ process . env . INPUT_GET_FILE_DIFF = '1' ;
147+ const mockStdout = spyOnStdout ( ) ;
148+ const mockEnv = spyOnExportVariable ( ) ;
149+
150+ setResult ( diffs , false , logger ) ;
151+
122152 stdoutCalledWith ( mockStdout , [
123153 '::group::Dump output' ,
124154 '' ,
@@ -157,6 +187,7 @@ describe('setResult', () => {
157187 process . env . INPUT_SET_ENV_NAME_INSERTIONS = 'INSERTIONS' ;
158188 process . env . INPUT_SET_ENV_NAME_DELETIONS = 'DELETIONS' ;
159189 process . env . INPUT_SET_ENV_NAME_LINES = 'LINES' ;
190+ process . env . INPUT_GET_FILE_DIFF = '1' ;
160191 const mockStdout = spyOnStdout ( ) ;
161192 const mockEnv = spyOnExportVariable ( ) ;
162193
@@ -208,6 +239,81 @@ describe('execute', () => {
208239 process . env . INPUT_FILES = 'package.json\ncomposer.json' ;
209240 process . env . INPUT_PATTERNS = 'src/**/*.+(ts|txt)\n__tests__/**/*.+(ts|txt)' ;
210241
242+ const mockExec = spyOnSpawn ( ) ;
243+ const mockStdout = spyOnStdout ( ) ;
244+ const mockEnv = spyOnExportVariable ( ) ;
245+ setChildProcessParams ( {
246+ stdout : ( command : string ) : string => {
247+ if ( command . startsWith ( 'git diff' ) ) {
248+ return 'package.json\nabc/package.json\nREADME.md\nsrc/main.ts' ;
249+ }
250+ return '' ;
251+ } ,
252+ } ) ;
253+
254+ await execute ( logger , prContext ) ;
255+
256+ execCalledWith ( mockExec , [
257+ 'git remote add get-diff-action \'https://octocat:test [email protected] /hello/world.git\' || :' , 258+ 'git fetch --no-tags --no-recurse-submodules \'--depth=10000\' get-diff-action \'refs/pull/55/merge:refs/remotes/get-diff-action/pull/55/merge\' \'refs/heads/master:refs/remotes/get-diff-action/master\' || :' ,
259+ 'git diff \'get-diff-action/master...get-diff-action/pull/55/merge\' \'--diff-filter=AMRC\' --name-only' ,
260+ ] ) ;
261+ stdoutCalledWith ( mockStdout , [
262+ '[command]git remote add get-diff-action' ,
263+ '[command]git fetch --no-tags --no-recurse-submodules \'--depth=10000\' get-diff-action \'refs/pull/55/merge:refs/remotes/get-diff-action/pull/55/merge\' \'refs/heads/master:refs/remotes/get-diff-action/master\'' ,
264+ '[command]git diff \'get-diff-action/master...get-diff-action/pull/55/merge\' \'--diff-filter=AMRC\' --name-only' ,
265+ ' >> package.json' ,
266+ ' >> abc/package.json' ,
267+ ' >> README.md' ,
268+ ' >> src/main.ts' ,
269+ '::group::Dump diffs' ,
270+ getLogStdout ( [
271+ {
272+ 'file' : 'package.json' ,
273+ 'filterIgnored' : true ,
274+ 'isMatched' : false ,
275+ } ,
276+ {
277+ 'file' : 'abc/package.json' ,
278+ 'filterIgnored' : true ,
279+ 'isMatched' : false ,
280+ } ,
281+ {
282+ 'file' : 'src/main.ts' ,
283+ 'filterIgnored' : false ,
284+ 'isMatched' : true ,
285+ } ,
286+ ] ) ,
287+ '::endgroup::' ,
288+ '::group::Dump output' ,
289+ '' ,
290+ '::set-output name=diff::\'package.json\' \'abc/package.json\' \'src/main.ts\'' ,
291+ '"diff: \'package.json\' \'abc/package.json\' \'src/main.ts\'"' ,
292+ '' ,
293+ '::set-output name=filtered_diff::\'src/main.ts\'' ,
294+ '"filtered_diff: \'src/main.ts\'"' ,
295+ '' ,
296+ '::set-output name=matched_files::\'package.json\' \'abc/package.json\'' ,
297+ '"matched_files: \'package.json\' \'abc/package.json\'"' ,
298+ '' ,
299+ '::set-output name=count::3' ,
300+ '"count: 3"' ,
301+ '::endgroup::' ,
302+ ] ) ;
303+ exportVariableCalledWith ( mockEnv , [
304+ { name : 'GIT_DIFF' , val : '\'package.json\' \'abc/package.json\' \'src/main.ts\'' } ,
305+ { name : 'GIT_DIFF_FILTERED' , val : '\'src/main.ts\'' } ,
306+ { name : 'MATCHED_FILES' , val : '\'package.json\' \'abc/package.json\'' } ,
307+ ] ) ;
308+ } ) ;
309+
310+ it ( 'should execute with file diff' , async ( ) => {
311+ process . env . GITHUB_WORKSPACE = '/home/runner/work/my-repo-name/my-repo-name' ;
312+ process . env . INPUT_GITHUB_TOKEN = 'test token' ;
313+ process . env . INPUT_FILES = 'package.json\ncomposer.json' ;
314+ process . env . INPUT_PATTERNS = 'src/**/*.+(ts|txt)\n__tests__/**/*.+(ts|txt)' ;
315+ process . env . INPUT_GET_FILE_DIFF = '1' ;
316+
211317 const mockExec = spyOnSpawn ( ) ;
212318 const mockStdout = spyOnStdout ( ) ;
213319 const mockEnv = spyOnExportVariable ( ) ;
@@ -357,15 +463,6 @@ describe('execute', () => {
357463 '' ,
358464 '::set-output name=count::0' ,
359465 '"count: 0"' ,
360- '' ,
361- '::set-output name=insertions::0' ,
362- '"insertions: 0"' ,
363- '' ,
364- '::set-output name=deletions::0' ,
365- '"deletions: 0"' ,
366- '' ,
367- '::set-output name=lines::0' ,
368- '"lines: 0"' ,
369466 '::endgroup::' ,
370467 ] ) ;
371468 exportVariableCalledWith ( mockEnv , [
@@ -402,15 +499,6 @@ describe('execute', () => {
402499 '' ,
403500 '::set-output name=count::0' ,
404501 '"count: 0"' ,
405- '' ,
406- '::set-output name=insertions::0' ,
407- '"insertions: 0"' ,
408- '' ,
409- '::set-output name=deletions::0' ,
410- '"deletions: 0"' ,
411- '' ,
412- '::set-output name=lines::0' ,
413- '"lines: 0"' ,
414502 '::endgroup::' ,
415503 ] ) ;
416504 exportVariableCalledWith ( mockEnv , [
@@ -422,6 +510,7 @@ describe('execute', () => {
422510
423511 it ( 'should execute empty with default value' , async ( ) => {
424512 process . env . GITHUB_WORKSPACE = '/home/runner/work/my-repo-name/my-repo-name' ;
513+ process . env . INPUT_GET_FILE_DIFF = '1' ;
425514 process . env . INPUT_DIFF_DEFAULT = '1' ;
426515 process . env . INPUT_FILTERED_DIFF_DEFAULT = '2' ;
427516 process . env . INPUT_MATCHED_FILES_DEFAULT = '3' ;
@@ -512,15 +601,6 @@ describe('execute', () => {
512601 '' ,
513602 '::set-output name=count::0' ,
514603 '"count: 0"' ,
515- '' ,
516- '::set-output name=insertions::0' ,
517- '"insertions: 0"' ,
518- '' ,
519- '::set-output name=deletions::0' ,
520- '"deletions: 0"' ,
521- '' ,
522- '::set-output name=lines::0' ,
523- '"lines: 0"' ,
524604 '::endgroup::' ,
525605 ] ) ;
526606 exportVariableCalledWith ( mockEnv , [
0 commit comments