Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/local-actions/branch-manager/main.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions github-actions/pull-request-labeling/main.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions ng-dev/commit-message/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface Commit {
fullText: string;
/** The header line of the commit, will be used in the changelog entries. */
header: string;
/** The original header line of the commit, before stripping away fixup, squash, etc. */
originalHeader: string;
/** The full body of the commit, not including the footer. */
body: string;
/** The footer of the commit, containing issue references and note sections. */
Expand Down Expand Up @@ -114,8 +116,8 @@ const parseOptions: ParserOptions = {
noteKeywords: [NoteSections.BREAKING_CHANGE, NoteSections.DEPRECATED],
notesPattern: (keywords: string) => new RegExp(`^\\s*(${keywords}): ?(.*)`),
};

let commitParser: CommitParser | undefined;
/** Instance of the commit parser to parse raw commits. */
const commitParser = new CommitParser(parseOptions);

/** Parse a commit message into its composite parts. */
export const parseCommitMessage: (fullText: string) => Commit = parseInternal;
Expand All @@ -128,21 +130,18 @@ 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. */
const strippedCommitMsg = fullText
.replace(FIXUP_PREFIX_RE, '')
.replace(SQUASH_PREFIX_RE, '')
.replace(REVERT_PREFIX_RE, '');

commitParser ??= new CommitParser(parseOptions);

fullText = fullText.toString().trim();
/** The initially parsed commit. */
const commit = commitParser.parse(strippedCommitMsg);
const commit = commitParser.parse(fullText);
/** A list of breaking change notes from the commit. */
const breakingChanges: CommitNote[] = [];
/** A list of deprecation notes from the commit. */
const deprecations: CommitNote[] = [];
/** The extracted header after stripping away fixup, squash, etc. */
const header = (commit.header || '')
.replace(FIXUP_PREFIX_RE, '')
.replace(SQUASH_PREFIX_RE, '')
.replace(REVERT_PREFIX_RE, '');

// Extract the commit message notes by marked types into their respective lists.
for (const note of commit.notes) {
Expand All @@ -160,9 +159,10 @@ function parseInternal(fullText: string | Buffer): CommitFromGitLog | Commit {
fullText,
breakingChanges,
deprecations,
header,
body: commit.body || '',
footer: commit.footer || '',
header: commit.header || '',
originalHeader: commit.header || '',
references: commit.references,
scope: commit['scope'] || '',
subject: commit['subject'] || '',
Expand Down
26 changes: 21 additions & 5 deletions ng-dev/release/notes/commits/get-commits-in-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function getCommitsForRangeWithDeduping(
}

/** Fetches commits for the given revision range using `git log`. */
export function fetchCommitsForRevisionRange(
function fetchCommitsForRevisionRange(
client: GitClient,
revisionRange: string,
): CommitFromGitLog[] {
Expand All @@ -85,12 +85,28 @@ export function fetchCommitsForRevisionRange(
`--format=${gitLogFormatForParsing}${splitDelimiter}`,
revisionRange,
]);
/** A set of the commits in the provided range. */
const commits = new Map<string, CommitFromGitLog>();

return output.stdout
output.stdout
.split(splitDelimiter)
.filter((entry) => !!entry.trim())
.map(santizeCommitMessage)
.map((entry) => parseCommitFromGitLog(Buffer.from(entry, 'utf-8')));
// Reverse the list of commits so that we encounter original commits before revert commits.
.reverse()
.forEach((entry) => {
if (entry.trim() === '') {
return;
}
const commit = parseCommitFromGitLog(Buffer.from(santizeCommitMessage(entry), 'utf-8'));
if (commit.isRevert) {
commits.delete(commit.originalHeader.match(/^revert:? "(.*)"/i)?.[1] || '');
} else {
commits.set(commit.header, commit);
}
});

// We return an array of the commits, Map preserves the instert order of the values in the Map. The
// order is reversed to get back to the expected order.
return Array.from(commits.values()).reverse();
}

/**
Expand Down
Loading