-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2694 from salesforce-ux/feature/release-notes
feature(release-notes): automate release notes
- Loading branch information
Showing
4 changed files
with
63 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,32 @@ | ||
const releaseNotes = require('../release-notes') | ||
const fs = require('fs') | ||
const through = require('through2'); | ||
const exhaustively = require('stream-exhaust'); | ||
|
||
describe('Release Notes', () => { | ||
it('generates notes for internal builds', (done) => { | ||
let data = '' | ||
const reader = through((chunk, enc, done) => done(null, data+=chunk)) | ||
releaseNotes({ | ||
isInternal: true, | ||
outStream: reader, | ||
callback: () => { | ||
expect(data).toContain('Bug Fixes') | ||
expect(data).toContain('design-system-internal') | ||
expect(data.length).toBeGreaterThan(100) | ||
done() | ||
} | ||
const reader = exhaustively(through((chunk, enc, done) => done(null, data+=chunk))) | ||
releaseNotes({ isInternal: true }) | ||
.pipe(reader) | ||
.on('end', () => { | ||
expect(data).toContain('Bug Fixes') | ||
expect(data).toContain('design-system-internal') | ||
expect(data.length).toBeGreaterThan(100) | ||
done() | ||
}) | ||
}) | ||
|
||
it('generates notes for external builds', (done) => { | ||
let data = '' | ||
const reader = through((chunk, enc, done) => done(null, data+=chunk)) | ||
releaseNotes({ | ||
isInternal: false, | ||
outStream: reader, | ||
callback: () => { | ||
expect(data).toContain('Bug Fixes') | ||
expect(data).not.toContain('design-system-internal') | ||
expect(data.length).toBeGreaterThan(100) | ||
done() | ||
} | ||
const reader = exhaustively(through((chunk, enc, d) => d(null, data+=chunk))) | ||
releaseNotes({ isInternal: false }) | ||
.pipe(reader) | ||
.on('end', () => { | ||
expect(data).toContain('Bug Fixes') | ||
expect(data).not.toContain('design-system-internal') | ||
expect(data.length).toBeGreaterThan(100) | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,48 @@ | ||
const lodash = require('lodash') | ||
const _ = lodash.mixin(require("lodash-inflection")) | ||
const {fromNullable} = require('data.either') | ||
const conventionalChangelog = require('conventional-changelog'); | ||
const through = require('through2'); | ||
const I = require('immutable'); | ||
|
||
const replaceInternal = str => | ||
str.replace(/design-system/ig, 'design-system-internal'); | ||
|
||
const replaceRepo = isInternal => (chunk, enc, callback) => | ||
callback(null, isInternal ? replaceInternal(String(chunk)) : chunk); | ||
const getSubject = line => | ||
fromNullable(String(line).match(/\*\*(.*)\*\*/ig)) | ||
.map(xs => xs[0]) | ||
.getOrElse('') | ||
|
||
module.exports = ({isInternal, outStream, callback}) => | ||
conventionalChangelog({ preset: 'angular', releaseCount: 0 }) | ||
.pipe(through(replaceRepo(isInternal))) | ||
.pipe(outStream) | ||
.on('finish', callback); | ||
const normalize = x => _.pluralize(_.kebabCase(x)) | ||
|
||
const getKeyAndValue = line => | ||
[normalize(getSubject(line)), _.last(line.split('**'))] | ||
|
||
const groupChunks = str => | ||
str.split('\n').reduce((acc, line) => { | ||
const [key, val] = getKeyAndValue(line) | ||
return acc.get(key) | ||
? acc.update(key, xs => xs.push(val)) | ||
: acc.set(key, I.List.of(val)) | ||
}, I.OrderedMap()) | ||
.map((v, k) => `* **${k}**:\n\t* ${v.join('\n\t*')}`) | ||
.join('\n') | ||
|
||
const groupRelatedBullets = x => | ||
x.match(/^\*/) ? groupChunks(x) : x | ||
|
||
const replaceRepoAndGroup = isInternal => (chunk, enc, callback) => { | ||
[String(chunk)] | ||
.map(str => isInternal ? replaceInternal(str) : str) | ||
.map(replaced => | ||
replaced.split(/\n{2,}/g) | ||
.map(groupRelatedBullets) | ||
.join('\n\n') | ||
) | ||
.map(x => x.replace(/<a name(.*)><\/a>/ig, '')) | ||
.map(result => callback(null, result)) | ||
} | ||
|
||
module.exports = ({isInternal, callback}) => | ||
conventionalChangelog({ preset: 'angular', releaseCount: 2 }) | ||
.pipe(through(replaceRepoAndGroup(isInternal))) |