Skip to content

Commit

Permalink
chore(repo): exclude master commits from commit linting (#22029)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj authored Feb 28, 2024
1 parent c207081 commit 888110a
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions scripts/commit-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,42 @@
const { types, scopes } = require('./commitizen.js');

console.log('🐟🐟🐟 Validating git commit message 🐟🐟🐟');
const gitMessage = require('child_process')
.execSync('git log -1 --no-merges')

const childProcess = require('child_process');

let gitLogCmd = 'git log -1 --no-merges';

const gitRemotes = childProcess
.execSync('git remote -v')
.toString()
.trim();
.trim()
.split('\n');
const upstreamRemote = gitRemotes.find((remote) =>
remote.includes('nrwl/nx.git')
);
if (upstreamRemote) {
const upstreamRemoteIdentifier = upstreamRemote.split('\t')[0].trim();
console.log(`Comparing against remote ${upstreamRemoteIdentifier}`);
const currentBranch = childProcess
.execSync('git branch --show-current')
.toString()
.trim();

// exclude all commits already present in upstream/master
gitLogCmd =
gitLogCmd + ` ${currentBranch} ^${upstreamRemoteIdentifier}/master`;
} else {
console.error(
'No upstream remote found for nrwl/nx.git. Skipping comparison against upstream master.'
);
}

const gitMessage = childProcess.execSync(gitLogCmd).toString().trim();

if (!gitMessage) {
console.log('No commits found. Skipping commit message validation.');
process.exit(0);
}

const allowedTypes = types.map((type) => type.value).join('|');
const allowedScopes = scopes.map((scope) => scope.value).join('|');
Expand Down

0 comments on commit 888110a

Please sign in to comment.