Skip to content

Commit

Permalink
Merge pull request #1131 from chromaui/jmhobbs/cap-2564-getcommittedf…
Browse files Browse the repository at this point in the history
…ilecount-causing-failures

Errors in project metadata gathering causing build failures
  • Loading branch information
jmhobbs authored Dec 11, 2024
2 parents 80f8504 + 9f23eea commit 46d617e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion node-src/git/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ describe('getCommittedFileCount', () => {
it('constructs the correct command', async () => {
await getCommittedFileCount(['page', 'screen'], ['js', 'ts']);
expect(execGitCommandCountLines).toHaveBeenCalledWith(
'git ls-files -- "*page*.js" "*page*.ts" "*Page*.js" "*Page*.ts" "*screen*.js" "*screen*.ts" "*Screen*.js" "*Screen*.ts"'
'git ls-files -- "*page*.js" "*page*.ts" "*Page*.js" "*Page*.ts" "*screen*.js" "*screen*.ts" "*Screen*.js" "*Screen*.ts"',
expect.anything()
);
});
it('parses the count successfully', async () => {
Expand Down
6 changes: 4 additions & 2 deletions node-src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export async function getStorybookCreationDate(ctx: {
*/
export async function getNumberOfComitters() {
try {
return execGitCommandCountLines(`git shortlog -sn --all --since="6 months ago"`, {
return await execGitCommandCountLines(`git shortlog -sn --all --since="6 months ago"`, {
timeout: 5000,
});
} catch {
Expand All @@ -462,7 +462,9 @@ export async function getCommittedFileCount(nameMatches: string[], extensions: s
extensions.map((extension) => `"*${match}*.${extension}"`)
);

return execGitCommandCountLines(`git ls-files -- ${globs.join(' ')}`);
return await execGitCommandCountLines(`git ls-files -- ${globs.join(' ')}`, {
timeout: 5000,
});
} catch {
return undefined;
}
Expand Down
18 changes: 11 additions & 7 deletions node-src/tasks/gitInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,17 @@ export const setGitInfo = async (ctx: Context, task: Task) => {
...commitAndBranchInfo,
};

ctx.projectMetadata = {
hasRouter: getHasRouter(ctx.packageJson),
creationDate: await getRepositoryCreationDate(),
storybookCreationDate: await getStorybookCreationDate(ctx),
numberOfCommitters: await getNumberOfComitters(),
numberOfAppFiles: await getCommittedFileCount(['page', 'screen'], ['js', 'jsx', 'ts', 'tsx']),
};
try {
ctx.projectMetadata = {
hasRouter: getHasRouter(ctx.packageJson),
creationDate: await getRepositoryCreationDate(),
storybookCreationDate: await getStorybookCreationDate(ctx),
numberOfCommitters: await getNumberOfComitters(),
numberOfAppFiles: await getCommittedFileCount(['page', 'screen'], ['js', 'jsx', 'ts', 'tsx']),
};
} catch (err) {
ctx.log.debug('Failed to gather project metadata', err);
}

if (isLocalBuild && !ctx.git.gitUserEmail) {
throw new Error(gitUserEmailNotFound());
Expand Down

0 comments on commit 46d617e

Please sign in to comment.