@@ -60,6 +60,7 @@ const createCommitResponse = createResponse<Octokit.GitCreateCommitResponse>({
60
60
verified : true ,
61
61
} ,
62
62
} ) ;
63
+ const escape = value => encodeURIComponent ( value ) . replace ( new RegExp ( '%2F' , 'g' ) , '%252F' ) ;
63
64
64
65
describe ( 'ApiHelper' , ( ) => {
65
66
disableNetConnect ( nock ) ;
@@ -213,7 +214,7 @@ describe('ApiHelper', () => {
213
214
const fn1 = jest . fn ( ) ;
214
215
const fn2 = jest . fn ( ) ;
215
216
nock ( 'https://api.github.com' )
216
- . patch ( '/repos/hello/world/git/refs/' + encodeURIComponent ( 'heads/test' ) , body => {
217
+ . patch ( '/repos/hello/world/git/refs/' + escape ( 'heads/test' ) , body => {
217
218
fn1 ( ) ;
218
219
expect ( body ) . toHaveProperty ( 'sha' ) ;
219
220
return body ;
@@ -234,7 +235,7 @@ describe('ApiHelper', () => {
234
235
const fn2 = jest . fn ( ) ;
235
236
const fn3 = jest . fn ( ) ;
236
237
nock ( 'https://api.github.com' )
237
- . patch ( '/repos/hello/world/git/refs/' + encodeURIComponent ( 'heads/new-topic' ) , body => {
238
+ . patch ( '/repos/hello/world/git/refs/' + escape ( 'heads/new-topic' ) , body => {
238
239
fn1 ( ) ;
239
240
expect ( body ) . toHaveProperty ( 'sha' ) ;
240
241
return body ;
@@ -263,7 +264,7 @@ describe('ApiHelper', () => {
263
264
it ( 'should cache PR get api' , async ( ) => {
264
265
const fn = jest . fn ( ) ;
265
266
nock ( 'https://api.github.com' )
266
- . patch ( '/repos/hello/world/git/refs/' + encodeURIComponent ( 'heads/new-topic' ) )
267
+ . patch ( '/repos/hello/world/git/refs/' + escape ( 'heads/new-topic' ) )
267
268
. reply ( 200 , ( ) => {
268
269
return getApiFixture ( rootDir , 'repos.git.refs.update' ) ;
269
270
} )
@@ -286,7 +287,7 @@ describe('ApiHelper', () => {
286
287
287
288
it ( 'should output warning' , async ( ) => {
288
289
nock ( 'https://api.github.com' )
289
- . patch ( '/repos/hello/world/git/refs/' + encodeURIComponent ( 'heads/test' ) , body => {
290
+ . patch ( '/repos/hello/world/git/refs/' + escape ( 'heads/test' ) , body => {
290
291
expect ( body ) . toHaveProperty ( 'sha' ) ;
291
292
return body ;
292
293
} )
@@ -326,7 +327,7 @@ describe('ApiHelper', () => {
326
327
it ( 'should create ref' , async ( ) => {
327
328
const fn = jest . fn ( ) ;
328
329
nock ( 'https://api.github.com' )
329
- . delete ( '/repos/hello/world/git/refs/heads/featureA' )
330
+ . delete ( '/repos/hello/world/git/refs/' + encodeURIComponent ( ' heads/featureA') )
330
331
. reply ( 204 , ( ) => {
331
332
fn ( ) ;
332
333
return getApiFixture ( rootDir , 'repos.git.refs.create' ) ;
@@ -579,7 +580,7 @@ describe('ApiHelper', () => {
579
580
. reply ( 201 , ( ) => getApiFixture ( rootDir , 'repos.git.trees' ) )
580
581
. post ( '/repos/hello/world/git/commits' )
581
582
. reply ( 201 , ( ) => getApiFixture ( rootDir , 'repos.git.commits' ) )
582
- . patch ( '/repos/hello/world/git/refs/' + encodeURIComponent ( 'heads/test' ) )
583
+ . patch ( '/repos/hello/world/git/refs/' + escape ( 'heads/test' ) )
583
584
. reply ( 200 , ( ) => getApiFixture ( rootDir , 'repos.git.refs.update' ) ) ;
584
585
585
586
expect ( await helper . commit ( rootDir , 'test commit message' , [ 'build1.json' , 'build2.json' ] ) ) . toBe ( true ) ;
@@ -625,7 +626,7 @@ describe('ApiHelper', () => {
625
626
. reply ( 201 , ( ) => getApiFixture ( rootDir , 'repos.git.trees' ) )
626
627
. post ( '/repos/hello/world/git/commits' )
627
628
. reply ( 201 , ( ) => getApiFixture ( rootDir , 'repos.git.commits' ) )
628
- . get ( '/repos/hello/world/git/ref/heads/create/test' )
629
+ . get ( '/repos/hello/world/git/ref/' + encodeURIComponent ( ' heads/create/test') )
629
630
. reply ( 404 )
630
631
. post ( '/repos/hello/world/git/refs' )
631
632
. reply ( 201 , ( ) => getApiFixture ( rootDir , 'repos.git.refs.create' ) )
@@ -679,9 +680,9 @@ describe('ApiHelper', () => {
679
680
. reply ( 201 , ( ) => getApiFixture ( rootDir , 'repos.git.trees' ) )
680
681
. post ( '/repos/hello/world/git/commits' )
681
682
. reply ( 201 , ( ) => getApiFixture ( rootDir , 'repos.git.commits' ) )
682
- . get ( '/repos/hello/world/git/ref/heads/create/test' )
683
+ . get ( '/repos/hello/world/git/ref/' + encodeURIComponent ( ' heads/create/test') )
683
684
. reply ( 200 , ( ) => getApiFixture ( rootDir , 'repos.git.ref' ) )
684
- . patch ( '/repos/hello/world/git/refs/heads/create/test' )
685
+ . patch ( '/repos/hello/world/git/refs/' + encodeURIComponent ( ' heads/create/test') )
685
686
. reply ( 200 , ( ) => getApiFixture ( rootDir , 'repos.git.refs.update' ) )
686
687
. post ( '/repos/hello/world/git/refs' )
687
688
. reply ( 201 , ( ) => getApiFixture ( rootDir , 'repos.git.refs.create' ) )
@@ -730,7 +731,7 @@ describe('ApiHelper', () => {
730
731
. reply ( 200 , ( ) => getApiFixture ( rootDir , 'pulls.list' ) )
731
732
. patch ( '/repos/hello/world/pulls/1347' )
732
733
. reply ( 200 , ( ) => getApiFixture ( rootDir , 'pulls.update' ) )
733
- . delete ( '/repos/hello/world/git/refs/heads/close/test' )
734
+ . delete ( '/repos/hello/world/git/refs/' + encodeURIComponent ( ' heads/close/test') )
734
735
. reply ( 204 ) ;
735
736
736
737
await helper . closePR ( 'close/test' ) ;
@@ -753,7 +754,7 @@ describe('ApiHelper', () => {
753
754
. reply ( 201 )
754
755
. patch ( '/repos/hello/world/pulls/1347' )
755
756
. reply ( 200 , ( ) => getApiFixture ( rootDir , 'pulls.update' ) )
756
- . delete ( '/repos/hello/world/git/refs/heads/close/test' )
757
+ . delete ( '/repos/hello/world/git/refs/' + encodeURIComponent ( ' heads/close/test') )
757
758
. reply ( 204 ) ;
758
759
759
760
await helper . closePR ( 'close/test' , 'close message' ) ;
@@ -772,9 +773,9 @@ describe('ApiHelper', () => {
772
773
. persist ( )
773
774
. get ( '/repos/hello/world/pulls?head=hello%3Aclose%2Ftest' )
774
775
. reply ( 200 , ( ) => [ ] )
775
- . get ( '/repos/hello/world/git/ref/heads/close/test' )
776
+ . get ( '/repos/hello/world/git/ref/' + encodeURIComponent ( ' heads/close/test') )
776
777
. reply ( 200 , ( ) => getApiFixture ( rootDir , 'repos.git.ref' ) )
777
- . delete ( '/repos/hello/world/git/refs/heads/close/test' )
778
+ . delete ( '/repos/hello/world/git/refs/' + encodeURIComponent ( ' heads/close/test') )
778
779
. reply ( 204 ) ;
779
780
780
781
await helper . closePR ( 'close/test' ) ;
@@ -792,7 +793,7 @@ describe('ApiHelper', () => {
792
793
. persist ( )
793
794
. get ( '/repos/hello/world/pulls?head=hello%3Aclose%2Ftest' )
794
795
. reply ( 200 , ( ) => [ ] )
795
- . get ( '/repos/hello/world/git/ref/heads/close/test' )
796
+ . get ( '/repos/hello/world/git/ref/' + encodeURIComponent ( ' heads/close/test') )
796
797
. reply ( 404 ) ;
797
798
798
799
await helper . closePR ( 'close/test' ) ;
0 commit comments