Skip to content

Commit

Permalink
#984: added interactive questions, no email validation at this point
Browse files Browse the repository at this point in the history
  • Loading branch information
phjulia committed Aug 13, 2023
1 parent e7c93c2 commit 92dfd6e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 23 deletions.
13 changes: 13 additions & 0 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6595,6 +6595,7 @@ CLI helper class
* [Cli](#Cli)
* [.initMcdevConfig()](#Cli.initMcdevConfig) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.addExtraCredential(properties)](#Cli.addExtraCredential) ⇒ <code>Promise.&lt;(boolean\|string)&gt;</code>
* [.updateNotificationNotes(type)](#Cli.updateNotificationNotes) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
* [.postFixKeysReretrieve(type, dependentTypes)](#Cli.postFixKeysReretrieve) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.logExistingCredentials(properties)](#Cli.logExistingCredentials) ⇒ <code>void</code>
* [.updateCredential(properties, credName)](#Cli.updateCredential) ⇒ <code>Promise.&lt;boolean&gt;</code>
Expand Down Expand Up @@ -6626,6 +6627,18 @@ Extends template file for properties.json
| --- | --- | --- |
| properties | <code>TYPE.Mcdevrc</code> | config file's json |

<a name="Cli.updateNotificationNotes"></a>

### Cli.updateNotificationNotes(type) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
interactive helper to set automation run completion/error note

**Kind**: static method of [<code>Cli</code>](#Cli)
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - responses

| Param | Type | Description |
| --- | --- | --- |
| type | <code>TYPE.SupportedMetadataTypes</code> | note type (error/completion) |

<a name="Cli.postFixKeysReretrieve"></a>

### Cli.postFixKeysReretrieve(type, dependentTypes) ⇒ <code>Promise.&lt;boolean&gt;</code>
Expand Down
53 changes: 31 additions & 22 deletions lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const File = require('../util/file');
const Definitions = require('../MetadataTypeDefinitions');
const cache = require('../util/cache');
const pLimit = require('p-limit');
const Cli = require('../util/cli');

/**
* Automation MetadataType
Expand Down Expand Up @@ -1653,41 +1654,49 @@ class Automation extends MetadataType {
`Error retrieving notifications for automation '${key}': ${ex.message} (${ex.code}))`
);
}

// check if there are any notifications set
if (Array.isArray(notificationsResult?.workers)) {
// if completion note was set check if there is an email address
if (
completionNote &&
completionEmail.length === 0 &&
// if a note was provided and email address was not - check if notif email address exists
if (
completionNote &&
completionEmail.length === 0 &&
(!notificationsResult.workers ||
!notificationsResult.workers.find(
(notification) => notification.notificationType == 'Complete'
)
) {
// if a note was provided and email address was not - check if notif email address exists
))
) {
const email = await Cli.updateNotificationNotes('completionEmail');
if (email) {
completionEmail.push(email);
} else {
completionNote = undefined;
shouldUpdateCompletion = false;
Util.logger.info(
` ☇ skipping --completionNote' - the email address for Run completion was not set`
);
completionNote = undefined;
shouldUpdateCompletion = false;
// TODO interactive question "do you want to set completionEmail" then ask for email ?
}

if (
errorNote &&
errorEmail.length === 0 &&
}
// same for errorNote
if (
errorNote &&
errorEmail.length === 0 &&
(!notificationsResult.workers ||
!notificationsResult.workers.find(
(notification) => notification.notificationType == 'Error'
)
) {
))
) {
const email = await Cli.updateNotificationNotes('errorEmail');
if (email) {
errorEmail.push(email);
} else {
errorNote = undefined;
shouldUpdateError = false;
Util.logger.info(
` ☇ skipping --errorNote' - the email address for Runtime error was not set`
);
errorNote = undefined;
shouldUpdateError = false;
// TODO interactive question "do you want to set errorEmail" then ask for email ?
}
}

// check if there are any notifications set
if (Array.isArray(notificationsResult?.workers)) {
// check again if there is anything else to update
if (!shouldUpdateCompletion && !shouldUpdateError) {
Util.logger.info(` ☇ skipping ${key}' - nothing to update`);
Expand Down
28 changes: 27 additions & 1 deletion lib/util/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,33 @@ const Cli = {
return null;
}
},

/**
* interactive helper to set automation run completion/error note
*
* @param {TYPE.SupportedMetadataTypes} type note type (error/completion)
* @returns {Promise.<string[]>} responses
*/
async updateNotificationNotes(type) {
const question1 = {
type: 'confirm',
name: 'provideEmail',
message: `To set run ${type} note, an email address should be set. Do you want to set it?`,
default: true,
};
const question2 = {
type: 'input',
name: 'updateNotificationNotes',
message: `Please enter email addresses separated by a comma:`,
};
try {
if (!(await inquirer.prompt(question1)).provideEmail) {
return;
}
return (await inquirer.prompt(question2)).updateNotificationNotes;
} catch (ex) {
Util.logger.info(ex);
}
},
/**
*
* @param {TYPE.SupportedMetadataTypes} type limit execution to given metadata type
Expand Down

0 comments on commit 92dfd6e

Please sign in to comment.