diff --git a/lib/format.js b/lib/format.js index 564680f..f63b85f 100644 --- a/lib/format.js +++ b/lib/format.js @@ -1,8 +1,14 @@ const template = ` -There were the following issues with this Pull Request +The following commits do not follow the [Conventional Commits][cc] rules: +
+ +
+ +
+ You may need to [change the commit messages][ref] to comply with the \ repository contributing guidelines. @@ -13,6 +19,7 @@ issues [here][issues]. Happy coding! +[cc]: https://www.conventionalcommits.org [ref]: https://help.github.com/articles/changing-a-commit-message/ [repo]: https://github.com/z0al/commitlint-bot [issues]: https://github.com/z0al/commitlint-bot/issues @@ -24,15 +31,18 @@ Happy coding! * @param {Array} report */ function format(commits) { - let message = ""; + let details = ""; + let message = commits.map(c => `* ${c.sha}`).join("\n") commits.forEach(c => { - message += `* Commit: ${c.sha}\n`; - message += c.errors.map(e => ` - ✖ ${e.message}\n`).join(""); - message += c.warnings.map(w => ` - ⚠ ${w.message}\n`).join(""); + details += `* Commit: ${c.sha}\n`; + details += c.errors.map(e => ` - ✖ ${e.message}\n`).join(""); + details += c.warnings.map(w => ` - ⚠ ${w.message}\n`).join(""); }); - return template.replace("", message); + return template + .replace("", message) + .replace("
", details); } module.exports = format; diff --git a/test/format.test.js b/test/format.test.js index 08b2c68..392d0b0 100644 --- a/test/format.test.js +++ b/test/format.test.js @@ -2,35 +2,43 @@ const format = require('../lib/format') const commits = [ - // #1 - [ - { - sha: 'abc', - errors: [], - warnings: [{ message: 'warning message' }] - } - ], + // #1 + [{ + sha: 'abc', + errors: [], + warnings: [{ + message: 'warning message' + }] + }], - // #2 - [ - { - sha: 'def', - errors: [{ message: 'error message' }], - warnings: [{ message: 'warning message' }] - } - ] + // #2 + [{ + sha: 'def', + errors: [{ + message: 'error message' + }], + warnings: [{ + message: 'warning message' + }] + }] ] -test('repalces placeholder', () => { - expect(format(commits[0])).not.toMatch(/PLACEHOLDER/) +test('replaces placeholder', () => { + expect(format(commits[0])).not.toMatch(/PLACEHOLDER/) +}) + +test('replaces details', () => { + expect(format(commits[0])).not.toMatch(/DETAILS/) }) test('generates comment body', () => { - // #1 - expect(format(commits[0])).toMatch(/Commit: abc/) - expect(format(commits[0])).toMatch(/warning message/) - // #2 - expect(format(commits[1])).toMatch(/Commit: def/) - expect(format(commits[1])).toMatch(/error message/) - expect(format(commits[1])).toMatch(/warning message/) + // #1 + expect(format(commits[0])).toMatch(/Commit: abc/) + expect(format(commits[0])).toMatch(/warning message/) + // #2 + expect(format(commits[1])).toMatch(/Commit: def/) + expect(format(commits[1])).toMatch(/error message/) + expect(format(commits[1])).toMatch(/warning message/) + // test both + expect(format(commits.flat())).toMatch(/\* abc\n\* def/) })

AltStyle によって変換されたページ (->オリジナル) /