import { isEmptyRepository , getCurrentBranch , checkoutBranch , commitPath , pushBranch , getOriginUrl , getPullRequestLink , deleteBranch , } from "./gitutils" ; import { logger } from "../logger" ; import { errorStatusCode } from "./errorStatusCode" ; import { build as buildError } from "./errorBuilder" ; param newBranchName param pathspecs export const checkoutCommitPushCreatePRLink = async ( newBranchName , ... pathspecs ) : Promise < void > => { try { if ( await isEmptyRepository ( ) ) { logger . error ( `You have checked out an empty git repository. Please create a base commit. Run 'git commit -m "Init HLD" --allow-empty && git push origin HEAD'` ) ; return ; } const currentBranch = await getCurrentBranch ( ) ; await checkoutBranch ( newBranchName , true ) ; await commitPath ( newBranchName , ... pathspecs ) ; await pushBranch ( newBranchName ) ; const originUrl = await getOriginUrl ( ) ; const pullRequestLink = await getPullRequestLink ( currentBranch , newBranchName , originUrl ) ; logger . info ( `Link to create PR: ${ pullRequestLink }` ) ; await checkoutBranch ( currentBranch , false ) ; await deleteBranch ( newBranchName ) ; } catch ( err ) { throw buildError ( errorStatusCode . GIT_OPS_ERR , "git-checkout-commit-push-create-PR-link" , err ) ; } } ;