Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Uses Basic Authentication
// Jira Doc: https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-basic-authentication
// Request (Promise) Doc: https://github.com/request/request#http-authentication
return rp({
auth: {
'user': user,
'pass': pass
},
method: 'POST',
uri: url,
body: newIssue,
json: true
});
};
exports.createNewIssue = functions.crashlytics.issue().onNewDetected(event => {
const data = event.data;
const issueId = data.issueId;
const issueTitle = data.issueTitle;
const appName = data.appInfo.appName;
const appId = data.appInfo.appId;
const appPlatform = data.appInfo.appPlatform;
const latestAppVersion = data.appInfo.latestAppVersion;
const summary = `New Issue - ${issueId} in ${appName} on $(appPlatform)`;
const description = `There is a new issue - ${issueTitle} in ${appId}, ` +
`version ${latestAppVersion}`;
const priority = calculateIssuePriority();
return createJiraIssue(summary, description, priority).then(() => {
console.log(`Created issue ${issueId} in Jira successfully`);
});
// Helper function that posts to Slack about the new issue
function notifySlack(slackMessage) {
// See https://api.slack.com/docs/message-formatting on how
// to customize the message payload
return rp({
method: 'POST',
uri: functions.config().slack.webhook_url,
body: {
text: slackMessage,
},
json: true,
});
}
exports.postOnNewIssue = functions.crashlytics.issue().onNew(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
const appPlatform = issue.appInfo.appPlatform;
const latestAppVersion = issue.appInfo.latestAppVersion;
const slackMessage = ` There is a new issue - ${issueTitle} (${issueId}) ` +
`in ${appName}, version ${latestAppVersion} on ${appPlatform}`;
await notifySlack(slackMessage);
console.log(`Posted new issue ${issueId} successfully to Slack`);
});
exports.postOnRegressedIssue = functions.crashlytics.issue().onRegressed(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const functions = require('firebase-functions'),
sendgridMail = require('@sendgrid/mail');
// Authentication for the SendGrid account
sendgridMail.setApiKey(functions.config().sendgrid.api_key);
exports.sendOnNewIssue = functions.crashlytics.issue().onNewDetected(event => {
const data = event.data;
const issueId = data.issueId;
const issueTitle = data.issueTitle;
const appName = data.appInfo.appName;
const appId = data.appInfo.appId;
const appPlatform = data.appInfo.appPlatform;
const latestAppVersion = data.appInfo.latestAppVersion;
const createTime = data.createTime;
const emailDetails = {
to: functions.config().email.destination_email,
from: functions.config().email.from_email,
subject: `${appName} on ${appPlatform} has a new issue`,
html: `<h2>${appName} on ${appPlatform} has a new issue!</h2>
<p>App Name: ${appName}</p>
<p>App Id: ${appId}</p>
<p>Platform: ${appPlatform}</p>
<p>Version: ${latestAppVersion}</p>
<p>Issue Id: ${issueId}</p>
<p>Issue Title: ${issueTitle}</p>
<p>Creation Time: ${createTime}</p>`
};
return sendgridMail.send(emailDetails).then(() => {
console.log('Successfully sent new issue email');
}).catch(error => {
console.error(error.toString());
});
});
exports.sendOnRegressedIssue = functions.crashlytics.issue().onRegressed(event => {
const data = event.data;
const issueId = data.issueId;
const issueTitle = data.issueTitle;
const appName = data.appInfo.appName;
const appId = data.appInfo.appId;
const appPlatform = data.appInfo.appPlatform;
const latestAppVersion = data.appInfo.latestAppVersion;
const createTime = data.createTime;
const resolvedTime = data.resolvedTime;
const emailDetails = {
to: functions.config().email.destination_email,
from: functions.config().email.from_email,
subject: `${appName} on ${appPlatform} has a regressed issue`,
html: `<h2>${appName} on ${appPlatform} has a regressed issue!</h2>
const issueTitle = data.issueTitle;
const appName = data.appInfo.appName;
const appId = data.appInfo.appId;
const appPlatform = data.appInfo.appPlatform;
const latestAppVersion = data.appInfo.latestAppVersion;
const summary = `New Issue - ${issueId} in ${appName} on $(appPlatform)`;
const description = `There is a new issue - ${issueTitle} in ${appId}, ` +
`version ${latestAppVersion}`;
const priority = calculateIssuePriority();
return createJiraIssue(summary, description, priority).then(() => {
console.log(`Created issue ${issueId} in Jira successfully`);
});
});
exports.createRegressedIssue = functions.crashlytics.issue().onRegressed(event => {
const data = event.data;
const issueId = data.issueId;
const issueTitle = data.issueTitle;
const appName = data.appInfo.appName;
const appId = data.appInfo.appId;
const appPlatform = data.appInfo.appPlatform;
const latestAppVersion = data.appInfo.latestAppVersion;
const resolvedTime = data.resolvedTime;
const summary = `Regressed Issue - ${issueId} in ${appName} on $(appPlatform)`;
const description = `There is a regressed issue - ${issueTitle} in ${appId}, ` +
`version ${latestAppVersion}. This issue was previously resolved at ` +
`${new Date(resolvedTime).toString()}`;
const priority = calculateIssuePriority('regressed');
return createJiraIssue(summary, description, priority).then(() => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
const appPlatform = issue.appInfo.appPlatform;
const latestAppVersion = issue.appInfo.latestAppVersion;
const resolvedTime = issue.resolvedTime;
const slackMessage = ` There is a regressed issue ${issueTitle} (${issueId}) ` +
`in ${appName}, version ${latestAppVersion} on ${appPlatform}. This issue was previously ` +
`resolved at ${new Date(resolvedTime).toString()}`;
await notifySlack(slackMessage);
console.log(`Posted regressed issue ${issueId} successfully to Slack`);
});
exports.postOnVelocityAlert = functions.crashlytics.issue().onVelocityAlert(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
const appPlatform = issue.appInfo.appPlatform;
const latestAppVersion = issue.appInfo.latestAppVersion;
const crashPercentage = issue.velocityAlert.crashPercentage;
const slackMessage = ` There is an issue ${issueTitle} (${issueId}) ` +
`in ${appName}, version ${latestAppVersion} on ${appPlatform} that is causing ` +
`${parseFloat(crashPercentage).toFixed(2)}% of all sessions to crash.`;
await notifySlack(slackMessage);
console.log(`Posted velocity alert ${issueId} successfully to Slack`);
});