-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
83 lines (72 loc) · 1.94 KB
/
index.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
/*
Required packages
*/
const yaml = require('write-yaml');
const slugify = require('slugify');
const { prompt } = require('enquirer');
const { sprintf } = require('sprintf-js');
/*
File path pattern
*/
const pattern = './changelog/unreleased/%s-%s.yml';
/*
Questions
*/
prompt( [
{
type: 'text',
name: 'message',
hint: '... e.g. Bug ticket title',
message: 'Changelog entry message',
validate() { return this.value.trim() ? true : 'Must not be empty' }
},
{
type: 'autocomplete',
name: 'type',
message: 'Type of change',
initial: 2,
hint: '... use arrow-keys, <return> to submit',
choices: ['FIX', 'MISC', 'FEATURE', 'BC BREAK', 'IMPROVEMENT'],
suggest(input, choices) {
return choices.filter( choice => choice.message.includes(typed) );
}
},
{
type: 'text',
name: 'issue',
message: 'Jira ticket',
hint: '... e.g. HD-987',
validate() { return this.value.trim() ? true : 'Must not be empty' }
},
{
type: 'text',
name: 'merge-request',
hint: '... e.g. 790',
initial: 0,
message: 'Merge Request',
result() { return parseInt( this.value, 10 ) },
validate() { return ! isNaN( this.value ) }
},
{
type: 'confirm',
name: 'confirmed',
message: 'Ready to create?',
initial: true
},
] ).then( answers => {
// Exit on abort
if ( ! answers.confirmed ) return;
// Fix MR default value
answers['merge-request'] = parseInt(answers['merge-request'], 10);
// Remove confirm
delete answers.confirmed;
const filepath = sprintf(
pattern,
slugify(answers.issue),
slugify(answers.message.toLowerCase())
);
// Write YAML
yaml(filepath, answers, error => {
if ( error ) throw new Error( error );
});
} ).catch( console.error );