feat: add ability to send mails as output of a function

This commit is contained in:
Odonno 2017-10-07 11:29:37 +02:00
Родитель 78932f34a5
Коммит e2d98772f9
11 изменённых файлов: 105 добавлений и 28 удалений

Просмотреть файл

@ -7,9 +7,13 @@
"direction": "in"
},
{
"type": "http",
"name": "$return",
"type": "sendGrid",
"direction": "out",
"name": "$return"
"apiKey" : "SENDGRID_KEY",
"to": "nmetulev@microsoft.com",
"from": "nmetulev@microsoft.com",
"subject": "SendGrid output bindings"
}
]
}

Просмотреть файл

@ -42,7 +42,10 @@ module.exports = function (context) {
});
}
context.log(decisions);
functions_1.completeFunction(context, null, { status: 201, body: decisions });
functions_1.completeFunctionBySendingMail(context, [{ "to": [{ "email": "nmetulev@microsoft.com" }] }], { email: "sender@contoso.com" }, "No Activity On Issues", [{
type: 'text/plain',
value: JSON.stringify(decisions)
}]);
});
};
var detectNumberOfAlertsAlreadySent = function (botUsername, issue) {

Просмотреть файл

@ -1,5 +1,5 @@
import { addDays, distinct } from '../shared/utils';
import { completeFunction } from '../shared/functions';
import { completeFunctionBySendingMail } from '../shared/functions';
import { IssueNode } from '../shared/models';
import { getAllGitHubIssuesRecursively, commentGitHubIssue, closeGitHubIssue } from '../shared/github';
@ -74,7 +74,16 @@ module.exports = (context) => {
}
context.log(decisions);
completeFunction(context, null, { status: 201, body: decisions });
completeFunctionBySendingMail(
context,
[{ "to": [{ "email": "nmetulev@microsoft.com" }] }],
{ email: "sender@contoso.com" },
"No Activity On Issues",
[{
type: 'text/plain',
value: JSON.stringify(decisions)
}]
);
});
}

Просмотреть файл

@ -7,9 +7,13 @@
"direction": "in"
},
{
"type": "http",
"name": "$return",
"type": "sendGrid",
"direction": "out",
"name": "$return"
"apiKey" : "SENDGRID_KEY",
"to": "nmetulev@microsoft.com",
"from": "nmetulev@microsoft.com",
"subject": "SendGrid output bindings"
}
]
}

Просмотреть файл

@ -19,7 +19,10 @@ module.exports = function (context) {
});
}
context.log(issuesWithoutResponse);
functions_1.completeFunction(context, null, { status: 201, body: issuesWithoutResponse });
functions_1.completeFunctionBySendingMail(context, [{ "to": [{ "email": "nmetulev@microsoft.com" }] }], { email: "sender@contoso.com" }, "No Response From Community On Issues", [{
type: 'text/plain',
value: JSON.stringify(issuesWithoutResponse)
}]);
});
};
var detectIfNoResponseFromCommunity = function (issue, exclusiveLabels) {

Просмотреть файл

@ -1,5 +1,5 @@
import { addDays, distinct } from '../shared/utils';
import { completeFunction } from '../shared/functions';
import { completeFunctionBySendingMail } from '../shared/functions';
import { IssueNode } from '../shared/models';
import { getAllGitHubIssuesRecursively, commentGitHubIssue } from '../shared/github';
@ -30,7 +30,16 @@ module.exports = (context) => {
}
context.log(issuesWithoutResponse);
completeFunction(context, null, { status: 201, body: issuesWithoutResponse });
completeFunctionBySendingMail(
context,
[{ "to": [{ "email": "nmetulev@microsoft.com" }] }],
{ email: "sender@contoso.com" },
"No Response From Community On Issues",
[{
type: 'text/plain',
value: JSON.stringify(issuesWithoutResponse)
}]
);
});
};

Просмотреть файл

@ -8,4 +8,12 @@ exports.completeFunction = function (context, request, response) {
context.done();
}
};
exports.completeFunctionBySendingMail = function (context, personalizations, mailFrom, subject, content) {
context.done(null, {
personalizations: personalizations,
from: mailFrom,
subject: subject,
content: content
});
};
//# sourceMappingURL=functions.js.map

Просмотреть файл

@ -4,4 +4,13 @@ export const completeFunction = (context: any, request: any, response: any) => {
} else {
context.done();
}
}
export const completeFunctionBySendingMail = (context: any, personalizations: any[], mailFrom: { email: string }, subject: string, content: any) => {
context.done(null, {
personalizations: personalizations,
from: mailFrom,
subject: subject,
content: content
});
}

Просмотреть файл

@ -7,9 +7,13 @@
"direction": "in"
},
{
"type": "http",
"name": "$return",
"type": "sendGrid",
"direction": "out",
"name": "$return"
"apiKey" : "SENDGRID_KEY",
"to": "nmetulev@microsoft.com",
"from": "nmetulev@microsoft.com",
"subject": "SendGrid output bindings"
}
]
}

