Skip to content

Commit

Permalink
feat(nx-heroku): add function to show repo size
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Apr 18, 2023
1 parent a9c4251 commit eedcc26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/nx-heroku/src/executors/common/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@ export async function getGitRemoteBranch(options: {
);
return stdout?.trim();
}

/**
* @returns {Promise<string>} size (eg: 1.06 GiB)
*/
export async function getGitRepoSizePack(): Promise<string> {
const { stdout } = await exec(
`git count-objects -H -v | grep 'size-pack' | cut -d':' -f2`,
{ encoding: 'utf-8' }
);
return stdout?.trim();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Inject, Service } from 'typedi';
import { Environment, EXECUTOR_CONTEXT } from '../../common/constants';
import {
getGitEmail,
getGitRepoSizePack,
getGitUserName,
setGitEmail,
setGitUserName,
Expand Down Expand Up @@ -73,9 +74,16 @@ export class HerokuDeployService extends HerokuBaseService<DeployExecutorSchema>
);
// If the Repo clone is shallow, make it unshallow
if (isShallow === 'true\n') {
this.logger.warn(
'The git repository is shallow, fetching all commits to get the correct size of the repository'
);
await exec('git fetch --prune --unshallow');
}

// show git repo size
const size = await getGitRepoSizePack();
this.logger.info(`Git repo size: ${size}`);

await this.setupHerokuAuth();
}

Expand Down

0 comments on commit eedcc26

Please sign in to comment.