Repository: nodejs/node
Pull request: tools: add semver-major release support to release-lint

Supersedes https://github.com/nodejs/node/pull/57827
<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: tools/actions/lint-release-proposal-commit-list.mjs
patch: @@ -19,14 +19,24 @@ const stdinLineByLine = createInterface(process.stdin)[Symbol.asyncIterator]();
 
 const changelog = await readFile(CHANGELOG_PATH, 'utf-8');
 const commitListingStart = changelog.indexOf('\n### Commits\n');
-const commitListingEnd = changelog.indexOf('\n\n<a', commitListingStart);
-const commitList = changelog.slice(commitListingStart, commitListingEnd === -1 ? undefined : commitListingEnd + 1)
-  // Checking for semverness is too expansive, it is left as a exercice for human reviewers.
+let commitList;
+if (commitListingStart === -1) {
+  // We're preparing a semver-major release.
+  commitList = changelog.replace(/(^.+\n### Semver-Major|\n### Semver-(Minor|Patch)) Commits\n/gs, '')
+    .replaceAll('**(SEMVER-MAJOR)** ', '');
+} else {
+  const commitListingEnd = changelog.indexOf('\n\n<a', commitListingStart);
+  assert.notStrictEqual(commitListingEnd, -1);
+  commitList = changelog.slice(commitListingStart, commitListingEnd + 1);
+}
+
+// Normalize for consistent comparison
+commitList = commitList
   .replaceAll('**(SEMVER-MINOR)** ', '')
-  // Correct Markdown escaping is validated by the linter, getting rid of it here helps.
   .replaceAll('\\', '');
 
-let expectedNumberOfCommitsLeft = commitList.match(/\n\* \[/g).length;
+let expectedNumberOfCommitsLeft = commitList.match(/\n\* \[/g)?.length ?? 0;
+
 for await (const line of stdinLineByLine) {
   const { smallSha, title, prURL } = JSON.parse(line);