11/* eslint-disable no-magic-numbers */
22import nock from 'nock' ;
3- import path , { resolve } from 'path' ;
3+ import path , { resolve } from 'path' ;
44import {
55 generateContext ,
66 testEnv ,
@@ -12,8 +12,8 @@ import {
1212 disableNetConnect ,
1313 getApiFixture ,
1414} from '@technote-space/github-action-test-helper' ;
15- import { Logger } from '@technote-space/github-action-log-helper' ;
16- import { getGitDiff , getFileDiff , getDiffFiles , sumResults } from '../../src/utils/command' ;
15+ import { Logger } from '@technote-space/github-action-log-helper' ;
16+ import { getGitDiff , getFileDiff , getDiffFiles , sumResults } from '../../src/utils/command' ;
1717
1818const rootDir = path . resolve ( __dirname , '../..' ) ;
1919const fixtureRootDir = resolve ( __dirname , '..' , 'fixtures' ) ;
@@ -415,6 +415,45 @@ describe('getGitDiff', () => {
415415 ] ) ;
416416 } ) ;
417417
418+ it ( 'should get git diff (push, not found pr with base setting)' , async ( ) => {
419+ process . env . GITHUB_WORKSPACE = '/home/runner/work/my-repo-name/my-repo-name' ;
420+ process . env . INPUT_GITHUB_TOKEN = 'test token' ;
421+ process . env . INPUT_BASE = 'main' ;
422+
423+ const mockExec = spyOnSpawn ( ) ;
424+ setChildProcessParams ( {
425+ stdout : ( command : string ) : string => {
426+ if ( command . startsWith ( 'git diff' ) ) {
427+ return 'package.json\nabc/composer.json\nREADME.md\nsrc/main.ts' ;
428+ }
429+ return '' ;
430+ } ,
431+ } ) ;
432+
433+ nock ( 'https://api.github.com' )
434+ . persist ( )
435+ . get ( '/repos/hello/world/pulls?head=hello%3Atest' )
436+ . reply ( 200 , ( ) => [ ] ) ;
437+
438+ expect ( await getGitDiff ( logger , Object . assign ( { } , pushContext , {
439+ ref : 'refs/heads/test' ,
440+ } ) ) ) . toEqual ( [
441+ { file : 'package.json' , ...emptyDiff } ,
442+ { file : 'abc/composer.json' , ...emptyDiff } ,
443+ { file : 'README.md' , ...emptyDiff } ,
444+ { file : 'src/main.ts' , ...emptyDiff } ,
445+ ] ) ;
446+ execCalledWith ( mockExec , [
447+ 'git remote add get-diff-action \'https://octocat:test [email protected] /hello/world.git\' || :' , 448+ 'git fetch --no-tags --no-recurse-submodules \'--depth=10000\' get-diff-action \'refs/heads/test:refs/remotes/get-diff-action/test\' || :' ,
449+ 'git diff \'main...after-sha\' \'--diff-filter=AMRC\' --name-only || :' ,
450+ 'git diff \'main...after-sha\' --shortstat -w -- \'package.json\'' ,
451+ 'git diff \'main...after-sha\' --shortstat -w -- \'abc/composer.json\'' ,
452+ 'git diff \'main...after-sha\' --shortstat -w -- \'README.md\'' ,
453+ 'git diff \'main...after-sha\' --shortstat -w -- \'src/main.ts\'' ,
454+ ] ) ;
455+ } ) ;
456+
418457 it ( 'should get git diff (push tag)' , async ( ) => {
419458 process . env . GITHUB_WORKSPACE = '/home/runner/work/my-repo-name/my-repo-name' ;
420459 process . env . INPUT_GITHUB_TOKEN = 'test token' ;
0 commit comments