diff --git a/README.md b/README.md index ba250ef..d189e6b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,14 @@ or `yarn run auto-changelog update --useShortPrLink` +#### Require PR numbers (filter out commits without PR numbers) + +- Only include commits that have associated PR numbers in the changelog +- Commits without PR numbers (like direct commits) will be filtered out +- This is useful for projects that want to ensure all changelog entries come from reviewed pull requests + +`yarn run auto-changelog update --requirePrNumbers` + #### Update the current release section of the changelog `yarn run auto-changelog update --rc` @@ -50,6 +58,10 @@ or `yarn run auto-changelog update --autoCategorize --useChangelogEntry --useShortPrLink --rc` +### With requirePrNumbers (for stricter PR-based workflows) + +`yarn run auto-changelog update --autoCategorize --useChangelogEntry --useShortPrLink --requirePrNumbers --rc` + #### Update the changelog for a renamed package This option is designed to be used for packages that live in a monorepo. @@ -132,6 +144,7 @@ const updatedChangelog = await updateChangelog({ currentVersion: '1.0.0', repoUrl: 'https://github.com/ExampleUsernameOrOrganization/ExampleRepository', isReleaseCandidate: false, + requirePrNumbers: false, // Optional: set to true to filter out commits without PR numbers }); await fs.writeFile('CHANGELOG.md', updatedChangelog); ``` diff --git a/src/cli.ts b/src/cli.ts index 209627a..86ce259 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -102,6 +102,10 @@ type UpdateOptions = { * Whether to use short PR links in the changelog entries */ useShortPrLink: boolean; + /** + * Whether to require PR numbers for all commits. If true, commits without PR numbers are filtered out. + */ + requirePrNumbers: boolean; }; /** @@ -121,6 +125,7 @@ type UpdateOptions = { * @param options.autoCategorize - Whether to categorize commits automatically based on their messages. * @param options.useChangelogEntry - Whether to read `CHANGELOG entry:` from the commit body and the no-changelog label. * @param options.useShortPrLink - Whether to use short PR links in the changelog entries. + * @param options.requirePrNumbers - Whether to require PR numbers for all commits. If true, commits without PR numbers are filtered out. */ async function update({ changelogPath, @@ -134,6 +139,7 @@ async function update({ autoCategorize, useChangelogEntry, useShortPrLink, + requirePrNumbers, }: UpdateOptions) { const changelogContent = await readChangelog(changelogPath); @@ -149,6 +155,7 @@ async function update({ autoCategorize, useChangelogEntry, useShortPrLink, + requirePrNumbers, }); if (newChangelogContent) { @@ -357,6 +364,12 @@ async function main() { description: 'Use short PR links in the changelog entries', type: 'boolean', }) + .option('requirePrNumbers', { + default: false, + description: + 'Only include commits with PR numbers in the changelog. Commits without PR numbers will be filtered out', + type: 'boolean', + }) .epilog(updateEpilog), ) .command( @@ -416,6 +429,7 @@ async function main() { prLinks, useChangelogEntry, useShortPrLink, + requirePrNumbers, } = argv; let { currentVersion } = argv; @@ -547,6 +561,7 @@ async function main() { autoCategorize, useChangelogEntry: Boolean(useChangelogEntry), useShortPrLink: Boolean(useShortPrLink), + requirePrNumbers: Boolean(requirePrNumbers), }); } else if (command === 'validate') { let packageRename: PackageRename | undefined; diff --git a/src/get-new-changes.ts b/src/get-new-changes.ts index 72fe79e..f674e8a 100644 --- a/src/get-new-changes.ts +++ b/src/get-new-changes.ts @@ -14,6 +14,7 @@ export type AddNewCommitsOptions = { projectRootDirectory?: string; useChangelogEntry: boolean; useShortPrLink: boolean; + requirePrNumbers?: boolean; }; // Get array of all ConventionalCommitType values @@ -61,6 +62,22 @@ function removeConventionalCommitPrefixIfPresent(message: string) { return message.replace(regex, ''); } +/** + * Remove HTML comments from the given message. + * Handles both complete comments () and unclosed comments () + let result = message.replace(//gu, ''); + // Remove unclosed HTML comments () + result = result.replace(/