refactor(dev-infra): move `parseCommitMessagesForRange` into the parse file (#39747)
When attempting to actually rely on `parseCommitMessagesForRange`, it became apparent that the function really belongs in the parse file, rather than utils. PR Close #39747
This commit is contained in:
parent
e2ce9af115
commit
881b77ef46
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue