381ea9d7d4
Check a range of commits by retrieving the log files to be parsed with the expected format for the parser. This change is in part of a larger set of changes making the process for obtaining and parsing commits for release note creation and message validation consistent. This consistency will make it easier to debug as well as ease the design of tooling which is built on top of these processes. PR Close #41341
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
/**
|
|
* @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 {
|
|
startingRef: string;
|
|
endingRef: string;
|
|
}
|
|
|
|
/** Builds the command. */
|
|
function builder(yargs: Argv) {
|
|
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',
|
|
});
|
|
}
|
|
|
|
/** Handles the command. */
|
|
async function handler({startingRef, endingRef}: Arguments<ValidateRangeOptions>) {
|
|
// 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;
|
|
}
|
|
await validateCommitRange(startingRef, endingRef);
|
|
}
|
|
|
|
/** yargs command module describing the command. */
|
|
export const ValidateRangeModule: CommandModule<{}, ValidateRangeOptions> = {
|
|
handler,
|
|
builder,
|
|
command: 'validate-range <starting-ref> [ending-ref]',
|
|
describe: 'Validate a range of commit messages',
|
|
};
|