@@ -263,6 +263,57 @@ describe("node", () => {
263263 } ) ;
264264 } ) ;
265265
266+ it ( "can create a commit using the REST git API" , async ( ) => {
267+ const branch = `${ TEST_BRANCH_PREFIX } -rest-git-${ Date . now ( ) } ` ;
268+ const filePath = "rest-git-api-test.txt" ;
269+
270+ const baseRef = await octokit . rest . git . getRef ( {
271+ ...REPO ,
272+ ref : "heads/main" ,
273+ } ) ;
274+ const baseOid = baseRef . data . object . sha ;
275+
276+ const baseCommit = await octokit . rest . git . getCommit ( {
277+ ...REPO ,
278+ commit_sha : baseOid ,
279+ } ) ;
280+
281+ const tree = await octokit . rest . git . createTree ( {
282+ ...REPO ,
283+ base_tree : baseCommit . data . tree . sha ,
284+ tree : [
285+ {
286+ path : filePath ,
287+ mode : "100644" ,
288+ type : "blob" ,
289+ content : "Hello from the REST git API!\n" ,
290+ } ,
291+ ] ,
292+ } ) ;
293+
294+ const commit = await octokit . rest . git . createCommit ( {
295+ ...REPO ,
296+ message : "Test REST git commit" ,
297+ tree : tree . data . sha ,
298+ parents : [ baseOid ] ,
299+ } ) ;
300+
301+ await octokit . rest . git . createRef ( {
302+ ...REPO ,
303+ ref : `refs/heads/${ branch } ` ,
304+ sha : commit . data . sha ,
305+ } ) ;
306+
307+ await waitForGitHubToBeReady ( ) ;
308+
309+ const branchRef = await octokit . rest . git . getRef ( {
310+ ...REPO ,
311+ ref : `heads/${ branch } ` ,
312+ } ) ;
313+
314+ expect ( branchRef . data . object . sha ) . toEqual ( commit . data . sha ) ;
315+ } ) ;
316+
266317 describe ( "existing branches" , ( ) => {
267318 it ( "can commit to existing branch when force is true" , async ( ) => {
268319 const branch = `${ TEST_BRANCH_PREFIX } -existing-branch-force` ;
0 commit comments