Skip to content

Commit

Permalink
Update crashlytics samples to Node 8
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasgarnier committed Aug 7, 2018
1 parent a566c62 commit 246e63b
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parserOptions": {
// Required for certain syntax usages
"ecmaVersion": 6
"ecmaVersion": 2017
},
"plugins": [
"promise"
Expand Down
33 changes: 18 additions & 15 deletions crashlytics-integration/email-notifier/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const sendgridMail = require('@sendgrid/mail');
// Authentication for the SendGrid account
sendgridMail.setApiKey(functions.config().sendgrid.api_key);

exports.sendOnNewIssue = functions.crashlytics.issue().onNew((issue) => {
exports.sendOnNewIssue = functions.crashlytics.issue().onNew(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
Expand All @@ -44,14 +44,15 @@ exports.sendOnNewIssue = functions.crashlytics.issue().onNew((issue) => {
<p>Creation Time: ${createTime}</p>`,
};

return sendgridMail.send(emailDetails).then(() => {
return console.log('Successfully sent new issue email');
}).catch((error) => {
try {
await sendgridMail.send(emailDetails);
console.log('Successfully sent new issue email');
} catch (error) {
console.error(error.toString());
});
}
});

exports.sendOnRegressedIssue = functions.crashlytics.issue().onRegressed((issue) => {
exports.sendOnRegressedIssue = functions.crashlytics.issue().onRegressed(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
Expand All @@ -76,14 +77,15 @@ exports.sendOnRegressedIssue = functions.crashlytics.issue().onRegressed((issue)
<p>Originally Resolved On: ${new Date(resolvedTime).toString()}</p>`,
};

return sendgridMail.send(emailDetails).then(() => {
return console.log('Successfully sent regressed issue email');
}).catch((error) => {
try {
await sendgridMail.send(emailDetails);
console.log('Successfully sent regressed issue email');
} catch(error) {
console.error(error.toString());
});
}
});

exports.sendOnVelocityAlert = functions.crashlytics.issue().onVelocityAlert((issue) => {
exports.sendOnVelocityAlert = functions.crashlytics.issue().onVelocityAlert(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
Expand All @@ -110,9 +112,10 @@ exports.sendOnVelocityAlert = functions.crashlytics.issue().onVelocityAlert((iss
<p># of Total Crashes: ${crashes.toString()}</p>`,
};

return sendgridMail.send(emailDetails).then(() => {
return console.log('Successfully sent velocity alert email');
}).catch((error) => {
try {
await sendgridMail.send(emailDetails);
console.log('Successfully sent velocity alert email');
} catch(error) {
console.error(error.toString());
});
}
});
7 changes: 5 additions & 2 deletions crashlytics-integration/email-notifier/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"firebase-admin": "~5.11.0",
"firebase-functions": "^1.0.0"
},
"private": true,
"devDependencies": {
"eslint": "^4.13.1",
"eslint-plugin-promise": "^3.6.0"
Expand All @@ -18,5 +17,9 @@
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
}
},
"engines": {
"node": "8"
},
"private": true
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parserOptions": {
// Required for certain syntax usages
"ecmaVersion": 6
"ecmaVersion": 2017
},
"plugins": [
"promise"
Expand Down
27 changes: 12 additions & 15 deletions crashlytics-integration/jira-issue/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const functions = require('firebase-functions');
const rp = require('request-promise');

// Helper function that calculates the priority of the issue
const calculateIssuePriority = (eventType) => {
function calculateIssuePriority(eventType) {
// Run custom logic that can determine the priority or severity of this issue
// For example, you can parse the stack trace to determine which part of your app
// is causing the crash and assign priorities based on that
Expand All @@ -44,7 +44,7 @@ const calculateIssuePriority = (eventType) => {

// Helper function that parses the Jira project url and returns an object
// of the url fragments
const parseUrl = (url) => {
function parseUrl(url) {
// input url format: https://yourdomain.atlassian.net/projects/XX
const matches = url.match(/(https?:\/\/)(.+?)(\/.+)?\/(projects|browse)\/([\w-]+)/);
if (matches && matches.length === 6) {
Expand All @@ -55,7 +55,7 @@ const parseUrl = (url) => {
};

// Helper function that posts to Jira to create a new issue
const createJiraIssue = (summary, description, priority) => {
function createJiraIssue(summary, description, priority) {
const project_url = functions.config().jira.project_url;
const user = functions.config().jira.user;
const pass = functions.config().jira.pass;
Expand Down Expand Up @@ -98,7 +98,7 @@ const createJiraIssue = (summary, description, priority) => {
});
};

exports.createNewIssue = functions.crashlytics.issue().onNew((issue) => {
exports.createNewIssue = functions.crashlytics.issue().onNew(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
Expand All @@ -110,12 +110,11 @@ exports.createNewIssue = functions.crashlytics.issue().onNew((issue) => {
const description = `There is a new issue - ${issueTitle} in ${appId}, ` +
`version ${latestAppVersion}`;
const priority = calculateIssuePriority();
return createJiraIssue(summary, description, priority).then(() => {
return console.log(`Created issue ${issueId} in Jira successfully`);
});
await createJiraIssue(summary, description, priority);
console.log(`Created issue ${issueId} in Jira successfully`);
});

exports.createRegressedIssue = functions.crashlytics.issue().onRegressed((issue) => {
exports.createRegressedIssue = functions.crashlytics.issue().onRegressed(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
Expand All @@ -129,12 +128,11 @@ exports.createRegressedIssue = functions.crashlytics.issue().onRegressed((issue)
`version ${latestAppVersion}. This issue was previously resolved at ` +
`${new Date(resolvedTime).toString()}`;
const priority = calculateIssuePriority('regressed');
return createJiraIssue(summary, description, priority).then(() => {
return console.log(`Created issue ${issueId} in Jira successfully`);
});
await createJiraIssue(summary, description, priority);
console.log(`Created issue ${issueId} in Jira successfully`);
});

exports.createVelocityAlert = functions.crashlytics.issue().onVelocityAlert((issue) => {
exports.createVelocityAlert = functions.crashlytics.issue().onVelocityAlert(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
Expand All @@ -148,7 +146,6 @@ exports.createVelocityAlert = functions.crashlytics.issue().onVelocityAlert((iss
`This issue is occuring in build version ${latestAppVersion} and is causing ` +
`${parseFloat(crashPercentage).toFixed(2)}% of all sessions to crash.`;
const priority = calculateIssuePriority('velocityAlert');
return createJiraIssue(summary, description, priority).then(() => {
return console.log(`Created issue ${issueId} in Jira successfully`);
});
await createJiraIssue(summary, description, priority);
console.log(`Created issue ${issueId} in Jira successfully`);
});
7 changes: 5 additions & 2 deletions crashlytics-integration/jira-issue/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"firebase-admin": "~5.11.0",
"firebase-functions": "^1.0.0"
},
"private": true,
"devDependencies": {
"eslint": "^4.13.1",
"eslint-plugin-promise": "^3.6.0"
Expand All @@ -19,5 +18,9 @@
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
}
},
"engines": {
"node": "8"
},
"private": true
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parserOptions": {
// Required for certain syntax usages
"ecmaVersion": 6
"ecmaVersion": 2017
},
"plugins": [
"promise"
Expand Down
23 changes: 10 additions & 13 deletions crashlytics-integration/slack-notifier/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const functions = require('firebase-functions');
const rp = require('request-promise');

// Helper function that posts to Slack about the new issue
const notifySlack = (slackMessage) => {
function notifySlack(slackMessage) {
// See https://api.slack.com/docs/message-formatting on how
// to customize the message payload
return rp({
Expand All @@ -32,7 +32,7 @@ const notifySlack = (slackMessage) => {
});
};

exports.postOnNewIssue = functions.crashlytics.issue().onNew((issue) => {
exports.postOnNewIssue = functions.crashlytics.issue().onNew(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
Expand All @@ -42,12 +42,11 @@ exports.postOnNewIssue = functions.crashlytics.issue().onNew((issue) => {
const slackMessage = `<!here|here> There is a new issue - ${issueTitle} (${issueId}) ` +
`in ${appName}, version ${latestAppVersion} on ${appPlatform}`;

return notifySlack(slackMessage).then(() => {
return console.log(`Posted new issue ${issueId} successfully to Slack`);
});
await notifySlack(slackMessage);
console.log(`Posted new issue ${issueId} successfully to Slack`);
});

exports.postOnRegressedIssue = functions.crashlytics.issue().onRegressed((issue) => {
exports.postOnRegressedIssue = functions.crashlytics.issue().onRegressed(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
Expand All @@ -59,12 +58,11 @@ exports.postOnRegressedIssue = functions.crashlytics.issue().onRegressed((issue)
`in ${appName}, version ${latestAppVersion} on ${appPlatform}. This issue was previously ` +
`resolved at ${new Date(resolvedTime).toString()}`;

return notifySlack(slackMessage).then(() => {
return console.log(`Posted regressed issue ${issueId} successfully to Slack`);
});
await notifySlack(slackMessage);
console.log(`Posted regressed issue ${issueId} successfully to Slack`);
});

exports.postOnVelocityAlert = functions.crashlytics.issue().onVelocityAlert((issue) => {
exports.postOnVelocityAlert = functions.crashlytics.issue().onVelocityAlert(async (issue) => {
const issueId = issue.issueId;
const issueTitle = issue.issueTitle;
const appName = issue.appInfo.appName;
Expand All @@ -76,7 +74,6 @@ exports.postOnVelocityAlert = functions.crashlytics.issue().onVelocityAlert((iss
`in ${appName}, version ${latestAppVersion} on ${appPlatform} that is causing ` +
`${parseFloat(crashPercentage).toFixed(2)}% of all sessions to crash.`;

return notifySlack(slackMessage)/then(() => {
console.log(`Posted velocity alert ${issueId} successfully to Slack`);
});
await notifySlack(slackMessage);
console.log(`Posted velocity alert ${issueId} successfully to Slack`);
});
7 changes: 5 additions & 2 deletions crashlytics-integration/slack-notifier/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"firebase-admin": "~5.11.0",
"firebase-functions": "^1.0.0"
},
"private": true,
"devDependencies": {
"eslint": "^4.13.1",
"eslint-plugin-promise": "^3.6.0"
Expand All @@ -19,5 +18,9 @@
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
}
},
"engines": {
"node": "8"
},
"private": true
}

0 comments on commit 246e63b

Please sign in to comment.