Skip to content

Commit b14d0b0

Browse files
committed
fix(ng-dev): properly remove reverted commits during release note generation
When we are compiling the list of the commits that should be included for release notes, we now remove the commits which have been identified as reverted based on later commits in the release commmits range.
1 parent 4913e6e commit b14d0b0

File tree

4 files changed

+48
-32
lines changed

4 files changed

+48
-32
lines changed

.github/local-actions/branch-manager/main.js

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

github-actions/pull-request-labeling/main.js

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

ng-dev/commit-message/parse.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export interface Commit {
1919
fullText: string;
2020
/** The header line of the commit, will be used in the changelog entries. */
2121
header: string;
22+
/** The original header line of the commit, before stripping away fixup, squash, etc. */
23+
originalHeader: string;
2224
/** The full body of the commit, not including the footer. */
2325
body: string;
2426
/** The footer of the commit, containing issue references and note sections. */
@@ -114,8 +116,8 @@ const parseOptions: ParserOptions = {
114116
noteKeywords: [NoteSections.BREAKING_CHANGE, NoteSections.DEPRECATED],
115117
notesPattern: (keywords: string) => new RegExp(`^\\s*(${keywords}): ?(.*)`),
116118
};
117-
118-
let commitParser: CommitParser | undefined;
119+
/** Instance of the commit parser to parse raw commits. */
120+
const commitParser = new CommitParser(parseOptions);
119121

120122
/** Parse a commit message into its composite parts. */
121123
export const parseCommitMessage: (fullText: string) => Commit = parseInternal;
@@ -128,21 +130,18 @@ function parseInternal(fullText: string): Commit;
128130
function parseInternal(fullText: Buffer): CommitFromGitLog;
129131
function parseInternal(fullText: string | Buffer): CommitFromGitLog | Commit {
130132
// Ensure the fullText symbol is a `string`, even if a Buffer was provided.
131-
fullText = fullText.toString();
132-
/** The commit message text with the fixup and squash markers stripped out. */
133-
const strippedCommitMsg = fullText
134-
.replace(FIXUP_PREFIX_RE, '')
135-
.replace(SQUASH_PREFIX_RE, '')
136-
.replace(REVERT_PREFIX_RE, '');
137-
138-
commitParser ??= new CommitParser(parseOptions);
139-
133+
fullText = fullText.toString().trim();
140134
/** The initially parsed commit. */
141-
const commit = commitParser.parse(strippedCommitMsg);
135+
const commit = commitParser.parse(fullText);
142136
/** A list of breaking change notes from the commit. */
143137
const breakingChanges: CommitNote[] = [];
144138
/** A list of deprecation notes from the commit. */
145139
const deprecations: CommitNote[] = [];
140+
/** The extracted header after stripping away fixup, squash, etc. */
141+
const header = (commit.header || '')
142+
.replace(FIXUP_PREFIX_RE, '')
143+
.replace(SQUASH_PREFIX_RE, '')
144+
.replace(REVERT_PREFIX_RE, '');
146145

147146
// Extract the commit message notes by marked types into their respective lists.
148147
for (const note of commit.notes) {
@@ -160,9 +159,10 @@ function parseInternal(fullText: string | Buffer): CommitFromGitLog | Commit {
160159
fullText,
161160
breakingChanges,
162161
deprecations,
162+
header,
163163
body: commit.body || '',
164164
footer: commit.footer || '',
165-
header: commit.header || '',
165+
originalHeader: commit.header || '',
166166
references: commit.references,
167167
scope: commit['scope'] || '',
168168
subject: commit['subject'] || '',

ng-dev/release/notes/commits/get-commits-in-range.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function getCommitsForRangeWithDeduping(
7575
}
7676

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

89-
return output.stdout
91+
output.stdout
9092
.split(splitDelimiter)
91-
.filter((entry) => !!entry.trim())
92-
.map(santizeCommitMessage)
93-
.map((entry) => parseCommitFromGitLog(Buffer.from(entry, 'utf-8')));
93+
// Reverse the list of commits so that we encounter original commits before revert commits.
94+
.reverse()
95+
.forEach((entry) => {
96+
if (entry.trim() === '') {
97+
return;
98+
}
99+
const commit = parseCommitFromGitLog(Buffer.from(santizeCommitMessage(entry), 'utf-8'));
100+
if (commit.isRevert) {
101+
commits.delete(commit.originalHeader.match(/^revert:? "(.*)"/i)?.[1] || '');
102+
} else {
103+
commits.set(commit.header, commit);
104+
}
105+
});
106+
107+
// We return an array of the commits, Map preserves the instert order of the values in the Map. The
108+
// order is reversed to get back to the expected order.
109+
return Array.from(commits.values()).reverse();
94110
}
95111

96112
/**

0 commit comments

Comments
 (0)