import { ProbotOctokit } from "probot" ; export interface FileToCreate { readonly content : string ; readonly path : string ; } export async function createCommit ( args ) { const getRefResult = await args . octokit . git . getRef ( { owner : args . org , ref : `heads/${ args . branch }` , repo : args . repo , } ) ; const currentCommitSha = getRefResult . data . object . sha ; const getCommitResult = await args . octokit . git . getCommit ( { commit_sha : currentCommitSha , owner : args . org , repo : args . repo , } ) ; const treeSha = getCommitResult . data . tree . sha ; const fileBlobs = [ ] ; for ( const file of args . files ) { const response = await args . octokit . git . createBlob ( { content : file . content , encoding : "utf-8" , owner : args . org , repo : args . repo , } ) ; fileBlobs . push ( response . data ) ; } const treeParams = [ ] ; for ( let i = 0 ; i < fileBlobs . length ; i ++ ) { treeParams . push ( { mode : "100644" , path : args . files [ i ] . path , sha : fileBlobs [ i ] . sha , type : "blob" , } ) ; } const createTreeResult = await args . octokit . git . createTree ( { base_tree : treeSha , owner : args . org , repo : args . repo , tree : treeParams , } ) ; const newCommitResult = await args . octokit . git . createCommit ( { message : args . message , owner : args . org , parents : [ currentCommitSha ] , repo : args . repo , tree : createTreeResult . data . sha , } ) ; const newCommitSha = newCommitResult . data . sha ; await args . octokit . git . updateRef ( { owner : args . org , ref : `heads/${ args . branch }` , repo : args . repo , sha : newCommitSha , } ) ; } type GitCreateTreeParamsTree = { content ? : string ; mode ? : "100644" | "100755" | "040000" | "160000" | "120000" ; path ? : string ; sha ? : string ; type ? : "blob" | "tree" | "commit" ; } ;