1 | 'use strict';
|
2 |
|
3 | var Bluebird = require('bluebird');
|
4 |
|
5 | var DEFAULT_TYPE = 'other';
|
6 | var TYPES = {
|
7 | chore: 'Chores',
|
8 | docs: 'Documentation Changes',
|
9 | feat: 'New Features',
|
10 | fix: 'Bug Fixes',
|
11 | other: 'Other Changes',
|
12 | refactor: 'Refactors',
|
13 | style: 'Code Style Changes',
|
14 | test: 'Tests'
|
15 | };
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | exports.markdown = function (version, commits, options) {
|
29 | var content = [];
|
30 | var now = new Date();
|
31 | var date = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();
|
32 | var heading;
|
33 |
|
34 | if (options.major) {
|
35 | heading = '##';
|
36 | } else if (options.minor) {
|
37 | heading = '###';
|
38 | } else {
|
39 | heading = '####';
|
40 | }
|
41 |
|
42 | heading += ' ' + version + ' (' + date + ')';
|
43 |
|
44 | content.push(heading);
|
45 | content.push('');
|
46 |
|
47 | return Bluebird.resolve(commits)
|
48 | .bind({ types: {} })
|
49 | .each(function (commit) {
|
50 | var type = TYPES[commit.type] ? commit.type : DEFAULT_TYPE;
|
51 | var category = commit.category;
|
52 |
|
53 | this.types[type] = this.types[type] || {};
|
54 | this.types[type][category] = this.types[type][category] || [];
|
55 |
|
56 | this.types[type][category].push(commit);
|
57 | })
|
58 | .then(function () {
|
59 | return Object.keys(this.types).sort();
|
60 | })
|
61 | .each(function (type) {
|
62 | var types = this.types;
|
63 |
|
64 | content.push('##### ' + TYPES[type]);
|
65 | content.push('');
|
66 |
|
67 | Object.keys(this.types[type]).forEach(function (category) {
|
68 | var prefix = '*';
|
69 | var nested = types[type][category].length > 1;
|
70 | var categoryHeading = '* **' + category + ':**';
|
71 |
|
72 | if (nested) {
|
73 | content.push(categoryHeading);
|
74 | prefix = ' *';
|
75 | } else {
|
76 | prefix = categoryHeading;
|
77 | }
|
78 |
|
79 | types[type][category].forEach(function (commit) {
|
80 | var shorthash = commit.hash.substring(0, 8);
|
81 |
|
82 | if (options.repoUrl) {
|
83 | shorthash = '[' + shorthash + '](' + options.repoUrl + '/commit/' + commit.hash + ')';
|
84 | }
|
85 |
|
86 | content.push(prefix + ' ' + commit.subject + ' (' + shorthash + ')');
|
87 | });
|
88 | });
|
89 |
|
90 | content.push('');
|
91 | })
|
92 | .then(function () {
|
93 | content.push('');
|
94 | return content.join('\n');
|
95 | });
|
96 | };
|