refactor(dev-infra): set up new method for checking range of commits (#41341)

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
This commit is contained in:
Joey Perrott
2021-03-24 16:17:15 -07:00
committed by Alex Rickabaugh
parent 18bc9ffb51
commit 381ea9d7d4
14 changed files with 208 additions and 131 deletions
@@ -5,8 +5,9 @@
* 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 {error, info} from '../../utils/console';
import {Commit, parseCommitMessagesForRange} from '../parse';
import {error, green, info, red} from '../../utils/console';
import {Commit} from '../parse';
import {getCommitsInRange} from '../utils';
import {printValidationErrors, validateCommitMessage, ValidateCommitMessageOptions} from '../validate';
// Whether the provided commit is a fixup commit.
@@ -16,12 +17,13 @@ const isNonFixup = (commit: Commit) => !commit.isFixup;
const extractCommitHeader = (commit: Commit) => commit.header;
/** Validate all commits in a provided git commit range. */
export function validateCommitRange(range: string) {
export async function validateCommitRange(from: string, to: string) {
/** A list of tuples of the commit header string and a list of error messages for the commit. */
const errors: [commitHeader: string, errors: string[]][] = [];
/** A list of parsed commit messages from the range. */
const commits = parseCommitMessagesForRange(range);
info(`Examining ${commits.length} commit(s) in the provided range: ${range}`);
const commits = await getCommitsInRange(from, to);
info(`Examining ${commits.length} commit(s) in the provided range: ${from}..${to}`);
/**
* Whether all commits in the range are valid, commits are allowed to be fixup commits for other
@@ -32,7 +34,7 @@ export function validateCommitRange(range: string) {
disallowSquash: true,
nonFixupCommitHeaders: isNonFixup(commit) ?
undefined :
commits.slice(0, i).filter(isNonFixup).map(extractCommitHeader)
commits.slice(i + 1).filter(isNonFixup).map(extractCommitHeader)
};
const {valid, errors: localErrors} = validateCommitMessage(commit, options);
if (localErrors.length) {
@@ -42,9 +44,9 @@ export function validateCommitRange(range: string) {
});
if (allCommitsInRangeValid) {
info('√ All commit messages in range valid.');
info(green('√ All commit messages in range valid.'));
} else {
error('✘ Invalid commit message');
error(red('✘ Invalid commit message'));
errors.forEach(([header, validationErrors]) => {
error.group(header);
printValidationErrors(validationErrors);