Skip to content

Commit

Permalink
Update test data generation
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Sep 1, 2019
1 parent b1ab27e commit c2c9bd8
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 168 deletions.
44 changes: 18 additions & 26 deletions scripts/generate-test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,38 @@ import { readFile, writeFile } from '../src/utils'
import { __get__ } from '../src/commits'
import { parseReleases } from '../src/releases'
import { compileTemplate } from '../src/template'
import remotes from '../test/data/remotes'

const parseCommits = __get__('parseCommits')

const DATA_DIR = join(__dirname, '..', 'test', 'data')

const remote = {
hostname: 'github.com',
url: 'https://github.com/user/repo'
}

const options = {
unreleased: false,
commitLimit: 3,
backfillLimit: 3,
tagPrefix: ''
}

async function run () {
const gitLog = await readFile(join(DATA_DIR, 'git-log.txt'))
const commits = parseCommits(gitLog, remote, options)
const releases = parseReleases(commits, remote, null, options)
await writeFile(join(DATA_DIR, 'commits.js'), 'export default ' + JSON.stringify(commits, null, 2))
await writeFile(join(DATA_DIR, 'commits-no-remote.js'), 'export default ' + JSON.stringify(commitsWithoutLinks(commits), null, 2))
await writeFile(join(DATA_DIR, 'releases.js'), 'export default ' + JSON.stringify(releases, null, 2))
await writeFile(join(DATA_DIR, 'template-compact.md'), await compileTemplate({ template: 'compact' }, { releases }))
await writeFile(join(DATA_DIR, 'template-keepachangelog.md'), await compileTemplate({ template: 'keepachangelog' }, { releases }))
await writeFile(join(DATA_DIR, 'template-json.json'), await compileTemplate({ template: 'json' }, { releases }))
function writeObject (filename, object) {
return writeFile(join(DATA_DIR, filename), `export default ${JSON.stringify(object, null, 2)}\n`)
}

function commitsWithoutLinks (commits) {
return commits.map(commit => {
const merge = commit.merge ? { ...commit.merge, href: null, commit: { ...commit.merge.commit, href: null } } : null
const fixes = commit.fixes ? commit.fixes.map(fix => ({ ...fix, href: null })) : null
return {
...commit,
href: null,
fixes,
merge
}
})
async function writeTemplate (filename, template, releases) {
return writeFile(join(DATA_DIR, filename), await compileTemplate({ template }, { releases }))
}

async function run () {
const gitLog = await readFile(join(DATA_DIR, 'git-log.txt'))
const commits = parseCommits(gitLog, remotes.github, options)
const commitsNoRemote = parseCommits(gitLog, remotes.null, options)
const releases = parseReleases(commits, remotes.github, null, options)
await writeObject('commits.js', commits)
await writeObject('commits-no-remote.js', commitsNoRemote)
await writeObject('releases.js', releases)
await writeTemplate('template-compact.md', 'compact', releases)
await writeTemplate('template-keepachangelog.md', 'keepachangelog', releases)
await writeTemplate('template-json.json', 'json', releases)
}

run().catch(e => console.error(e))
2 changes: 1 addition & 1 deletion test/data/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,4 @@ export default [
"deletions": 22,
"merge": null
}
]
]
144 changes: 73 additions & 71 deletions test/data/releases.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export default [
{
"tag": "v1.0.0",
"title": "v1.0.0",
"date": "2015-12-15T12:03:09.000Z",
"isoDate": "2015-12-15",
"niceDate": "15 December 2015",
"commits": [
{
"hash": "b0b304049847d9568585bc11399fa6cfa4cab5dc",
Expand All @@ -19,18 +24,18 @@ export default [
"merge": null
}
],
"fixes": [],
"merges": [],
"tag": "v1.0.0",
"date": "2015-12-15T12:03:09.000Z",
"fixes": [],
"summary": null,
"title": "v1.0.0",
"niceDate": "15 December 2015",
"isoDate": "2015-12-15",
"href": "https://github.com/user/repo/compare/v0.1.0...v1.0.0",
"major": true
"major": true,
"href": "https://github.com/user/repo/compare/v0.1.0...v1.0.0"
},
{
"tag": "v0.1.0",
"title": "v0.1.0",
"date": "2015-12-29T21:19:17.000Z",
"isoDate": "2015-12-29",
"niceDate": "29 December 2015",
"commits": [
{
"hash": "12c0624e7e419a70bd5f3b403d7e0bd8f23ec617",
Expand Down Expand Up @@ -67,19 +72,40 @@ export default [
"merge": null
}
],
"fixes": [],
"merges": [],
"tag": "v0.1.0",
"date": "2015-12-29T21:19:17.000Z",
"fixes": [],
"summary": null,
"title": "v0.1.0",
"niceDate": "29 December 2015",
"isoDate": "2015-12-29",
"href": "https://github.com/user/repo/compare/v0.0.2...v0.1.0",
"major": false
"major": false,
"href": "https://github.com/user/repo/compare/v0.0.2...v0.1.0"
},
{
"tag": "v0.0.2",
"title": "v0.0.2",
"date": "2015-12-28T21:17:17.000Z",
"isoDate": "2015-12-28",
"niceDate": "28 December 2015",
"commits": [],
"merges": [
{
"id": "5",
"message": "Should not parse #4 in PR title",
"href": "https://github.com/user/repo/pull/5",
"author": "Pete Cook",
"commit": {
"hash": "0e24bf427a51eac52133cc731b4b5d74a7e04672",
"shorthash": "0e24bf4",
"author": "Pete Cook",
"email": "email@example.com",
"date": "2015-12-24T20:29:22.000Z",
"tag": null,
"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,
"href": "https://github.com/user/repo/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672",
"breaking": false
}
}
],
"fixes": [
{
"fixes": [
Expand Down Expand Up @@ -114,37 +140,16 @@ export default [
}
}
],
"merges": [
{
"id": "5",
"message": "Should not parse #4 in PR title",
"href": "https://github.com/user/repo/pull/5",
"author": "Pete Cook",
"commit": {
"hash": "0e24bf427a51eac52133cc731b4b5d74a7e04672",
"shorthash": "0e24bf4",
"author": "Pete Cook",
"email": "email@example.com",
"date": "2015-12-24T20:29:22.000Z",
"tag": null,
"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,
"href": "https://github.com/user/repo/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672",
"breaking": false
}
}
],
"tag": "v0.0.2",
"date": "2015-12-28T21:17:17.000Z",
"summary": null,
"title": "v0.0.2",
"niceDate": "28 December 2015",
"isoDate": "2015-12-28",
"href": "https://github.com/user/repo/compare/v0.0.1...v0.0.2",
"major": false
"major": false,
"href": "https://github.com/user/repo/compare/v0.0.1...v0.0.2"
},
{
"tag": "v0.0.1",
"title": "v0.0.1",
"date": "2015-12-15T12:03:09.000Z",
"isoDate": "2015-12-15",
"niceDate": "15 December 2015",
"commits": [
{
"hash": "158fdde54b6188c9f9ca3034e9cb5bcc3fe3ff69",
Expand All @@ -164,6 +169,27 @@ export default [
"merge": null
}
],
"merges": [
{
"id": "3",
"message": "Third commit with same name as PR",
"href": "https://github.com/user/repo/pull/3",
"author": "Pete Cook",
"commit": {
"hash": "31b7d3da24d64e32a0a7e558f254d01c348613f3",
"shorthash": "31b7d3d",
"author": "Pete Cook",
"email": "email@example.com",
"date": "2015-12-15T11:37:05.000Z",
"tag": null,
"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,
"href": "https://github.com/user/repo/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3",
"breaking": false
}
}
],
"fixes": [
{
"fixes": [
Expand Down Expand Up @@ -208,32 +234,8 @@ export default [
}
}
],
"merges": [
{
"id": "3",
"message": "Third commit with same name as PR",
"href": "https://github.com/user/repo/pull/3",
"author": "Pete Cook",
"commit": {
"hash": "31b7d3da24d64e32a0a7e558f254d01c348613f3",
"shorthash": "31b7d3d",
"author": "Pete Cook",
"email": "email@example.com",
"date": "2015-12-15T11:37:05.000Z",
"tag": null,
"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,
"href": "https://github.com/user/repo/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3",
"breaking": false
}
}
],
"tag": "v0.0.1",
"date": "2015-12-15T12:03:09.000Z",
"summary": null,
"title": "v0.0.1",
"niceDate": "15 December 2015",
"isoDate": "2015-12-15"
"major": false,
"href": null
}
]
]
Loading

0 comments on commit c2c9bd8

Please sign in to comment.