Skip to content

Commit

Permalink
#984: updateNotifications improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
phjulia committed Aug 12, 2023
1 parent 19f1318 commit 24543f0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 39 deletions.
6 changes: 0 additions & 6 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3009,7 +3009,6 @@ ImportFile MetadataType
* [.update(importFile)](#ImportFile.update) ⇒ <code>Promise</code>
* [.preDeployTasks(metadata)](#ImportFile.preDeployTasks) ⇒ <code>Promise</code>
* [.parseMetadata(metadata)](#ImportFile.parseMetadata) ⇒ <code>TYPE.MetadataTypeItem</code>
* [.updateNotifications()](#ImportFile.updateNotifications) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>

<a name="ImportFile.retrieve"></a>

Expand Down Expand Up @@ -3109,11 +3108,6 @@ parses retrieved Metadata before saving
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeItem</code> | a single import definition |

<a name="ImportFile.updateNotifications"></a>

### ImportFile.updateNotifications() ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
**Kind**: static method of [<code>ImportFile</code>](#ImportFile)
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - keys of the importFiles where notifications were updated
<a name="Journey"></a>

## Journey ⇐ [<code>MetadataType</code>](#MetadataType)
Expand Down
53 changes: 26 additions & 27 deletions lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1619,12 +1619,22 @@ class Automation extends MetadataType {
* @returns {Promise.<string[]>} keys of the automations where notifications were updated
*/
static async updateNotifications(keys) {
const completionEmail = Util.OPTIONS.completionEmail
? Util.OPTIONS.completionEmail.split(',')
: undefined;
const errorEmail = Util.OPTIONS.errorEmail ? Util.OPTIONS.errorEmail.split(',') : undefined;
let completionNote = Util.OPTIONS.completionNote;
let errorNote = Util.OPTIONS.errorNote;
let completionEmail = '',
errorEmail = '',
completionNote = '',
errorNote = '';
if (Util.OPTIONS.completionEmail) {
completionEmail = Util.OPTIONS.completionEmail.split(',');
}
if (Util.OPTIONS.errorEmail) {
errorEmail = Util.OPTIONS.errorEmail.split(',');
}
if (Util.OPTIONS.completionNote) {
completionNote = Util.OPTIONS.completionNote.split(',');
}
if (Util.OPTIONS.errorNote) {
errorNote = Util.OPTIONS.errorNote.split(',');
}
const updatedKeys = [];
let notificationsResult;
const automationLegacyMapObj = await this.#getEncodedAutomationIDs(); // retrieve automation legacy keys to update notifications
Expand Down Expand Up @@ -1674,15 +1684,15 @@ class Automation extends MetadataType {
else if (
notificationsResult.workers.find(
(notification) =>
(notification.notificationType === 'Complete' &&
(completionEmail !== notification.definition ||
Util.OPTIONS.completionNote !== notification.body)) ||
notificationsResult.workers.find(
(notification) =>
notification.notificationType === 'Error' &&
(errorEmail !== notification.definition ||
Util.OPTIONS.errorNote !== notification.body)
)
notification.notificationType === 'Complete' &&
(completionEmail != notification.definition ||
completionNote != notification.body)
) &&
notificationsResult.workers.find(
(notification) =>
notification.notificationType === 'Error' &&
errorEmail != notification.definition &&
errorNote != notification.body
)
) {
// create payload
Expand Down Expand Up @@ -1728,21 +1738,10 @@ class Automation extends MetadataType {
Util.logger.info(
` ☇ skipping automation '${key}' - email addresses provided and run notes are the same`
);
return;
}
}
return updatedKeys;
}
// const deployOrder = Util.getMetadataHierachy(metadataTypes);
// Util.logger.info(`Caching dependent Metadata: ${type}`);
// Util.logSubtypes(subTypeArr);
// result = await MetadataTypeInfo[type].retrieveForCache(null, subTypeArr);
// const retrieved = await this.retrieve('/retrieve', null, null, keys);
//const retrieved = await retriever.retrieve([this.definition.type], keys, null, false);
// console.log(retrieved);

//save updated automation
//this.saveResults(retrieved, this.retrieve, null, null);
return updatedKeys;
}
}

Expand Down
4 changes: 4 additions & 0 deletions lib/metadataTypes/MetadataType.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ class MetadataType {
if (!this.hasChanged(cachedVersion, metadataMap[metadataKey])) {
hasError = true;
}
if (Util.OPTIONS.completionEmail) {
metadataMap[metadataKey].sendEmailNotification = true;
metadataMap[metadataKey].notificationEmailAddress = Util.OPTIONS.completionEmail;
}
if (Util.OPTIONS.changeKeyField) {
if (this.definition.keyField == this.definition.idField) {
Util.logger.error(
Expand Down
6 changes: 0 additions & 6 deletions test/type.automation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,6 @@ describe('type: automation', () => {
'automation',
['testExisting_automation_updateNotifications']
);
// need to retrieve first (will be removed once the function updates the automation in retrieve dir)
await handler.retrieve(
'testInstance/testBU',
['automation'],
['testExisting_automation_updateNotifications']
);
assert.equal(
process.exitCode,
false,
Expand Down

0 comments on commit 24543f0

Please sign in to comment.