ci: Modify immutable commit subject via spreading (#27467)

This commit is contained in:
Matsu 2026-03-24 08:37:24 +02:00 committed by GitHub
parent 61a526133d
commit bf856cd442
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,5 @@
import createTempFile from 'tempfile';
import { ConventionalChangelog, packagePrefix } from 'conventional-changelog';
import { ConventionalChangelog } from 'conventional-changelog';
import { resolve } from 'path';
import { createReadStream, createWriteStream } from 'fs';
import { dirname } from 'path';
@ -35,7 +35,15 @@ const changelogStream = new ConventionalChangelog()
// Strip backport information from commit subject, e.g.:
// "Fix something (backport to release-candidate/2.12.x) (#123)" → "Fix something (#123)"
if (commit.subject) {
commit.subject = commit.subject.replace(/\s*\(backport to [^)]+\)/g, '');
// The commit.subject is immutable so we need to recreate the commit object
/** @type { import("conventional-changelog").Commit } */
let newCommit = /** @type { any } */ ({
...commit,
subject: commit.subject.replace(/\s*\(backport to [^)]+\)/g, ''),
});
return newCommit;
}
return commit;