Skip to content

Commit 3072a7a

Browse files
a-ignatov-parccookpete
authored andcommitted
Added support for old git versions (#35)
1 parent f62c1a1 commit 3072a7a

8 files changed

+85
-76
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ You can also set any option in `package.json` under the `auto-changelog` key, us
9494

9595
#### Requirements
9696

97-
`auto-changelog` is designed to be as flexible as possible, providing a clear changelog for any project. The only absolute requirement is that all versions are tagged using [semver](https://semver.org) tag names. This happens by default when using [`npm version`](https://docs.npmjs.com/cli/version).
97+
`auto-changelog` is designed to be as flexible as possible, providing a clear changelog for any project. There are only two absolute requirements:
98+
99+
- You should be using git `1.7.2` or later
100+
- All versions should be tagged using [semver](https://semver.org) tag names – this happens by default when using [`npm version`](https://docs.npmjs.com/cli/version)
98101

99102
There are some less strict requirements to improve your changelog:
100103

scripts/generate-test-data.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ const remote = {
1414
url: 'https://github.com/user/repo'
1515
}
1616

17+
const options = {
18+
unreleased: false,
19+
commitLimit: 3,
20+
tagPrefix: ''
21+
}
22+
1723
async function run () {
1824
const gitLog = await readFile(join(DATA_DIR, 'git-log.txt'), 'utf-8')
19-
const commits = parseCommits(gitLog, remote, { tagPrefix: '' })
20-
const releases = parseReleases(commits, remote, null, { unreleased: false, commitLimit: 3 })
25+
const commits = parseCommits(gitLog, remote, options)
26+
const releases = parseReleases(commits, remote, null, options)
2127
await writeFile(join(DATA_DIR, 'commits.js'), 'export default ' + JSON.stringify(commits, null, 2))
2228
await writeFile(join(DATA_DIR, 'commits-no-remote.js'), 'export default ' + JSON.stringify(commitsWithoutLinks(commits), null, 2))
2329
await writeFile(join(DATA_DIR, 'releases.js'), 'export default ' + JSON.stringify(releases, null, 2))

src/commits.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { cmd, isLink } from './utils'
44

55
const COMMIT_SEPARATOR = '__AUTO_CHANGELOG_COMMIT_SEPARATOR__'
66
const MESSAGE_SEPARATOR = '__AUTO_CHANGELOG_MESSAGE_SEPARATOR__'
7-
const LOG_FORMAT = COMMIT_SEPARATOR + '%H%n%D%n%aI%n%an%n%ae%n%B' + MESSAGE_SEPARATOR
8-
const MATCH_COMMIT = /(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n([\S\s]+)/
7+
const LOG_FORMAT = COMMIT_SEPARATOR + '%H%n%d%n%ai%n%an%n%ae%n%B' + MESSAGE_SEPARATOR
8+
const MATCH_COMMIT = /(.*)\n(?:\s\((.*)\))?\n(.*)\n(.*)\n(.*)\n([\S\s]+)/
99
const MATCH_STATS = /(\d+) files? changed(?:, (\d+) insertions?...)?(?:, (\d+) deletions?...)?/
1010

1111
// https://help.github.com/articles/closing-issues-via-commit-messages
@@ -54,7 +54,7 @@ function parseCommit (commit, remote, options = {}) {
5454
shorthash: hash.slice(0, 7),
5555
author,
5656
email,
57-
date,
57+
date: new Date(date).toISOString(),
5858
tag: getTag(refs, options),
5959
subject: getSubject(message),
6060
message: message.trim(),

test/data/commits-no-remote.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default [
44
"shorthash": "b0b3040",
55
"author": "Pete Cook",
66
"email": "email@example.com",
7-
"date": "2015-12-29T21:57:19+00:00",
7+
"date": "2015-12-29T21:57:19.000Z",
88
"tag": null,
99
"subject": "Unreleased commit",
1010
"message": "Unreleased commit\n\nFixes #6",
@@ -25,7 +25,7 @@ export default [
2525
"shorthash": "b0b3040",
2626
"author": "Pete Cook",
2727
"email": "email@example.com",
28-
"date": "2015-12-15T12:03:09+00:00",
28+
"date": "2015-12-15T12:03:09.000Z",
2929
"tag": "v1.0.0",
3030
"subject": "1.0.0",
3131
"message": "1.0.0",
@@ -41,7 +41,7 @@ export default [
4141
"shorthash": "b0b3040",
4242
"author": "Pete Cook",
4343
"email": "email@example.com",
44-
"date": "2015-12-29T21:57:19+00:00",
44+
"date": "2015-12-29T21:57:19.000Z",
4545
"tag": null,
4646
"subject": "Some breaking change",
4747
"message": "Some breaking change",
@@ -57,7 +57,7 @@ export default [
5757
"shorthash": "db92947",
5858
"author": "Pete Cook",
5959
"email": "email@example.com",
60-
"date": "2015-12-29T21:19:17+00:00",
60+
"date": "2015-12-29T21:19:17.000Z",
6161
"tag": "v0.1.0",
6262
"subject": "0.1.0",
6363
"message": "0.1.0",
@@ -73,7 +73,7 @@ export default [
7373
"shorthash": "e9a43b2",
7474
"author": "Pete Cook",
7575
"email": "email@example.com",
76-
"date": "2015-12-29T21:19:19+00:00",
76+
"date": "2015-12-29T21:19:19.000Z",
7777
"tag": null,
7878
"subject": "Another commit that fixes nothing but with less changes",
7979
"message": "Another commit that fixes nothing but with less changes",
@@ -89,7 +89,7 @@ export default [
8989
"shorthash": "12c0624",
9090
"author": "Pete Cook",
9191
"email": "email@example.com",
92-
"date": "2015-12-29T21:18:19+00:00",
92+
"date": "2015-12-29T21:18:19.000Z",
9393
"tag": null,
9494
"subject": "Commit that fixes nothing",
9595
"message": "Commit that fixes nothing",
@@ -105,7 +105,7 @@ export default [
105105
"shorthash": "ef17dcc",
106106
"author": "Pete Cook",
107107
"email": "email@example.com",
108-
"date": "2015-12-28T21:17:17+00:00",
108+
"date": "2015-12-28T21:17:17.000Z",
109109
"tag": "v0.0.2",
110110
"subject": "0.0.2",
111111
"message": "0.0.2",
@@ -121,7 +121,7 @@ export default [
121121
"shorthash": "0e24bf4",
122122
"author": "Pete Cook",
123123
"email": "email@example.com",
124-
"date": "2015-12-24T20:29:22+00:00",
124+
"date": "2015-12-24T20:29:22.000Z",
125125
"tag": null,
126126
"subject": "Merge pull request #5 from repo/branch",
127127
"message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title",
@@ -138,7 +138,7 @@ export default [
138138
"shorthash": "9283969",
139139
"author": "Pete Cook",
140140
"email": "email@example.com",
141-
"date": "2015-12-29T11:35:54+00:00",
141+
"date": "2015-12-29T11:35:54.000Z",
142142
"tag": null,
143143
"subject": "Merge remote-tracking branch 'random-branch' into master",
144144
"message": "Merge remote-tracking branch 'random-branch' into master",
@@ -154,7 +154,7 @@ export default [
154154
"shorthash": "17fbef8",
155155
"author": "Pete Cook",
156156
"email": "email@example.com",
157-
"date": "2015-12-28T11:35:54+00:00",
157+
"date": "2015-12-28T11:35:54.000Z",
158158
"tag": null,
159159
"subject": "Commit 4 fixes #4 in the subject",
160160
"message": "Commit 4 fixes #4 in the subject\n\nWith some extra notes here",
@@ -175,7 +175,7 @@ export default [
175175
"shorthash": "796edd1",
176176
"author": "Pete Cook",
177177
"email": "email@example.com",
178-
"date": "2015-12-15T12:03:09+00:00",
178+
"date": "2015-12-15T12:03:09.000Z",
179179
"tag": "v0.0.1",
180180
"subject": "0.0.1",
181181
"message": "0.0.1",
@@ -191,7 +191,7 @@ export default [
191191
"shorthash": "31b7d3d",
192192
"author": "Pete Cook",
193193
"email": "email@example.com",
194-
"date": "2015-12-15T11:37:05+00:00",
194+
"date": "2015-12-15T11:37:05.000Z",
195195
"tag": null,
196196
"subject": "Merge pull request #3 from repo/branch",
197197
"message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR",
@@ -208,7 +208,7 @@ export default [
208208
"shorthash": "1c2694e",
209209
"author": "Pete Cook",
210210
"email": "email@example.com",
211-
"date": "2015-12-15T11:31:06+00:00",
211+
"date": "2015-12-15T11:31:06.000Z",
212212
"tag": null,
213213
"subject": "Third commit with same name as PR",
214214
"message": "Third commit with same name as PR",
@@ -224,7 +224,7 @@ export default [
224224
"shorthash": "90ef334",
225225
"author": "Pete Cook",
226226
"email": "email@example.com",
227-
"date": "2015-12-15T11:31:06+00:00",
227+
"date": "2015-12-15T11:31:06.000Z",
228228
"tag": null,
229229
"subject": "Second commit",
230230
"message": "Second commit\n\nResolves #1 and fixes https://github.com/user/repo/issues/2",
@@ -249,7 +249,7 @@ export default [
249249
"shorthash": "158fdde",
250250
"author": "Pete Cook",
251251
"email": "email@example.com",
252-
"date": "2015-12-14T17:06:12+00:00",
252+
"date": "2015-12-14T17:06:12.000Z",
253253
"tag": null,
254254
"subject": "First commit",
255255
"message": "First commit",

test/data/commits.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default [
44
"shorthash": "b0b3040",
55
"author": "Pete Cook",
66
"email": "email@example.com",
7-
"date": "2015-12-29T21:57:19+00:00",
7+
"date": "2015-12-29T21:57:19.000Z",
88
"tag": null,
99
"subject": "Unreleased commit",
1010
"message": "Unreleased commit\n\nFixes #6",
@@ -25,7 +25,7 @@ export default [
2525
"shorthash": "b0b3040",
2626
"author": "Pete Cook",
2727
"email": "email@example.com",
28-
"date": "2015-12-15T12:03:09+00:00",
28+
"date": "2015-12-15T12:03:09.000Z",
2929
"tag": "v1.0.0",
3030
"subject": "1.0.0",
3131
"message": "1.0.0",
@@ -41,7 +41,7 @@ export default [
4141
"shorthash": "b0b3040",
4242
"author": "Pete Cook",
4343
"email": "email@example.com",
44-
"date": "2015-12-29T21:57:19+00:00",
44+
"date": "2015-12-29T21:57:19.000Z",
4545
"tag": null,
4646
"subject": "Some breaking change",
4747
"message": "Some breaking change",
@@ -57,7 +57,7 @@ export default [
5757
"shorthash": "db92947",
5858
"author": "Pete Cook",
5959
"email": "email@example.com",
60-
"date": "2015-12-29T21:19:17+00:00",
60+
"date": "2015-12-29T21:19:17.000Z",
6161
"tag": "v0.1.0",
6262
"subject": "0.1.0",
6363
"message": "0.1.0",
@@ -73,7 +73,7 @@ export default [
7373
"shorthash": "e9a43b2",
7474
"author": "Pete Cook",
7575
"email": "email@example.com",
76-
"date": "2015-12-29T21:19:19+00:00",
76+
"date": "2015-12-29T21:19:19.000Z",
7777
"tag": null,
7878
"subject": "Another commit that fixes nothing but with less changes",
7979
"message": "Another commit that fixes nothing but with less changes",
@@ -89,7 +89,7 @@ export default [
8989
"shorthash": "12c0624",
9090
"author": "Pete Cook",
9191
"email": "email@example.com",
92-
"date": "2015-12-29T21:18:19+00:00",
92+
"date": "2015-12-29T21:18:19.000Z",
9393
"tag": null,
9494
"subject": "Commit that fixes nothing",
9595
"message": "Commit that fixes nothing",
@@ -105,7 +105,7 @@ export default [
105105
"shorthash": "ef17dcc",
106106
"author": "Pete Cook",
107107
"email": "email@example.com",
108-
"date": "2015-12-28T21:17:17+00:00",
108+
"date": "2015-12-28T21:17:17.000Z",
109109
"tag": "v0.0.2",
110110
"subject": "0.0.2",
111111
"message": "0.0.2",
@@ -121,7 +121,7 @@ export default [
121121
"shorthash": "0e24bf4",
122122
"author": "Pete Cook",
123123
"email": "email@example.com",
124-
"date": "2015-12-24T20:29:22+00:00",
124+
"date": "2015-12-24T20:29:22.000Z",
125125
"tag": null,
126126
"subject": "Merge pull request #5 from repo/branch",
127127
"message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title",
@@ -138,7 +138,7 @@ export default [
138138
"shorthash": "9283969",
139139
"author": "Pete Cook",
140140
"email": "email@example.com",
141-
"date": "2015-12-29T11:35:54+00:00",
141+
"date": "2015-12-29T11:35:54.000Z",
142142
"tag": null,
143143
"subject": "Merge remote-tracking branch 'random-branch' into master",
144144
"message": "Merge remote-tracking branch 'random-branch' into master",
@@ -154,7 +154,7 @@ export default [
154154
"shorthash": "17fbef8",
155155
"author": "Pete Cook",
156156
"email": "email@example.com",
157-
"date": "2015-12-28T11:35:54+00:00",
157+
"date": "2015-12-28T11:35:54.000Z",
158158
"tag": null,
159159
"subject": "Commit 4 fixes #4 in the subject",
160160
"message": "Commit 4 fixes #4 in the subject\n\nWith some extra notes here",
@@ -175,7 +175,7 @@ export default [
175175
"shorthash": "796edd1",
176176
"author": "Pete Cook",
177177
"email": "email@example.com",
178-
"date": "2015-12-15T12:03:09+00:00",
178+
"date": "2015-12-15T12:03:09.000Z",
179179
"tag": "v0.0.1",
180180
"subject": "0.0.1",
181181
"message": "0.0.1",
@@ -191,7 +191,7 @@ export default [
191191
"shorthash": "31b7d3d",
192192
"author": "Pete Cook",
193193
"email": "email@example.com",
194-
"date": "2015-12-15T11:37:05+00:00",
194+
"date": "2015-12-15T11:37:05.000Z",
195195
"tag": null,
196196
"subject": "Merge pull request #3 from repo/branch",
197197
"message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR",
@@ -208,7 +208,7 @@ export default [
208208
"shorthash": "1c2694e",
209209
"author": "Pete Cook",
210210
"email": "email@example.com",
211-
"date": "2015-12-15T11:31:06+00:00",
211+
"date": "2015-12-15T11:31:06.000Z",
212212
"tag": null,
213213
"subject": "Third commit with same name as PR",
214214
"message": "Third commit with same name as PR",
@@ -224,7 +224,7 @@ export default [
224224
"shorthash": "90ef334",
225225
"author": "Pete Cook",
226226
"email": "email@example.com",
227-
"date": "2015-12-15T11:31:06+00:00",
227+
"date": "2015-12-15T11:31:06.000Z",
228228
"tag": null,
229229
"subject": "Second commit",
230230
"message": "Second commit\n\nResolves #1 and fixes https://github.com/user/repo/issues/2",
@@ -249,7 +249,7 @@ export default [
249249
"shorthash": "158fdde",
250250
"author": "Pete Cook",
251251
"email": "email@example.com",
252-
"date": "2015-12-14T17:06:12+00:00",
252+
"date": "2015-12-14T17:06:12.000Z",
253253
"tag": null,
254254
"subject": "First commit",
255255
"message": "First commit",

0 commit comments

Comments
 (0)