1441 |
ariadna |
1 |
#!/usr/bin/env node
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
import inquirer from 'inquirer';
|
|
|
18 |
import chalk from 'chalk';
|
|
|
19 |
|
|
|
20 |
import { createNote } from './note.mjs';
|
|
|
21 |
import { getInitialValues } from './helpers.mjs';
|
|
|
22 |
import * as Prompts from './prompts.mjs';
|
|
|
23 |
import logger from './logger.mjs';
|
|
|
24 |
|
|
|
25 |
export default async (options) => {
|
|
|
26 |
// Processs the initial values.
|
|
|
27 |
const initialValues = getInitialValues(options);
|
|
|
28 |
|
|
|
29 |
// Fetch information.
|
|
|
30 |
const messages = [];
|
|
|
31 |
const { issueNumber } = await inquirer.prompt([
|
|
|
32 |
Prompts.getIssuePrompt(),
|
|
|
33 |
], initialValues);
|
|
|
34 |
|
|
|
35 |
let selection = {};
|
|
|
36 |
let notePath;
|
|
|
37 |
do {
|
|
|
38 |
selection = {};
|
|
|
39 |
selection = await inquirer.prompt([
|
|
|
40 |
Prompts.getComponentsPrompt(),
|
|
|
41 |
Prompts.getTypePrompt(),
|
|
|
42 |
Prompts.getMessagePromptInput(),
|
|
|
43 |
], initialValues);
|
|
|
44 |
if (selection.message === '') {
|
|
|
45 |
selection = Object.assign(
|
|
|
46 |
selection,
|
|
|
47 |
await inquirer.prompt([
|
|
|
48 |
Prompts.getMessagePromptEditor(),
|
|
|
49 |
]),
|
|
|
50 |
);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
logger.info(`
|
|
|
54 |
Creating upgrade note with the following options:
|
|
|
55 |
|
|
|
56 |
- Issue: ${chalk.bold(issueNumber)}
|
|
|
57 |
- Component: ${chalk.bold(selection.components)}
|
|
|
58 |
- Type: ${chalk.bold(selection.type)}
|
|
|
59 |
- Message:
|
|
|
60 |
${chalk.bold(selection.message)}
|
|
|
61 |
`);
|
|
|
62 |
|
|
|
63 |
messages.push({
|
|
|
64 |
components: [selection.components],
|
|
|
65 |
type: selection.type,
|
|
|
66 |
message: selection.message,
|
|
|
67 |
});
|
|
|
68 |
|
|
|
69 |
// Save the note so far.
|
|
|
70 |
if (notePath) {
|
|
|
71 |
await createNote(issueNumber, messages, notePath);
|
|
|
72 |
logger.info(`Updated note at: ${chalk.underline(chalk.bold(notePath))}`);
|
|
|
73 |
} else {
|
|
|
74 |
notePath = await createNote(issueNumber, messages);
|
|
|
75 |
logger.info(`Note created at: ${chalk.underline(chalk.bold(notePath))}`);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
selection = Object.assign(
|
|
|
79 |
selection,
|
|
|
80 |
await inquirer.prompt([
|
|
|
81 |
Prompts.getAddAnotherPrompt(),
|
|
|
82 |
], initialValues),
|
|
|
83 |
);
|
|
|
84 |
} while (selection.addAnother);
|
|
|
85 |
};
|