From 21251523975297b0a491a6328e423e857e371cb9 Mon Sep 17 00:00:00 2001
From: Dmitry Dobrynin
Date: Sun, 6 Apr 2025 02:07:28 +0200
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20--only-stable=20option=20to?=
=?UTF-8?q?=20include=20only=20stable=20versions?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/gitmoji-changelog-cli/src/index.js | 1 +
packages/gitmoji-changelog-core/src/index.js | 8 ++++--
.../gitmoji-changelog-core/src/index.spec.js | 26 +++++++++++++++++++
.../gitmoji-changelog-documentation/README.md | 1 +
4 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/packages/gitmoji-changelog-cli/src/index.js b/packages/gitmoji-changelog-cli/src/index.js
index a51b5d8..178f37a 100755
--- a/packages/gitmoji-changelog-cli/src/index.js
+++ b/packages/gitmoji-changelog-cli/src/index.js
@@ -52,6 +52,7 @@ yargs
.option('group-similar-commits', { desc: '[⚗️ - beta] try to group similar commits', default: false })
.option('author', { default: false, desc: 'add the author in changelog lines' })
.option('interactive', { default: false, desc: 'select commits manually', alias: 'i' })
+ .option('only-stable', { default: false, desc: 'Include only stable versions when generating the changelog', type: 'boolean' })
.help('help')
.epilog(`For more information visit: ${homepage}`)
diff --git a/packages/gitmoji-changelog-core/src/index.js b/packages/gitmoji-changelog-core/src/index.js
index 8143a40..a83814f 100644
--- a/packages/gitmoji-changelog-core/src/index.js
+++ b/packages/gitmoji-changelog-core/src/index.js
@@ -126,9 +126,13 @@ async function generateVersions({
}
async function generateChangelog(from, to, {
- groupSimilarCommits, client = fromGitFileClient,
+ groupSimilarCommits, onlyStable, client = fromGitFileClient,
} = {}) {
- const gitTags = await client.getTags()
+ let gitTags = await client.getTags()
+ if (onlyStable) {
+ gitTags = gitTags.filter((tag) => !/(dev|rc|alpha|beta)/i.test(tag))
+ }
+
let tagsToProcess = [...gitTags]
const hasNext = hasNextVersion(gitTags, to)
diff --git a/packages/gitmoji-changelog-core/src/index.spec.js b/packages/gitmoji-changelog-core/src/index.spec.js
index d71b6cb..826c9e4 100644
--- a/packages/gitmoji-changelog-core/src/index.spec.js
+++ b/packages/gitmoji-changelog-core/src/index.spec.js
@@ -362,6 +362,32 @@ describe('changelog', () => {
{ date: '2019-02-01T00:00:00+00:00', body: '9' },
])
})
+
+ it('should include unstable commits', async () => {
+ mockGroup([recycleCommit])
+ mockGroup([lipstickCommit])
+ mockGroup([sparklesCommit])
+ mockGroup([lockCommit])
+
+ gitSemverTags.mockImplementation(cb => cb(null, ['v1.0.0', 'v1.0.0-dev.1', 'v1.0.1']))
+
+ const { changes } = await generateChangelog(TAIL, HEAD, { onlyStable: false })
+
+ expect(changes).toHaveLength(4)
+ })
+
+ it('should exclude unstable commits', async () => {
+ mockGroup([recycleCommit])
+ mockGroup([lipstickCommit])
+ mockGroup([sparklesCommit])
+ mockGroup([lockCommit])
+
+ gitSemverTags.mockImplementation(cb => cb(null, ['v1.0.0', 'v1.0.0-dev.1', 'v1.0.1']))
+
+ const { changes } = await generateChangelog(TAIL, HEAD, { onlyStable: true })
+
+ expect(changes).toHaveLength(3)
+ })
})
jest.mock('git-raw-commits')
diff --git a/packages/gitmoji-changelog-documentation/README.md b/packages/gitmoji-changelog-documentation/README.md
index 39f035e..6830359 100644
--- a/packages/gitmoji-changelog-documentation/README.md
+++ b/packages/gitmoji-changelog-documentation/README.md
@@ -62,6 +62,7 @@ The first command listed above is the idiomatic usage of `gitmoji-changelog` (re
| --group-similar-commits | [⚗️,- beta] try to group similar commits | false |
| --author | add the author in changelog lines | false |
| --interactive -i | select commits manually | false |
+| --only-stable | Include only stable versions when generating the changelog | false |
| --help | display help | |
### Example