2020-09-14 16:21:31 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {Arguments, Argv, CommandModule} from 'yargs';
|
|
|
|
|
|
|
|
import {info} from '../../utils/console';
|
|
|
|
|
|
|
|
import {validateCommitRange} from './validate-range';
|
|
|
|
|
|
|
|
|
|
|
|
export interface ValidateRangeOptions {
|
2021-03-24 19:17:15 -04:00
|
|
|
startingRef: string;
|
|
|
|
endingRef: string;
|
2020-09-14 16:21:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Builds the command. */
|
|
|
|
function builder(yargs: Argv) {
|
2021-03-24 19:17:15 -04:00
|
|
|
return yargs
|
|
|
|
.positional('startingRef', {
|
|
|
|
description: 'The first ref in the range to select',
|
|
|
|
type: 'string',
|
|
|
|
demandOption: true,
|
|
|
|
})
|
|
|
|
.positional('endingRef', {
|
|
|
|
description: 'The last ref in the range to select',
|
|
|
|
type: 'string',
|
|
|
|
default: 'HEAD',
|
|
|
|
});
|
2020-09-14 16:21:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Handles the command. */
|
2021-03-24 19:17:15 -04:00
|
|
|
async function handler({startingRef, endingRef}: Arguments<ValidateRangeOptions>) {
|
2020-09-14 16:21:31 -04:00
|
|
|
// If on CI, and no pull request number is provided, assume the branch
|
|
|
|
// being run on is an upstream branch.
|
|
|
|
if (process.env['CI'] && process.env['CI_PULL_REQUEST'] === 'false') {
|
|
|
|
info(`Since valid commit messages are enforced by PR linting on CI, we do not`);
|
|
|
|
info(`need to validate commit messages on CI runs on upstream branches.`);
|
|
|
|
info();
|
|
|
|
info(`Skipping check of provided commit range`);
|
|
|
|
return;
|
|
|
|
}
|
2021-03-24 19:17:15 -04:00
|
|
|
await validateCommitRange(startingRef, endingRef);
|
2020-09-14 16:21:31 -04:00
|
|
|
}
|
|
|
|
|
2021-03-24 19:17:15 -04:00
|
|
|
/** yargs command module describing the command. */
|
2020-09-14 16:21:31 -04:00
|
|
|
export const ValidateRangeModule: CommandModule<{}, ValidateRangeOptions> = {
|
|
|
|
handler,
|
|
|
|
builder,
|
2021-03-24 19:17:15 -04:00
|
|
|
command: 'validate-range <starting-ref> [ending-ref]',
|
2020-09-14 16:21:31 -04:00
|
|
|
describe: 'Validate a range of commit messages',
|
|
|
|
};
|