From a6b35fae5ee5d2389b96f4085c8893d16952b1d0 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sun, 28 Feb 2021 12:44:17 +0900 Subject: [PATCH 01/11] add --sort-tags --- src/run.js | 2 ++ src/tags.js | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/run.js b/src/run.js index 27008a46..ff3bd598 100644 --- a/src/run.js +++ b/src/run.js @@ -13,6 +13,7 @@ const DEFAULT_OPTIONS = { commitLimit: 3, backfillLimit: 3, tagPrefix: '', + sortTags: 'semver', sortCommits: 'relevance', appendGitLog: '', config: '.auto-changelog' @@ -43,6 +44,7 @@ const getOptions = async argv => { .option('--ignore-commit-pattern ', 'pattern to ignore when parsing commits') .option('--tag-pattern ', 'override regex pattern for version tags') .option('--tag-prefix ', 'prefix used in version tags') + .option('--sort-tags ', `sort commits by property 'semver' or git fields, default: ${DEFAULT_OPTIONS.sortTags}`) .option('--starting-version ', 'specify earliest version to include in changelog') .option('--sort-commits ', `sort commits by property [relevance, date, date-desc], default: ${DEFAULT_OPTIONS.sortCommits}`) .option('--release-summary', 'use tagged commit message body as release summary') diff --git a/src/tags.js b/src/tags.js index fc3db039..3add9410 100644 --- a/src/tags.js +++ b/src/tags.js @@ -6,12 +6,21 @@ const MATCH_V = /^v\d/ const fetchTags = async (options, remote) => { const format = `%(refname:short)${DIVIDER}%(creatordate:short)` - const tags = (await cmd(`git tag -l --sort=-creatordate --format=${format}`)) - .trim() - .split('\n') - .map(parseTag(options)) - .filter(isValidTag(options)) - .sort(sortTags(options)) + let tags; + if (options.sortTags === "semver") { + tags = (await cmd(`git tag -l --sort=-creatordate --format=${format}`)) + .trim() + .split('\n') + .map(parseTag(options)) + .filter(isValidTag(options)) + .sort(sortTags(options)) + } else { + tags = (await cmd(`git tag -l --sort=${options.sortTags} --format=${format}`)) + .trim() + .split('\n') + .map(parseTag(options)) + .filter(isValidTag(options)) + } const { latestVersion, unreleased, unreleasedOnly, getCompareLink } = options if (latestVersion || unreleased || unreleasedOnly) { From 66cb417d8664a5346f6e1bb651b7372610d8f374 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 14 Jun 2021 12:04:58 +0900 Subject: [PATCH 02/11] fix merge --- src/tags.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tags.js b/src/tags.js index adf071db..1392ea70 100644 --- a/src/tags.js +++ b/src/tags.js @@ -20,7 +20,7 @@ const fetchTags = async (options, remote) => { .split('\n') .map(parseTag(options)) .filter(isValidTag(options)) - } master + } const { latestVersion, unreleased, unreleasedOnly, getCompareLink } = options if (latestVersion || unreleased || unreleasedOnly) { From 532441bc682504e140a705b75e55b98dc2dee5a6 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 14 Jun 2021 12:14:44 +0900 Subject: [PATCH 03/11] fix test/tags.js --- test/tags.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/tags.js b/test/tags.js index 5218bd52..2a5c20dd 100644 --- a/test/tags.js +++ b/test/tags.js @@ -9,6 +9,7 @@ const { const options = { tagPrefix: '', + sortTags: 'semver' ...remotes.github } From 576583ae9c4d4f78305715c4b102f311f168a200 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 14 Jun 2021 12:17:45 +0900 Subject: [PATCH 04/11] fix test/tags.js --- test/tags.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tags.js b/test/tags.js index 2a5c20dd..ccd361eb 100644 --- a/test/tags.js +++ b/test/tags.js @@ -9,7 +9,7 @@ const { const options = { tagPrefix: '', - sortTags: 'semver' + sortTags: 'semver', ...remotes.github } From 56a1612a7567d33d89aeb3978ef6d4c0e8eaae9c Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 14 Jun 2021 12:22:09 +0900 Subject: [PATCH 05/11] fix merge --- src/tags.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tags.js b/src/tags.js index 1392ea70..7bb0c690 100644 --- a/src/tags.js +++ b/src/tags.js @@ -13,7 +13,7 @@ const fetchTags = async (options, remote) => { .split('\n') .map(parseTag(options)) .filter(isValidTag(options)) - .sort(sortTags(options)) + .sort(sortTags) } else { tags = (await cmd(`git tag -l --sort=${options.sortTags} --format=${format} ${options.appendGitTag}`)) .trim() From 3beba01347526468e61ff31bfd5dd647bea2d022 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 14 Jun 2021 17:28:56 +0900 Subject: [PATCH 06/11] fix style --- src/tags.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tags.js b/src/tags.js index 7bb0c690..96cb2eca 100644 --- a/src/tags.js +++ b/src/tags.js @@ -6,8 +6,8 @@ const MATCH_V = /^v\d/ const fetchTags = async (options, remote) => { const format = `%(refname:short)${DIVIDER}%(creatordate:short)` - let tags; - if (options.sortTags === "semver") { + let tags + if (options.sortTags === 'semver') { tags = (await cmd(`git tag -l --format=${format} ${options.appendGitTag}`)) .trim() .split('\n') From bb99e60f1cf2542cef4909661a225600419d63c5 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 14 Jun 2021 17:35:55 +0900 Subject: [PATCH 07/11] add test for --sort-tags --- test/tags.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/tags.js b/test/tags.js index ccd361eb..084d20ca 100644 --- a/test/tags.js +++ b/test/tags.js @@ -114,6 +114,19 @@ describe('fetchTags', () => { expect(await fetchTags({ ...options, startingDate: '2000-05-01' })).to.have.lengthOf(1) }) + // with --sort-tags, we shouldn't sort by semver, keep git command's order. + it('supports --sort-tags', async () => { + const tags = await fetchTags({ ...options, sortTags: 'something' }) + expect(tags.map(t => t.version)).to.deep.equal([ + 'v0.1.0', + 'v0.2.0', + 'v0.2.1', + 'v0.2.2', + 'v0.3.0', + 'v1.0.0' + ]) + }) + it('supports partial semver tags', async () => { mock('cmd', () => Promise.resolve([ 'v0.1---2000-02-01', From bf017e6235d8e6219943dc81f4fe77bbec0e831c Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 14 Jun 2021 17:40:38 +0900 Subject: [PATCH 08/11] fix help message for --sort-tags --- src/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run.js b/src/run.js index c321cac2..c3487a15 100644 --- a/src/run.js +++ b/src/run.js @@ -45,7 +45,7 @@ const getOptions = async argv => { .option('--ignore-commit-pattern ', 'pattern to ignore when parsing commits') .option('--tag-pattern ', 'override regex pattern for version tags') .option('--tag-prefix ', 'prefix used in version tags') - .option('--sort-tags ', `sort commits by property 'semver' or git fields, default: ${DEFAULT_OPTIONS.sortTags}`) + .option('--sort-tags ', `sort commits by semantic versioning or git fields, default: ${DEFAULT_OPTIONS.sortTags}`) .option('--starting-version ', 'specify earliest version to include in changelog') .option('--starting-date ', 'specify earliest date to include in changelog') .option('--sort-commits ', `sort commits by property [relevance, date, date-desc], default: ${DEFAULT_OPTIONS.sortCommits}`) From 1e0b38c9b99797303e3b068ee1d9ccdd8783b38a Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 14 Jun 2021 17:42:46 +0900 Subject: [PATCH 09/11] add --sort-tags to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bd72db6f..c9cca8f2 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Options: --ignore-commit-pattern [regex] # pattern to ignore when parsing commits --tag-pattern [regex] # override regex pattern for version tags --tag-prefix [prefix] # prefix used in version tags, default: v + --sort-tags [property] # sort commits by semantic versioning or git fields, default: semver --starting-version [tag] # specify earliest version to include in changelog --starting-date [yyyy-mm-dd] # specify earliest date to include in changelog --sort-commits [property] # sort commits by property [relevance, date, date-desc, subject, subject-desc], default: relevance From f507ed867f09fa17c54c2e9e1996e4f5a8cf338e Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 15 Jun 2021 20:34:01 +0900 Subject: [PATCH 10/11] fix test for --sort-tags --- test/tags.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/tags.js b/test/tags.js index 084d20ca..eb939143 100644 --- a/test/tags.js +++ b/test/tags.js @@ -116,14 +116,22 @@ describe('fetchTags', () => { // with --sort-tags, we shouldn't sort by semver, keep git command's order. it('supports --sort-tags', async () => { - const tags = await fetchTags({ ...options, sortTags: 'something' }) + mock('cmd', () => Promise.resolve([ + 'v0.1.0---2000-02-01', + 'v0.2.0---2000-03-01', + 'v0.2.1---2000-03-02', + 'v1.0.0---2000-03-03', + 'v0.2.2---2000-04-01', + 'v0.3.0---2001-01-01' + ].join('\n'))) + const tags = await fetchTags({ ...options, sortTags: 'creatordate' }) expect(tags.map(t => t.version)).to.deep.equal([ 'v0.1.0', 'v0.2.0', 'v0.2.1', + 'v1.0.0', 'v0.2.2', - 'v0.3.0', - 'v1.0.0' + 'v0.3.0' ]) }) From 42367285df9ea049ac55b14f5d230ed8633c878a Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 15 Jun 2021 20:37:03 +0900 Subject: [PATCH 11/11] add test --sort-tags=semver --- test/tags.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/tags.js b/test/tags.js index eb939143..69f48047 100644 --- a/test/tags.js +++ b/test/tags.js @@ -114,6 +114,18 @@ describe('fetchTags', () => { expect(await fetchTags({ ...options, startingDate: '2000-05-01' })).to.have.lengthOf(1) }) + it('supports --sort-tags=semver', async () => { + const tags = await fetchTags({ ...options, sortTags: 'semver' }) + expect(tags.map(t => t.version)).to.deep.equal([ + 'v1.0.0', + 'v0.3.0', + 'v0.2.2', + 'v0.2.1', + 'v0.2.0', + 'v0.1.0' + ]) + }) + // with --sort-tags, we shouldn't sort by semver, keep git command's order. it('supports --sort-tags', async () => { mock('cmd', () => Promise.resolve([