Skip to content

Commit

Permalink
feat(commits.js): added niceDate format of commits (#206)
Browse files Browse the repository at this point in the history
* feat(commits.js): added niceDate format of commits

* Tweak niceDate logic

* Update test data

Co-authored-by: Pete Cook <[email protected]>
  • Loading branch information
thkruz and cookpete authored Feb 3, 2022
1 parent dbd36d5 commit 73a2524
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/commits.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const semver = require('semver')
const { cmd, isLink, encodeHTML, replaceText, getGitVersion } = require('./utils')
const { cmd, isLink, encodeHTML, niceDate, replaceText, getGitVersion } = require('./utils')

const COMMIT_SEPARATOR = '__AUTO_CHANGELOG_COMMIT_SEPARATOR__'
const MESSAGE_SEPARATOR = '__AUTO_CHANGELOG_MESSAGE_SEPARATOR__'
Expand Down Expand Up @@ -48,6 +48,7 @@ const parseCommit = (commit, options = {}) => {
author,
email,
date: new Date(date).toISOString(),
niceDate: niceDate(date),
subject: replaceText(getSubject(message), options),
message: message.trim(),
fixes: getFixes(message, author, options),
Expand Down
17 changes: 17 additions & 0 deletions test/data/commits-no-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:57:19.000Z",
"niceDate": "29 December 2015",
"subject": "Unreleased commit",
"message": "Unreleased commit\n\nFixes #6",
"fixes": [
Expand All @@ -27,6 +28,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T12:03:09.000Z",
"niceDate": "15 December 2015",
"subject": "1.0.0",
"message": "1.0.0\n\nThis is my major release description.\n\n- And a bullet point",
"fixes": null,
Expand All @@ -43,6 +45,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:57:19.000Z",
"niceDate": "29 December 2015",
"subject": "Some breaking change",
"message": "Some breaking change",
"fixes": null,
Expand All @@ -59,6 +62,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:19:17.000Z",
"niceDate": "29 December 2015",
"subject": "0.1.0",
"message": "0.1.0",
"fixes": null,
Expand All @@ -75,6 +79,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:19:19.000Z",
"niceDate": "29 December 2015",
"subject": "Another commit that fixes nothing but with less changes",
"message": "Another commit that fixes nothing but with less changes",
"fixes": null,
Expand All @@ -91,6 +96,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:18:19.000Z",
"niceDate": "29 December 2015",
"subject": "Commit that fixes nothing with `backticks` and &lt;html&gt;",
"message": "Commit that fixes nothing with `backticks` and &lt;html&gt;",
"fixes": null,
Expand All @@ -107,6 +113,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-28T21:17:17.000Z",
"niceDate": "28 December 2015",
"subject": "0.0.2",
"message": "0.0.2",
"fixes": null,
Expand All @@ -123,6 +130,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-24T20:29:22.000Z",
"niceDate": "24 December 2015",
"subject": "Merge pull request #5 from repo/branch",
"message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title",
"fixes": null,
Expand All @@ -139,6 +147,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-24T20:29:22.000Z",
"niceDate": "24 December 2015",
"subject": "Merge pull request #5 from repo/branch",
"message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title",
"fixes": null,
Expand All @@ -153,6 +162,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T11:35:54.000Z",
"niceDate": "29 December 2015",
"subject": "Merge remote-tracking branch 'random-branch' into master",
"message": "Merge remote-tracking branch 'random-branch' into master",
"fixes": null,
Expand All @@ -169,6 +179,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-28T11:35:54.000Z",
"niceDate": "28 December 2015",
"subject": "Commit 4 fixes #4 in the subject",
"message": "Commit 4 fixes #4 in the subject\n\nWith some extra notes here",
"fixes": [
Expand All @@ -191,6 +202,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T12:03:09.000Z",
"niceDate": "15 December 2015",
"subject": "0.0.1",
"message": "0.0.1",
"fixes": null,
Expand All @@ -207,6 +219,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T11:37:05.000Z",
"niceDate": "15 December 2015",
"subject": "Merge pull request #3 from repo/branch",
"message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR",
"fixes": null,
Expand All @@ -223,6 +236,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T11:37:05.000Z",
"niceDate": "15 December 2015",
"subject": "Merge pull request #3 from repo/branch",
"message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR",
"fixes": null,
Expand All @@ -237,6 +251,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T11:31:06.000Z",
"niceDate": "15 December 2015",
"subject": "Third commit with same name as PR",
"message": "Third commit with same name as PR",
"fixes": null,
Expand All @@ -253,6 +268,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T11:31:06.000Z",
"niceDate": "15 December 2015",
"subject": "Second commit",
"message": "Second commit\n\nResolves #1 and fixes https://github.com/user/repo/issues/2",
"fixes": [
Expand Down Expand Up @@ -280,6 +296,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-14T17:06:12.000Z",
"niceDate": "14 December 2015",
"subject": "First commit",
"message": "First commit",
"fixes": null,
Expand Down
17 changes: 17 additions & 0 deletions test/data/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:57:19.000Z",
"niceDate": "29 December 2015",
"subject": "Unreleased commit",
"message": "Unreleased commit\n\nFixes #6",
"fixes": [
Expand All @@ -27,6 +28,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T12:03:09.000Z",
"niceDate": "15 December 2015",
"subject": "1.0.0",
"message": "1.0.0\n\nThis is my major release description.\n\n- And a bullet point",
"fixes": null,
Expand All @@ -43,6 +45,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:57:19.000Z",
"niceDate": "29 December 2015",
"subject": "Some breaking change",
"message": "Some breaking change",
"fixes": null,
Expand All @@ -59,6 +62,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:19:17.000Z",
"niceDate": "29 December 2015",
"subject": "0.1.0",
"message": "0.1.0",
"fixes": null,
Expand All @@ -75,6 +79,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:19:19.000Z",
"niceDate": "29 December 2015",
"subject": "Another commit that fixes nothing but with less changes",
"message": "Another commit that fixes nothing but with less changes",
"fixes": null,
Expand All @@ -91,6 +96,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T21:18:19.000Z",
"niceDate": "29 December 2015",
"subject": "Commit that fixes nothing with `backticks` and &lt;html&gt;",
"message": "Commit that fixes nothing with `backticks` and &lt;html&gt;",
"fixes": null,
Expand All @@ -107,6 +113,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-28T21:17:17.000Z",
"niceDate": "28 December 2015",
"subject": "0.0.2",
"message": "0.0.2",
"fixes": null,
Expand All @@ -123,6 +130,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-24T20:29:22.000Z",
"niceDate": "24 December 2015",
"subject": "Merge pull request #5 from repo/branch",
"message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title",
"fixes": null,
Expand All @@ -139,6 +147,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-24T20:29:22.000Z",
"niceDate": "24 December 2015",
"subject": "Merge pull request #5 from repo/branch",
"message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title",
"fixes": null,
Expand All @@ -153,6 +162,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-29T11:35:54.000Z",
"niceDate": "29 December 2015",
"subject": "Merge remote-tracking branch 'random-branch' into master",
"message": "Merge remote-tracking branch 'random-branch' into master",
"fixes": null,
Expand All @@ -169,6 +179,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-28T11:35:54.000Z",
"niceDate": "28 December 2015",
"subject": "Commit 4 fixes #4 in the subject",
"message": "Commit 4 fixes #4 in the subject\n\nWith some extra notes here",
"fixes": [
Expand All @@ -191,6 +202,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T12:03:09.000Z",
"niceDate": "15 December 2015",
"subject": "0.0.1",
"message": "0.0.1",
"fixes": null,
Expand All @@ -207,6 +219,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T11:37:05.000Z",
"niceDate": "15 December 2015",
"subject": "Merge pull request #3 from repo/branch",
"message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR",
"fixes": null,
Expand All @@ -223,6 +236,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T11:37:05.000Z",
"niceDate": "15 December 2015",
"subject": "Merge pull request #3 from repo/branch",
"message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR",
"fixes": null,
Expand All @@ -237,6 +251,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T11:31:06.000Z",
"niceDate": "15 December 2015",
"subject": "Third commit with same name as PR",
"message": "Third commit with same name as PR",
"fixes": null,
Expand All @@ -253,6 +268,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-15T11:31:06.000Z",
"niceDate": "15 December 2015",
"subject": "Second commit",
"message": "Second commit\n\nResolves #1 and fixes https://github.com/user/repo/issues/2",
"fixes": [
Expand Down Expand Up @@ -280,6 +296,7 @@ module.exports = [
"author": "Example Author",
"email": "[email protected]",
"date": "2015-12-14T17:06:12.000Z",
"niceDate": "14 December 2015",
"subject": "First commit",
"message": "First commit",
"fixes": null,
Expand Down

0 comments on commit 73a2524

Please sign in to comment.