Skip to content

Add more messages to prettier prepush to help diagnose intermittent problems #2909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions tools/gitHooks/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const { resolve } = require('path');
const simpleGit = require('simple-git/promise');
const fs = require('mz/fs');
const ora = require('ora');
const chalk = require('chalk');

const root = resolve(__dirname, '../..');
const git = simpleGit(root);
Expand Down Expand Up @@ -116,16 +117,24 @@ async function doLicenseCommit(changedFiles) {

const hasDiff = await git.diff();

if (!hasDiff) return;
if (!hasDiff) {
console.log(
chalk`\n{red License pass caused no changes.} Skipping commit.\n`
);
return;
}

const gitSpinner = ora(' Creating automated license commit').start();
await git.add('.');

await git.commit('[AUTOMATED]: License Headers');
const commit = await git.commit('[AUTOMATED]: License Headers');

gitSpinner.stopAndPersist({
symbol: '✅'
});
console.log(
chalk`{green Commited ${commit.commit} to branch ${commit.branch}}`
);
}

module.exports = {
Expand Down
16 changes: 13 additions & 3 deletions tools/gitHooks/prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ async function doPrettierCommit(changedFiles) {

// Only run on .js or .ts files.
const targetFiles = changedFiles.filter(line => line.match(/(js|ts)$/));
if (targetFiles.length === 0) return;
if (targetFiles.length === 0) {
console.log('No files changed.');
}

const stylingSpinner = ora(
` Formatting ${targetFiles.length} files with prettier`
Expand All @@ -88,15 +90,23 @@ async function doPrettierCommit(changedFiles) {

const hasDiff = await git.diff();

if (!hasDiff) return;
if (!hasDiff) {
console.log(
chalk`\n{red Prettier formatting caused no changes.} Skipping commit.\n`
);
return;
}

const gitSpinner = ora(' Creating automated style commit').start();
await git.add(targetFiles);

await git.commit('[AUTOMATED]: Prettier Code Styling');
const commit = await git.commit('[AUTOMATED]: Prettier Code Styling');
gitSpinner.stopAndPersist({
symbol: '✅'
});
console.log(
chalk`{green Commited ${commit.commit} to branch ${commit.branch}}`
);
}

module.exports = {
Expand Down