Skip to content

Commit 92dfd6e

Browse files
committed
#984: added interactive questions, no email validation at this point
1 parent e7c93c2 commit 92dfd6e

File tree

3 files changed

+71
-23
lines changed

3 files changed

+71
-23
lines changed

docs/dist/documentation.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6595,6 +6595,7 @@ CLI helper class
65956595
* [Cli](#Cli)
65966596
* [.initMcdevConfig()](#Cli.initMcdevConfig) ⇒ <code>Promise.&lt;boolean&gt;</code>
65976597
* [.addExtraCredential(properties)](#Cli.addExtraCredential) ⇒ <code>Promise.&lt;(boolean\|string)&gt;</code>
6598+
* [.updateNotificationNotes(type)](#Cli.updateNotificationNotes) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
65986599
* [.postFixKeysReretrieve(type, dependentTypes)](#Cli.postFixKeysReretrieve) ⇒ <code>Promise.&lt;boolean&gt;</code>
65996600
* [.logExistingCredentials(properties)](#Cli.logExistingCredentials) ⇒ <code>void</code>
66006601
* [.updateCredential(properties, credName)](#Cli.updateCredential) ⇒ <code>Promise.&lt;boolean&gt;</code>
@@ -6626,6 +6627,18 @@ Extends template file for properties.json
66266627
| --- | --- | --- |
66276628
| properties | <code>TYPE.Mcdevrc</code> | config file's json |
66286629

6630+
<a name="Cli.updateNotificationNotes"></a>
6631+
6632+
### Cli.updateNotificationNotes(type) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
6633+
interactive helper to set automation run completion/error note
6634+
6635+
**Kind**: static method of [<code>Cli</code>](#Cli)
6636+
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - responses
6637+
6638+
| Param | Type | Description |
6639+
| --- | --- | --- |
6640+
| type | <code>TYPE.SupportedMetadataTypes</code> | note type (error/completion) |
6641+
66296642
<a name="Cli.postFixKeysReretrieve"></a>
66306643

66316644
### Cli.postFixKeysReretrieve(type, dependentTypes) ⇒ <code>Promise.&lt;boolean&gt;</code>

lib/metadataTypes/Automation.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const File = require('../util/file');
77
const Definitions = require('../MetadataTypeDefinitions');
88
const cache = require('../util/cache');
99
const pLimit = require('p-limit');
10+
const Cli = require('../util/cli');
1011

1112
/**
1213
* Automation MetadataType
@@ -1653,41 +1654,49 @@ class Automation extends MetadataType {
16531654
`Error retrieving notifications for automation '${key}': ${ex.message} (${ex.code}))`
16541655
);
16551656
}
1656-
1657-
// check if there are any notifications set
1658-
if (Array.isArray(notificationsResult?.workers)) {
1659-
// if completion note was set check if there is an email address
1660-
if (
1661-
completionNote &&
1662-
completionEmail.length === 0 &&
1657+
// if a note was provided and email address was not - check if notif email address exists
1658+
if (
1659+
completionNote &&
1660+
completionEmail.length === 0 &&
1661+
(!notificationsResult.workers ||
16631662
!notificationsResult.workers.find(
16641663
(notification) => notification.notificationType == 'Complete'
1665-
)
1666-
) {
1667-
// if a note was provided and email address was not - check if notif email address exists
1664+
))
1665+
) {
1666+
const email = await Cli.updateNotificationNotes('completionEmail');
1667+
if (email) {
1668+
completionEmail.push(email);
1669+
} else {
1670+
completionNote = undefined;
1671+
shouldUpdateCompletion = false;
16681672
Util.logger.info(
16691673
` ☇ skipping --completionNote' - the email address for Run completion was not set`
16701674
);
1671-
completionNote = undefined;
1672-
shouldUpdateCompletion = false;
1673-
// TODO interactive question "do you want to set completionEmail" then ask for email ?
16741675
}
1675-
1676-
if (
1677-
errorNote &&
1678-
errorEmail.length === 0 &&
1676+
}
1677+
// same for errorNote
1678+
if (
1679+
errorNote &&
1680+
errorEmail.length === 0 &&
1681+
(!notificationsResult.workers ||
16791682
!notificationsResult.workers.find(
16801683
(notification) => notification.notificationType == 'Error'
1681-
)
1682-
) {
1684+
))
1685+
) {
1686+
const email = await Cli.updateNotificationNotes('errorEmail');
1687+
if (email) {
1688+
errorEmail.push(email);
1689+
} else {
1690+
errorNote = undefined;
1691+
shouldUpdateError = false;
16831692
Util.logger.info(
16841693
` ☇ skipping --errorNote' - the email address for Runtime error was not set`
16851694
);
1686-
errorNote = undefined;
1687-
shouldUpdateError = false;
1688-
// TODO interactive question "do you want to set errorEmail" then ask for email ?
16891695
}
1696+
}
16901697

1698+
// check if there are any notifications set
1699+
if (Array.isArray(notificationsResult?.workers)) {
16911700
// check again if there is anything else to update
16921701
if (!shouldUpdateCompletion && !shouldUpdateError) {
16931702
Util.logger.info(` ☇ skipping ${key}' - nothing to update`);

lib/util/cli.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,33 @@ const Cli = {
5353
return null;
5454
}
5555
},
56-
56+
/**
57+
* interactive helper to set automation run completion/error note
58+
*
59+
* @param {TYPE.SupportedMetadataTypes} type note type (error/completion)
60+
* @returns {Promise.<string[]>} responses
61+
*/
62+
async updateNotificationNotes(type) {
63+
const question1 = {
64+
type: 'confirm',
65+
name: 'provideEmail',
66+
message: `To set run ${type} note, an email address should be set. Do you want to set it?`,
67+
default: true,
68+
};
69+
const question2 = {
70+
type: 'input',
71+
name: 'updateNotificationNotes',
72+
message: `Please enter email addresses separated by a comma:`,
73+
};
74+
try {
75+
if (!(await inquirer.prompt(question1)).provideEmail) {
76+
return;
77+
}
78+
return (await inquirer.prompt(question2)).updateNotificationNotes;
79+
} catch (ex) {
80+
Util.logger.info(ex);
81+
}
82+
},
5783
/**
5884
*
5985
* @param {TYPE.SupportedMetadataTypes} type limit execution to given metadata type

0 commit comments

Comments
 (0)