forked from commitizen/cz-conventional-changelog
-
Notifications
You must be signed in to change notification settings - Fork 1
/
engine.js
196 lines (175 loc) · 5.43 KB
/
engine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
"format cjs";
var wrap = require('word-wrap');
var map = require('lodash.map');
var longest = require('longest');
var rightPad = require('right-pad');
// This can be any kind of SystemJS compatible module.
// We use Commonjs here, but ES6 or AMD would do just
// fine.
module.exports = function (options) {
var types = options.types;
var length = longest(Object.keys(types)).length + 1;
var choices = map(types, function (type, key) {
return {
name: rightPad(key + ':', length) + ' ' + type.description,
value: key
};
});
var projects = [{
name: 'Pricing engine and anything related to the eventual calculation of a price.',
value: 'pricing-engine'
}, {
name: 'API v2 and migration to API v2',
value: 'api-v2'
}, {
name: 'Data Warehousing and tracking',
value: 'data-warehousing-tracking'
}, {
name: 'B2C project',
value: 'b2c-project'
}, {
name: 'Other (or if you have no idea)',
value: ''
}];
var subCategories = {
'pricing-engine': [{
name: 'Vocational & High-School',
value: 'vocational-high-school'
}, {
name: 'Expanding Pricing Engine',
value: 'engine-expansion'
}, {
name: 'Package Concept',
value: 'packages'
}, {
name: 'Elasticsearch R&D',
value: 'elasticsearch'
}, {
name: 'Uncategorized',
value: ''
}],
'api-v2': [{
name: 'Legacy Conversion v1 -> v2',
value: 'legacy-conversion'
}, {
name: 'Development of API',
value: 'v2-development'
}, {
name: 'Webhook Support',
value: 'webhook-support'
}, {
name: 'Uncategorized',
value: ''
}],
'data-warehousing-tracking': [{
name: 'Consolidating Dispersed Data',
value: 'data-collection'
}, {
name: 'Uncategorized',
value: ''
}]
};
return {
// When a user runs `git cz`, prompter will
// be executed. We pass you cz, which currently
// is just an instance of inquirer.js. Using
// this you can ask questions and get answers.
//
// The commit callback should be executed when
// you're ready to send back a commit template
// to git.
//
// By default, we'll de-indent your commit
// template and will keep empty lines.
prompter: function(cz, commit) {
console.log('\nLine 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.\n');
// Let's ask some questions of the user
// so that we can populate our commit
// template.
//
// See inquirer.js docs for specifics.
// You can also opt to use another input
// collection library if you prefer.
cz.prompt([
{
type: 'list',
name: 'type',
message: 'Select the type of change that you\'re committing:',
choices: choices
}, {
type: 'input',
name: 'subject',
message: 'Write a short, imperative tense description of the change:\n'
}, {
type: 'input',
name: 'body',
message: 'Provide a longer description of the change:\n'
}, {
type: 'input',
name: 'taskNumber',
message: 'Provide the task number of the current change ("ES-???"):\n'
}, {
type: 'input',
name: 'hours',
message: 'Provide the # of hours spent on this commit (ex: "2" or "2.5"):\n'
}, {
type: 'list',
name: 'project',
message: 'Select the project this commit should fall into:',
choices: projects
}, {
when: function(response) {
return response.project === 'pricing-engine' ||
response.project === 'api-v2' ||
response.project === 'data-warehousing-tracking'
},
type: 'list',
name: 'problem',
message: 'Choose a sub-category of the project',
choices: function(response) {
return subCategories[response.project]
}
}, {
type: 'input',
name: 'footer',
message: 'List any breaking changes or issues closed by this change:\n'
}
]).then(function(answers) {
var maxLineWidth = 100;
var wrapOptions = {
trim: true,
newline: '\n',
indent:'',
width: maxLineWidth
};
// Hard limit this line
var head = (answers.type + '-' + answers.taskNumber + ': ' + answers.subject.trim()).slice(0, maxLineWidth);
// Wrap these lines at 100 characters
var body = wrap(answers.body, wrapOptions);
// Add SRED.io code
var hours = '';
var project = '';
var subProject = '';
if (answers.hours.trim()) {
hours = '-d ' + answers.hours.trim();
}
if (answers.project.trim()) {
project = '-p ' + answers.project
if (answers.problem && answers.problem.trim()) {
subProject = '-c ' + answers.problem
}
}
var sred = ''
if (hours || project) {
sred = 'sred ' + [hours, project, subProject].join(' ')
}
var jiraTimeTracking = ''
if (answers.hours || answers.taskNumber) {
jiraTimeTracking = '#time ' + answers.hours.trim() + 'h'
}
var footer = wrap(answers.footer, wrapOptions);
commit([head, body, footer, sred, jiraTimeTracking].join('\n\n'));
});
}
};
};