@@ -141,6 +141,31 @@ test(`no file contents provided`, async () => {
141141 ) ;
142142} ) ;
143143
144+ test ( `success (submodule, branch exists)` , async ( ) => {
145+ const body = {
146+ ...validRequest ,
147+ changes : [
148+ {
149+ message : "Your submodule commit message" ,
150+ files : {
151+ my_submodule : {
152+ contents : "new-submodule-sha" ,
153+ mode : "160000" ,
154+ type : "commit"
155+ }
156+ }
157+ }
158+ ]
159+ } ;
160+
161+ mockGetRef ( branch , `sha-${ branch } ` , true ) ;
162+ mockCreateTreeSubmodule ( `sha-${ branch } ` ) ;
163+ mockCommitSubmodule ( `sha-${ branch } ` ) ;
164+ mockUpdateRef ( branch ) ;
165+
166+ await expect ( run ( body ) ) . resolves . toEqual ( branch ) ;
167+ } ) ;
168+
144169test ( `success (branch exists)` , async ( ) => {
145170 const body = {
146171 ...validRequest
@@ -277,6 +302,31 @@ function mockCreateBlobFileThree() {
277302 ) ;
278303}
279304
305+ function mockCreateTreeSubmodule ( baseTree ) {
306+ const expectedBody = {
307+ tree : [
308+ {
309+ path : "my_submodule" ,
310+ sha : "new-submodule-sha" ,
311+ mode : "160000" ,
312+ type : "commit"
313+ }
314+ ] ,
315+ base_tree : baseTree
316+ } ;
317+
318+ const m = nock ( "https://api.github.com" ) . post (
319+ `/repos/${ owner } /${ repo } /git/trees` ,
320+ expectedBody
321+ ) ;
322+
323+ const body = {
324+ sha : "4112258c05f8ce2b0570f1bbb1a330c0f9595ff9"
325+ } ;
326+
327+ m . reply ( 200 , body ) ;
328+ }
329+
280330function mockCreateTree ( baseTree ) {
281331 const expectedBody = {
282332 tree : [
@@ -333,6 +383,25 @@ function mockCreateTreeSecond(baseTree) {
333383 m . reply ( 200 , body ) ;
334384}
335385
386+ function mockCommitSubmodule ( baseTree ) {
387+ const expectedBody = {
388+ message : "Your submodule commit message" ,
389+ tree : "4112258c05f8ce2b0570f1bbb1a330c0f9595ff9" ,
390+ parents : [ baseTree ]
391+ } ;
392+
393+ const m = nock ( "https://api.github.com" ) . post (
394+ `/repos/${ owner } /${ repo } /git/commits` ,
395+ expectedBody
396+ ) ;
397+
398+ const body = {
399+ sha : "ef105a72c03ce2743d90944c2977b1b5563b43c0"
400+ } ;
401+
402+ m . reply ( 200 , body ) ;
403+ }
404+
336405function mockCommit ( baseTree ) {
337406 const expectedBody = {
338407 message : "Your commit message" ,
0 commit comments