Joey Perrott c63d00e5b0 feat(dev-infra): update commit-message functions to properly type commits from git log ()
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 
2021-04-06 10:04:53 -07:00

33 lines
1.3 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 * as gitCommits_ from 'git-raw-commits';
import {CommitFromGitLog, gitLogFormatForParsing, parseCommitFromGitLog} from './parse';
// Set `gitCommits` as this imported value to address "Cannot call a namespace" error.
const gitCommits = gitCommits_;
/**
* Find all commits within the given range and return an object describing those.
*/
export function getCommitsInRange(from: string, to: string = 'HEAD'): Promise<CommitFromGitLog[]> {
return new Promise((resolve, reject) => {
/** List of parsed commit objects. */
const commits: CommitFromGitLog[] = [];
/** Stream of raw git commit strings in the range provided. */
const commitStream = gitCommits({from, to, format: gitLogFormatForParsing});
// Accumulate the parsed commits for each commit from the Readable stream into an array, then
// resolve the promise with the array when the Readable stream ends.
commitStream.on('data', (commit: Buffer) => commits.push(parseCommitFromGitLog(commit)));
commitStream.on('error', (err: Error) => reject(err));
commitStream.on('end', () => resolve(commits));
});
}