Просмотреть файл

@ -6,7 +6,7 @@ var github_1 = require("../shared/github");
module.exports = function (context, req) {
if (req.action !== 'closed' || !req.pull_request.merged) {
context.log('Only watch merged PR.');
functions_1.completeFunction(context, req, { status: 201, body: { success: false, message: 'Only watch merged PR.' } });
functions_1.completeFunction(context, null, { status: 201, body: { success: false, message: 'Only watch merged PR.' } });
return;
}
var githubApiHeaders = {
@ -25,18 +25,24 @@ module.exports = function (context, req) {
.filter(function (n) { return !!n; });
if (unclosedIssuesNumber.length <= 0) {
context.log('No linked issue detected.');
functions_1.completeFunction(context, req, { status: 201, body: { success: false, message: 'No unclosed issue linked to this merged PR.' } });
functions_1.completeFunctionBySendingMail(context, [{ "to": [{ "email": "nmetulev@microsoft.com" }] }], { email: "sender@contoso.com" }, "#" + pullRequestNumber + " PR merged - no linked issue", [{
type: 'text/plain',
value: 'No unclosed issue linked to this merged PR.'
}]);
return;
}
var linkedItemsMessagePart = unclosedIssuesNumber
.sort(function (a, b) { return a - b; })
.map(function (n) { return '#' + n; })
.join(', ');
if (process.env.GITHUB_BOT_UWP_TOOLKIT_ACTIVATE_MUTATION) {
var linkedItemsMessagePart = unclosedIssuesNumber
.sort(function (a, b) { return a - b; })
.map(function (n) { return '#' + n; })
.join(', ');
github_1.commentGitHubIssue(githubApiHeaders, pullRequest.id, "This PR is linked to unclosed issues. Please check if one of these issues should be closed: " + linkedItemsMessagePart);
}
context.log(unclosedIssuesNumber);
functions_1.completeFunction(context, req, { status: 201, body: { success: true, message: unclosedIssuesNumber } });
functions_1.completeFunctionBySendingMail(context, [{ "to": [{ "email": "nmetulev@microsoft.com" }] }], { email: "sender@contoso.com" }, "#" + pullRequestNumber + " PR merged - found linked issues", [{
type: 'text/plain',
value: "This PR is linked to unclosed issues. Please check if one of these issues should be closed: " + linkedItemsMessagePart
}]);
});
});
};

Просмотреть файл

@ -1,12 +1,12 @@
import { distinct } from '../shared/utils';
import { completeFunction } from '../shared/functions';
import { completeFunction, completeFunctionBySendingMail } from '../shared/functions';
import { PullRequestNode } from '../shared/models';
import { getPullRequest, getIssueOrPullRequestLinks, commentGitHubIssue } from '../shared/github';
module.exports = (context, req) => {
if (req.action !== 'closed' || !req.pull_request.merged) {
context.log('Only watch merged PR.');
completeFunction(context, req, { status: 201, body: { success: false, message: 'Only watch merged PR.' } })
completeFunction(context, null, { status: 201, body: { success: false, message: 'Only watch merged PR.' } })
return;
}
@ -38,17 +38,26 @@ module.exports = (context, req) => {
if (unclosedIssuesNumber.length <= 0) {
context.log('No linked issue detected.');
completeFunction(context, req, { status: 201, body: { success: false, message: 'No unclosed issue linked to this merged PR.' } });
completeFunctionBySendingMail(
context,
[{ "to": [{ "email": "nmetulev@microsoft.com" }] }],
{ email: "sender@contoso.com" },
`#${pullRequestNumber} PR merged - no linked issue`,
[{
type: 'text/plain',
value: 'No unclosed issue linked to this merged PR.'
}]
);
return;
}
const linkedItemsMessagePart = unclosedIssuesNumber
.sort((a, b) => a - b)
.map(n => '#' + n)
.join(', ');
if (process.env.GITHUB_BOT_UWP_TOOLKIT_ACTIVATE_MUTATION) {
// send a message with links to unclosed issues
const linkedItemsMessagePart = unclosedIssuesNumber
.sort((a, b) => a - b)
.map(n => '#' + n)
.join(', ');
commentGitHubIssue(
githubApiHeaders,
pullRequest.id,
@ -56,7 +65,16 @@ module.exports = (context, req) => {
}
context.log(unclosedIssuesNumber);
completeFunction(context, req, { status: 201, body: { success: true, message: unclosedIssuesNumber } });
completeFunctionBySendingMail(
context,
[{ "to": [{ "email": "nmetulev@microsoft.com" }] }],
{ email: "sender@contoso.com" },
`#${pullRequestNumber} PR merged - found linked issues`,
[{
type: 'text/plain',
value: `This PR is linked to unclosed issues. Please check if one of these issues should be closed: ${linkedItemsMessagePart}`
}]
);
});
});
}