import { Context } from "@actions/github/lib/context" ; export async function createBranch ( getOctokit , context , branch , sha ? ) { const toolkit = getOctokit ( githubToken ( ) ) ; branch = branch . replace ( 'refs/heads/' , '' ) ; try { await toolkit . rest . repos . getBranch ( { ... context . repo , branch } ) ; } catch ( error ) { if ( error . name === 'HttpError' && error . status === 404 ) { await toolkit . rest . git . createRef ( { ref : `refs/heads/${ branch }` , sha : sha || context . sha , ... context . repo } ) ; } else { throw Error ( error ) ; } } } function githubToken ( ) { const token = process . env . GITHUB_TOKEN ; if ( ! token ) throw ReferenceError ( 'No token defined in the environment variables' ) ; return token ; }