diff --git a/dev-infra/commit-message/parse.ts b/dev-infra/commit-message/parse.ts index 3ccd870620..bbd95502e7 100644 --- a/dev-infra/commit-message/parse.ts +++ b/dev-infra/commit-message/parse.ts @@ -6,6 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ +import {exec} from '../utils/shelljs'; + /** A parsed commit message. */ export interface ParsedCommitMessage { header: string; @@ -75,3 +77,30 @@ export function parseCommitMessage(commitMsg: string): ParsedCommitMessage { isRevert: REVERT_PREFIX_RE.test(commitMsg), }; } + +/** Retrieve and parse each commit message in a provide range. */ +export function parseCommitMessagesForRange(range: string): ParsedCommitMessage[] { + /** A random number used as a split point in the git log result. */ + const randomValueSeparator = `${Math.random()}`; + /** + * Custom git log format that provides the commit header and body, separated as expected with the + * custom separator as the trailing value. + */ + const gitLogFormat = `%s%n%n%b${randomValueSeparator}`; + + // Retrieve the commits in the provided range. + const result = exec(`git log --reverse --format=${gitLogFormat} ${range}`); + if (result.code) { + throw new Error(`Failed to get all commits in the range:\n ${result.stderr}`); + } + + return result + // Separate the commits from a single string into individual commits. + .split(randomValueSeparator) + // Remove extra space before and after each commit message. + .map(l => l.trim()) + // Remove any superfluous lines which remain from the split. + .filter(line => !!line) + // Parse each commit message. + .map(commit => parseCommitMessage(commit)); +} diff --git a/dev-infra/commit-message/utils.ts b/dev-infra/commit-message/utils.ts deleted file mode 100644 index 17c75c2935..0000000000 --- a/dev-infra/commit-message/utils.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @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 {exec} from '../utils/shelljs'; - -import {parseCommitMessage, ParsedCommitMessage} from './parse'; - -/** Retrieve and parse each commit message in a provide range. */ -export function parseCommitMessagesForRange(range: string): ParsedCommitMessage[] { - /** A random number used as a split point in the git log result. */ - const randomValueSeparator = `${Math.random()}`; - /** - * Custom git log format that provides the commit header and body, separated as expected with the - * custom separator as the trailing value. - */ - const gitLogFormat = `%s%n%n%b${randomValueSeparator}`; - - // Retrieve the commits in the provided range. - const result = exec(`git log --reverse --format=${gitLogFormat} ${range}`); - if (result.code) { - throw new Error(`Failed to get all commits in the range:\n ${result.stderr}`); - } - - return result - // Separate the commits from a single string into individual commits. - .split(randomValueSeparator) - // Remove extra space before and after each commit message. - .map(l => l.trim()) - // Remove any superfluous lines which remain from the split. - .filter(line => !!line) - // Parse each commit message. - .map(commit => parseCommitMessage(commit)); -} diff --git a/dev-infra/commit-message/validate-range/validate-range.ts b/dev-infra/commit-message/validate-range/validate-range.ts index bf609139b8..56158e74de 100644 --- a/dev-infra/commit-message/validate-range/validate-range.ts +++ b/dev-infra/commit-message/validate-range/validate-range.ts @@ -7,8 +7,7 @@ */ import {error, info} from '../../utils/console'; -import {ParsedCommitMessage} from '../parse'; -import {parseCommitMessagesForRange} from '../utils'; +import {parseCommitMessagesForRange, ParsedCommitMessage} from '../parse'; import {printValidationErrors, validateCommitMessage, ValidateCommitMessageOptions} from '../validate'; // Whether the provided commit is a fixup commit.