@@ -76,7 +76,7 @@ mock('@actions/github', {
7676 context : gitHubContext ,
7777} ) ;
7878
79- const { cmd, pull, push } = require ( '../src/git' ) ;
79+ const { cmd, pull, push, fetch } = require ( '../src/git' ) ;
8080const ok : ( x : any ) => asserts x = A . ok ;
8181const userArgs = [
8282 '-c' ,
@@ -209,4 +209,48 @@ describe('git', function () {
209209 eq ( fakedExec . lastArgs , null ) ;
210210 } ) ;
211211 } ) ;
212+
213+ describe ( 'fetch()' , function ( ) {
214+ afterEach ( function ( ) {
215+ gitHubContext . payload . repository = { full_name : 'user/repo' } ;
216+ } ) ;
217+
218+ it ( 'runs `git fetch` with given branch and options with token' , async function ( ) {
219+ const stdout = await fetch ( 'this-is-token' , 'my-branch' , 'opt1' , 'opt2' ) ;
220+ const args = fakedExec . lastArgs ;
221+
222+ eq ( stdout , 'this is test' ) ;
223+ ok ( args ) ;
224+ eq ( args [ 0 ] , 'git' ) ;
225+ eq (
226+ args [ 1 ] ,
227+ userArgs . concat ( [
228+ 'fetch' ,
229+ 'https://x-access-token:[email protected] /user/repo.git' , 230+ 'my-branch:my-branch' ,
231+ 'opt1' ,
232+ 'opt2' ,
233+ ] ) ,
234+ ) ;
235+ } ) ;
236+
237+ it ( 'runs `git fetch` with given branch and options without token' , async function ( ) {
238+ const stdout = await fetch ( undefined , 'my-branch' , 'opt1' , 'opt2' ) ;
239+ const args = fakedExec . lastArgs ;
240+
241+ eq ( stdout , 'this is test' ) ;
242+ ok ( args ) ;
243+ eq ( args [ 0 ] , 'git' ) ;
244+ eq ( args [ 1 ] , userArgs . concat ( [ 'fetch' , 'origin' , 'my-branch:my-branch' , 'opt1' , 'opt2' ] ) ) ;
245+ } ) ;
246+
247+ it ( 'raises an error when repository info is not included in payload' , async function ( ) {
248+ gitHubContext . payload . repository = null ;
249+ await A . rejects (
250+ ( ) => fetch ( 'this-is-token' , 'my-branch' , 'opt1' , 'opt2' ) ,
251+ / ^ E r r o r : R e p o s i t o r y i n f o i s n o t a v a i l a b l e i n p a y l o a d / ,
252+ ) ;
253+ eq ( fakedExec . lastArgs , null ) ;
254+ } ) ;
255+ } ) ;
212256} ) ;
0 commit comments