feat(dev-infra): update commit-message functions to properly type commits from git log (#41458)

For commits from git log entries additional fields are available such as the reference
hash and author name, update the utility functions in commit-message to include the
parsed fields.  Additionally define, per commit message type, whether to include the
commit in a release notes entry.

PR Close #41458
This commit is contained in:
Joey Perrott
2021-04-01 16:03:38 -07:00
committed by atscott
parent ba3344ddbe
commit c63d00e5b0
4 changed files with 60 additions and 8 deletions
+18 -1
View File
@@ -41,6 +41,13 @@ export interface Commit {
isRevert: boolean;
}
/** A parsed commit which originated from a Git Log entry */
export interface CommitFromGitLog extends Commit {
author: string;
hash: string;
shortHash: string;
}
/**
* A list of tuples expressing the fields to extract from each commit log entry. The tuple contains
* two values, the first is the key for the property and the second is the template shortcut for the
@@ -107,9 +114,16 @@ const parseOptions: Options&{notesPattern: (keywords: string) => RegExp} = {
notesPattern: (keywords: string) => new RegExp(`(${keywords})(?:: ?)(.*)`),
};
/** Parse a commit message into its composite parts. */
export const parseCommitMessage: (fullText: string) => Commit = parseInternal;
/** Parse a commit message from a git log entry into its composite parts. */
export const parseCommitFromGitLog: (fullText: Buffer) => CommitFromGitLog = parseInternal;
/** Parse a full commit message into its composite parts. */
export function parseCommitMessage(fullText: string|Buffer): Commit {
function parseInternal(fullText: string): Commit;
function parseInternal(fullText: Buffer): CommitFromGitLog;
function parseInternal(fullText: string|Buffer): CommitFromGitLog|Commit {
// Ensure the fullText symbol is a `string`, even if a Buffer was provided.
fullText = fullText.toString();
/** The commit message text with the fixup and squash markers stripped out. */
@@ -148,5 +162,8 @@ export function parseCommitMessage(fullText: string|Buffer): Commit {
isFixup: FIXUP_PREFIX_RE.test(fullText),
isSquash: SQUASH_PREFIX_RE.test(fullText),
isRevert: REVERT_PREFIX_RE.test(fullText),
author: commit.author || undefined,
hash: commit.hash || undefined,
shortHash: commit.shortHash || undefined,
};
}