fixed linting error

This commit is contained in:
Wyatt Johnson
2018-02-27 15:23:29 -07:00
parent 91b11c838b
commit cdd77339b0
2 changed files with 18 additions and 15 deletions
@@ -5,7 +5,9 @@ const config = {
if (process.env.NODE_ENV !== 'test' && !config.SLACK_WEBHOOK_URL) {
// TODO this error should point users to Talk's Slack app once that's in place
throw new Error('Please set the TALK_SLACK_WEBHOOK_URL environment variable to use the slack-notifications plugin.');
throw new Error(
'Please set the TALK_SLACK_WEBHOOK_URL environment variable to use the slack-notifications plugin.'
);
}
module.exports = config;
@@ -1,5 +1,5 @@
const fetch = require('node-fetch');
const {SLACK_WEBHOOK_URL, SLACK_WEBHOOK_TIMEOUT} = require('./config');
const { SLACK_WEBHOOK_URL, SLACK_WEBHOOK_TIMEOUT } = require('./config');
const debug = require('debug')('talk:plugin:slack-notifications');
// We don't add the hooks during _test_ as the Slack API is not available.
@@ -10,14 +10,9 @@ if (process.env.NODE_ENV === 'test') {
module.exports = {
RootMutation: {
createComment: {
async post(_, {input}, context, _info, result) {
async post(root, args, context, info, result) {
debug(`Posting notification to Slack webhook: ${SLACK_WEBHOOK_URL}`);
const {
comment: {
body: text,
created_at: createdAt
}
} = result;
const { comment: { body: text, created_at: createdAt } } = result;
const username = context.user.username;
process.nextTick(async () => {
const response = await fetch(SLACK_WEBHOOK_URL, {
@@ -27,16 +22,22 @@ module.exports = {
},
timeout: SLACK_WEBHOOK_TIMEOUT,
body: JSON.stringify({
attachments: [{
text: text,
footer: `Comment by ${username}`,
ts: Math.floor(Date.parse(createdAt) / 1000),
}]
attachments: [
{
text: text,
footer: `Comment by ${username}`,
ts: Math.floor(Date.parse(createdAt) / 1000),
},
],
}),
});
if (!response.ok) {
const responseText = await response.text();
console.trace(`Posting to Slack failed with HTTP code ${response.status} and body '${responseText}'`);
console.trace(
`Posting to Slack failed with HTTP code ${
response.status
} and body '${responseText}'`
);
}
});
return result;