@@ -25,11 +25,8 @@ const context = (override: object = {}): Context => getContext(Object.assign({
25
25
describe ( 'GitHelper' , ( ) => {
26
26
testEnv ( ) ;
27
27
testChildProcess ( ) ;
28
- beforeEach ( ( ) => {
29
- process . env . INPUT_GITHUB_TOKEN = 'token' ;
30
- } ) ;
31
28
32
- const helper = new GitHelper ( new Logger ( ) ) ;
29
+ const helper = new GitHelper ( new Logger ( ) , { token : 'token1' } ) ;
33
30
34
31
describe ( 'getCurrentBranchName' , ( ) => {
35
32
it ( 'should return empty 1' , async ( ) => {
@@ -69,7 +66,7 @@ describe('GitHelper', () => {
69
66
} ) ) ;
70
67
71
68
execCalledWith ( mockExec , [
72
- 'git clone \'--branch=test\' \'--depth=3\' \'https://octocat:token @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
69
+ 'git clone \'--branch=test\' \'--depth=3\' \'https://octocat:token1 @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
73
70
] ) ;
74
71
} ) ;
75
72
@@ -82,8 +79,8 @@ describe('GitHelper', () => {
82
79
} ) ) ) ;
83
80
84
81
execCalledWith ( mockExec , [
85
- 'git clone \'--depth=3\' \'https://octocat:token @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
86
- 'git fetch \'https://octocat:token @github.com/hello/world.git\' \'+refs/pull/123/merge\' > /dev/null 2>&1' ,
82
+ 'git clone \'--depth=3\' \'https://octocat:token1 @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
83
+ 'git fetch \'https://octocat:token1 @github.com/hello/world.git\' \'+refs/pull/123/merge\' > /dev/null 2>&1' ,
87
84
'git checkout -qf FETCH_HEAD' ,
88
85
] ) ;
89
86
} ) ;
@@ -105,8 +102,8 @@ describe('GitHelper', () => {
105
102
await helper . checkout ( workDir , context ( ) ) ;
106
103
107
104
execCalledWith ( mockExec , [
108
- 'git clone \'--depth=3\' \'https://octocat:token @github.com/hello/world.git\' \'.\' > /dev/null 2>&1' ,
109
- 'git fetch \'https://octocat:token @github.com/hello/world.git\' refs/heads/test-ref > /dev/null 2>&1' ,
105
+ 'git clone \'--depth=3\' \'https://octocat:token1 @github.com/hello/world.git\' \'.\' > /dev/null 2>&1' ,
106
+ 'git fetch \'https://octocat:token1 @github.com/hello/world.git\' refs/heads/test-ref > /dev/null 2>&1' ,
110
107
'git checkout -qf test-sha' ,
111
108
] ) ;
112
109
} ) ;
@@ -117,7 +114,7 @@ describe('GitHelper', () => {
117
114
await helper . checkout ( workDir , context ( { sha : '' } ) ) ;
118
115
119
116
execCalledWith ( mockExec , [
120
- 'git clone \'https://octocat:token @github.com/hello/world.git\' \'.\' > /dev/null 2>&1' ,
117
+ 'git clone \'https://octocat:token1 @github.com/hello/world.git\' \'.\' > /dev/null 2>&1' ,
121
118
'git checkout -qf test-ref' ,
122
119
] ) ;
123
120
} ) ;
@@ -128,7 +125,7 @@ describe('GitHelper', () => {
128
125
await helper . checkout ( workDir , context ( { sha : '' , ref : 'refs/tags/test-tag' } ) ) ;
129
126
130
127
execCalledWith ( mockExec , [
131
- 'git clone \'https://octocat:token @github.com/hello/world.git\' \'.\' > /dev/null 2>&1' ,
128
+ 'git clone \'https://octocat:token1 @github.com/hello/world.git\' \'.\' > /dev/null 2>&1' ,
132
129
'git checkout -qf refs/tags/test-tag' ,
133
130
] ) ;
134
131
} ) ;
@@ -169,7 +166,7 @@ describe('GitHelper', () => {
169
166
execCalledWith ( mockExec , [
170
167
`rm -rdf '${ workDir } '` ,
171
168
'git init \'.\'' ,
172
- 'git remote add origin \'https://octocat:token @github.com/hello/world.git\' > /dev/null 2>&1 || :' ,
169
+ 'git remote add origin \'https://octocat:token1 @github.com/hello/world.git\' > /dev/null 2>&1 || :' ,
173
170
] ) ;
174
171
} ) ;
175
172
} ) ;
@@ -183,7 +180,7 @@ describe('GitHelper', () => {
183
180
execCalledWith ( mockExec , [
184
181
`rm -rdf '${ workDir } '` ,
185
182
'git init \'.\'' ,
186
- 'git remote add origin \'https://octocat:token @github.com/hello/world.git\' > /dev/null 2>&1 || :' ,
183
+ 'git remote add origin \'https://octocat:token1 @github.com/hello/world.git\' > /dev/null 2>&1 || :' ,
187
184
'git fetch origin || :' ,
188
185
] ) ;
189
186
} ) ;
@@ -196,7 +193,7 @@ describe('GitHelper', () => {
196
193
execCalledWith ( mockExec , [
197
194
`rm -rdf '${ workDir } '` ,
198
195
'git init \'.\'' ,
199
- 'git remote add origin \'https://octocat:token @github.com/hello/world.git\' > /dev/null 2>&1 || :' ,
196
+ 'git remote add origin \'https://octocat:token1 @github.com/hello/world.git\' > /dev/null 2>&1 || :' ,
200
197
'git fetch --no-tags origin || :' ,
201
198
] ) ;
202
199
} ) ;
@@ -209,7 +206,7 @@ describe('GitHelper', () => {
209
206
execCalledWith ( mockExec , [
210
207
`rm -rdf '${ workDir } '` ,
211
208
'git init \'.\'' ,
212
- 'git remote add origin \'https://octocat:token @github.com/hello/world.git\' > /dev/null 2>&1 || :' ,
209
+ 'git remote add origin \'https://octocat:token1 @github.com/hello/world.git\' > /dev/null 2>&1 || :' ,
213
210
'git fetch origin \'+refs/pull/*/merge:refs/remotes/pull/*/merge\' \'+refs/heads/hoge:refs/remotes/origin/hoge\' || :' ,
214
211
] ) ;
215
212
} ) ;
@@ -222,7 +219,7 @@ describe('GitHelper', () => {
222
219
await helper . fetchBranch ( workDir , 'test-branch' , context ( ) ) ;
223
220
224
221
execCalledWith ( mockExec , [
225
- 'git fetch --prune --no-recurse-submodules \'--depth=3\' \'https://octocat:token @github.com/hello/world.git\' \'+refs/heads/test-branch:refs/remotes/origin/test-branch\' > /dev/null 2>&1 || :' ,
222
+ 'git fetch --prune --no-recurse-submodules \'--depth=3\' \'https://octocat:token1 @github.com/hello/world.git\' \'+refs/heads/test-branch:refs/remotes/origin/test-branch\' > /dev/null 2>&1 || :' ,
226
223
] ) ;
227
224
} ) ;
228
225
} ) ;
@@ -336,7 +333,7 @@ describe('GitHelper', () => {
336
333
} ;
337
334
}
338
335
339
- const helper = new GitHelper ( new ThrowErrorLogger ( ) ) ;
336
+ const helper = new GitHelper ( new ThrowErrorLogger ( ) , { token : 'token' } ) ;
340
337
await expect ( helper . runCommand ( workDir , [
341
338
'command1' ,
342
339
'command2' ,
@@ -466,7 +463,7 @@ describe('GitHelper', () => {
466
463
execCalledWith ( mockExec , [
467
464
'git tag' ,
468
465
'git tag -d \'v1.2.3\' \'v1.2.4\' \'v1.2.5\' \'v1.2.6\' || :' ,
469
- 'git fetch \'https://octocat:token @github.com/hello/world.git\' --tags > /dev/null 2>&1' ,
466
+ 'git fetch \'https://octocat:token1 @github.com/hello/world.git\' --tags > /dev/null 2>&1' ,
470
467
] ) ;
471
468
} ) ;
472
469
@@ -480,7 +477,7 @@ describe('GitHelper', () => {
480
477
'git tag' ,
481
478
'git tag -d \'v1.2.3\' \'v1.2.4\' \'v1.2.5\' || :' ,
482
479
'git tag -d \'v1.2.6\' || :' ,
483
- 'git fetch \'https://octocat:token @github.com/hello/world.git\' --tags > /dev/null 2>&1' ,
480
+ 'git fetch \'https://octocat:token1 @github.com/hello/world.git\' --tags > /dev/null 2>&1' ,
484
481
] ) ;
485
482
} ) ;
486
483
} ) ;
@@ -492,7 +489,7 @@ describe('GitHelper', () => {
492
489
await helper . deleteTag ( workDir , 'delete-tag' , context ( ) ) ;
493
490
494
491
execCalledWith ( mockExec , [
495
- 'git push \'https://octocat:token @github.com/hello/world.git\' --delete tags/delete-tag > /dev/null 2>&1 || :' ,
492
+ 'git push \'https://octocat:token1 @github.com/hello/world.git\' --delete tags/delete-tag > /dev/null 2>&1 || :' ,
496
493
'git tag -d delete-tag || :' ,
497
494
] ) ;
498
495
} ) ;
@@ -506,7 +503,7 @@ describe('GitHelper', () => {
506
503
] , context ( ) ) ;
507
504
508
505
execCalledWith ( mockExec , [
509
- 'git push \'https://octocat:token @github.com/hello/world.git\' --delete tags/delete-tag1 tags/delete-tag2 > /dev/null 2>&1 || :' ,
506
+ 'git push \'https://octocat:token1 @github.com/hello/world.git\' --delete tags/delete-tag1 tags/delete-tag2 > /dev/null 2>&1 || :' ,
510
507
'git tag -d delete-tag1 delete-tag2 || :' ,
511
508
] ) ;
512
509
} ) ;
@@ -523,8 +520,8 @@ describe('GitHelper', () => {
523
520
] , context ( ) , 3 ) ;
524
521
525
522
execCalledWith ( mockExec , [
526
- 'git push \'https://octocat:token @github.com/hello/world.git\' --delete tags/delete-tag1 tags/delete-tag2 tags/delete-tag3 > /dev/null 2>&1 || :' ,
527
- 'git push \'https://octocat:token @github.com/hello/world.git\' --delete tags/delete-tag4 refs/tags/delete-tag5 > /dev/null 2>&1 || :' ,
523
+ 'git push \'https://octocat:token1 @github.com/hello/world.git\' --delete tags/delete-tag1 tags/delete-tag2 tags/delete-tag3 > /dev/null 2>&1 || :' ,
524
+ 'git push \'https://octocat:token1 @github.com/hello/world.git\' --delete tags/delete-tag4 refs/tags/delete-tag5 > /dev/null 2>&1 || :' ,
528
525
'git tag -d delete-tag1 delete-tag2 delete-tag3 || :' ,
529
526
'git tag -d delete-tag4 delete-tag5 || :' ,
530
527
] ) ;
@@ -538,10 +535,10 @@ describe('GitHelper', () => {
538
535
await helper . copyTag ( workDir , 'new-tag' , 'from-tag' , context ( ) ) ;
539
536
540
537
execCalledWith ( mockExec , [
541
- 'git push \'https://octocat:token @github.com/hello/world.git\' --delete tags/new-tag > /dev/null 2>&1 || :' ,
538
+ 'git push \'https://octocat:token1 @github.com/hello/world.git\' --delete tags/new-tag > /dev/null 2>&1 || :' ,
542
539
'git tag -d new-tag || :' ,
543
540
'git tag new-tag from-tag' ,
544
- 'git push \'https://octocat:token @github.com/hello/world.git\' refs/tags/new-tag > /dev/null 2>&1' ,
541
+ 'git push \'https://octocat:token1 @github.com/hello/world.git\' refs/tags/new-tag > /dev/null 2>&1' ,
545
542
] ) ;
546
543
} ) ;
547
544
} ) ;
@@ -576,7 +573,7 @@ describe('GitHelper', () => {
576
573
await helper . push ( workDir , 'test-branch' , true , context ( ) ) ;
577
574
578
575
execCalledWith ( mockExec , [
579
- 'git push --tags \'https://octocat:token @github.com/hello/world.git\' \'test-branch:refs/heads/test-branch\' > /dev/null 2>&1' ,
576
+ 'git push --tags \'https://octocat:token1 @github.com/hello/world.git\' \'test-branch:refs/heads/test-branch\' > /dev/null 2>&1' ,
580
577
] ) ;
581
578
} ) ;
582
579
@@ -586,7 +583,7 @@ describe('GitHelper', () => {
586
583
await helper . push ( workDir , 'test-branch' , false , context ( ) ) ;
587
584
588
585
execCalledWith ( mockExec , [
589
- 'git push \'https://octocat:token @github.com/hello/world.git\' \'test-branch:refs/heads/test-branch\' > /dev/null 2>&1' ,
586
+ 'git push \'https://octocat:token1 @github.com/hello/world.git\' \'test-branch:refs/heads/test-branch\' > /dev/null 2>&1' ,
590
587
] ) ;
591
588
} ) ;
592
589
} ) ;
@@ -598,7 +595,7 @@ describe('GitHelper', () => {
598
595
await helper . forcePush ( workDir , 'test-branch' , context ( ) ) ;
599
596
600
597
execCalledWith ( mockExec , [
601
- 'git push --force \'https://octocat:token @github.com/hello/world.git\' \'test-branch:refs/heads/test-branch\' > /dev/null 2>&1' ,
598
+ 'git push --force \'https://octocat:token1 @github.com/hello/world.git\' \'test-branch:refs/heads/test-branch\' > /dev/null 2>&1' ,
602
599
] ) ;
603
600
} ) ;
604
601
} ) ;
@@ -705,11 +702,11 @@ describe('GitHelper', () => {
705
702
} ) ) ;
706
703
707
704
execCalledWith ( mockExec , [
708
- 'git clone \'--branch=test\' \'--depth=3\' \'https://octocat:token @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
705
+ 'git clone \'--branch=test\' \'--depth=3\' \'https://octocat:token1 @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
709
706
'git clone \'--branch=test\' \'--depth=3\' origin \'.\' > /dev/null 2>&1 || :' ,
710
707
'git clone \'--branch=test\' \'--depth=3\' test \'.\' > /dev/null 2>&1 || :' ,
711
708
'git clone \'--branch=test\' \'--depth=3\' origin \'.\' || :' ,
712
- 'git clone \'--branch=test\' \'--depth=3\' \'https://octocat:token @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
709
+ 'git clone \'--branch=test\' \'--depth=3\' \'https://octocat:token1 @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
713
710
] ) ;
714
711
} ) ;
715
712
} ) ;
@@ -718,11 +715,8 @@ describe('GitHelper', () => {
718
715
describe ( 'GitHelper with params 1' , ( ) => {
719
716
testEnv ( ) ;
720
717
testChildProcess ( ) ;
721
- beforeEach ( ( ) => {
722
- process . env . INPUT_GITHUB_TOKEN = 'token' ;
723
- } ) ;
724
718
725
- const helper = new GitHelper ( new Logger ( ) , { depth : 1 , filter : ( line : string ) : boolean => line . endsWith ( '.md' ) } ) ;
719
+ const helper = new GitHelper ( new Logger ( ) , { depth : 1 , filter : ( line : string ) : boolean => line . endsWith ( '.md' ) , token : 'token2' } ) ;
726
720
727
721
describe ( 'clone' , ( ) => {
728
722
it ( 'should run git clone' , async ( ) => {
@@ -734,7 +728,7 @@ describe('GitHelper with params 1', () => {
734
728
} ) ) ;
735
729
736
730
execCalledWith ( mockExec , [
737
- 'git clone \'--branch=test\' \'--depth=1\' \'https://octocat:token @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
731
+ 'git clone \'--branch=test\' \'--depth=1\' \'https://octocat:token2 @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
738
732
] ) ;
739
733
} ) ;
740
734
} ) ;
@@ -752,14 +746,33 @@ describe('GitHelper with params 1', () => {
752
746
describe ( 'GitHelper with params 2' , ( ) => {
753
747
testEnv ( ) ;
754
748
testChildProcess ( ) ;
755
- beforeEach ( ( ) => {
756
- process . env . INPUT_GITHUB_TOKEN = 'token' ;
749
+
750
+ describe ( 'clone' , ( ) => {
751
+ it ( 'should run git clone' , async ( ) => {
752
+ process . env . INPUT_GITHUB_TOKEN = 'token3' ;
753
+ const helper = new GitHelper ( new Logger ( ) , { depth : - 1 } ) ;
754
+ setExists ( false ) ;
755
+ const mockExec = spyOnExec ( ) ;
756
+
757
+ await helper . clone ( workDir , context ( {
758
+ ref : 'refs/heads/test' ,
759
+ } ) ) ;
760
+
761
+ execCalledWith ( mockExec , [
762
+ 'git clone \'--branch=test\' \'https://octocat:[email protected] /hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
763
+ ] ) ;
764
+ } ) ;
757
765
} ) ;
766
+ } ) ;
758
767
759
- const helper = new GitHelper ( new Logger ( ) , { depth : - 1 } ) ;
768
+ describe ( 'GitHelper without params' , ( ) => {
769
+ testEnv ( ) ;
770
+ testChildProcess ( ) ;
760
771
761
772
describe ( 'clone' , ( ) => {
762
773
it ( 'should run git clone' , async ( ) => {
774
+ process . env . INPUT_GITHUB_TOKEN = 'token4' ;
775
+ const helper = new GitHelper ( new Logger ( ) ) ;
763
776
setExists ( false ) ;
764
777
const mockExec = spyOnExec ( ) ;
765
778
@@ -768,7 +781,7 @@ describe('GitHelper with params 2', () => {
768
781
} ) ) ;
769
782
770
783
execCalledWith ( mockExec , [
771
- 'git clone \'--branch=test\' \'https://octocat:token @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
784
+ 'git clone \'--branch=test\' \'--depth=3\' \' https://octocat:token4 @github.com/hello/world.git\' \'.\' > /dev/null 2>&1 || :' ,
772
785
] ) ;
773
786
} ) ;
774
787
} ) ;
0 commit comments