UNPKG

commitlint-azure-pipelines-cli

Version:
54 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const commitlint = require("@commitlint/cli"); const execa = require("execa"); async function commitlintAzurePipelines() { if (process.env.TF_BUILD !== 'True') { throw new Error('commitlint-azure-pipelines-cli is designed to be used in Azure Pipelines.'); } const { from, to } = await getCommitRange(); await lint(from, to); } exports.default = commitlintAzurePipelines; function isPR() { return process.env.BUILD_REASON === 'PullRequest'; } async function getCommitRange() { if (isPR()) { return { from: await lastTargetCommit(), to: await lastPrCommit(), }; } const commit = process.env.BUILD_SOURCEVERSION; return { from: commit, to: commit }; } async function lastPrCommit() { const { stdout } = await execa('git', ['rev-parse', 'HEAD^2']); return stdout; } async function lastTargetCommit() { const { stdout } = await execa('git', ['rev-parse', 'HEAD^1']); return stdout; } async function lint(fromHash, toHash) { if (fromHash === toHash) { const { stdout } = await execa('git', [ 'log', '-n', '1', '--pretty=format:%B', fromHash, ]); await execa(commitlint, [], { stdio: ['pipe', 'inherit', 'inherit'], input: stdout, }); } else { await execa(commitlint, ['--from', fromHash, '--to', toHash], { stdio: ['pipe', 'inherit', 'inherit'], }); } } //# sourceMappingURL=index.js.map