Skip to content

Commit

Permalink
Add decision link in email template (#1102)
Browse files Browse the repository at this point in the history
* add decision link in email template

* Update assets/mail-templates/failure.txt

Co-authored-by: Denis Ah-Kang <deniak@users.noreply.github.com>

* Update assets/mail-templates/success.txt

Co-authored-by: Denis Ah-Kang <deniak@users.noreply.github.com>

Co-authored-by: Denis Ah-Kang <deniak@users.noreply.github.com>
  • Loading branch information
jennyliang220 and deniak authored Nov 22, 2022
1 parent a74a261 commit 637b1a4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const processRequest = (req, res, isTar) => {
requests[id],
url || tar.originalname,
ccEmail,
decision,
);
}
})
Expand Down
2 changes: 1 addition & 1 deletion assets/mail-templates/failure.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
✗ Echidna failed to publish @SOURCE
✗ Echidna failed to publish @SOURCE (decision: @DECISION)
for the following reasons:

@ERRORS
Expand Down
2 changes: 2 additions & 0 deletions assets/mail-templates/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

👍 @DESTINATION

Decision: @DECISION

More details are available here@ATTACHMENT:

https://labs.w3.org/echidna/api/status?id=@ID
Expand Down
16 changes: 9 additions & 7 deletions lib/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const fields = [
'SOURCE',
'ENCODEDSOURCE',
'ERRORS',
'DECISION',
];
const pubrulesInstance = 'https://www.w3.org/pubrules/doc/rules/?profile=';

Expand Down Expand Up @@ -81,7 +82,7 @@ const formatErrors = (s, profile) => {
return result;
};

const extractFields = (s, json) => {
const extractFields = (s, json, decision) => {
const R = s ? s.results : null;
const M = R ? R.get('metadata') : null;
const regex = /.*\/([^/]+)\/$/;
Expand Down Expand Up @@ -117,20 +118,21 @@ const extractFields = (s, json) => {
SOURCE: source,
ENCODEDSOURCE: encodeSource,
ERRORS: formatErrors(json, s.results ? M.get('profile') : null),
DECISION: decision,
};
};

const interpolateTemplate = (t, v) => {
let result = t;

console.log(`interpolate before: ${t}`);
console.log(`interpolate before: \n${t}`);

fields.every(f => {
result = result.replace(new RegExp(`@${f}`, 'gi'), v[f]);
return true;
});

console.log(`interpolate after: ${result}`);
console.log(`\n\ninterpolate after: \n${result}`);
return result;
};

Expand Down Expand Up @@ -164,13 +166,13 @@ const composeSubject = (success, state, url) => {
return result;
};

const composeTextBody = (success, state, json) => {
const composeTextBody = (success, state, json, decision) => {
let result;

if (success) result = templateTextSuccess;
else result = templateTextFailure;

result = interpolateTemplate(result, extractFields(json, state));
result = interpolateTemplate(result, extractFields(json, state, decision));

return result;
};
Expand All @@ -184,7 +186,7 @@ const composeTextBody = (success, state, json) => {
* @param url - URL (or TAR filename) that was to be published.
*/

const sendMessage = (id, state, json, url, ccEmail) => {
const sendMessage = (id, state, json, url, ccEmail, decision) => {
const success = Orchestrator.STATUS_SUCCESS === state.get('status');
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email#Basic_validation
const re =
Expand All @@ -200,7 +202,7 @@ const sendMessage = (id, state, json, url, ccEmail) => {
from: global.MAIL_SENDER,
to: global.MAILING_LIST + additionalEmails,
subject: composeSubject(success, state, url),
text: composeTextBody(success, state, json),
text: composeTextBody(success, state, json, decision),
replyTo: global.MAIL_REPLYTO,
};

Expand Down

0 comments on commit 637b1a4

Please sign in to comment.