Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/actions/handleGithubComment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

const axios = require('axios');
const config = require('../../.config')
module.exports = ({task, conn}) => async function handleGithubComment(params) {
Comment thread
IslandRhythms marked this conversation as resolved.
const {Subscriber} = conn.models;

const {comment, issue} = params;
const orgs = await axios.get(comment.user['organizations_url']).then(res => res.data);
Comment thread
IslandRhythms marked this conversation as resolved.
Outdated
const orgNames = orgs.map(org => org.login);
const orgIds = orgs.map(org => org.id);
const subscriber = await Subscriber.findOne({
$or: [
{ githubUsername: comment.user.login },
{ githubUserId: comment.user.id.$numberInt },
{ githubOrganization: { $in: orgNames } },
{ githubOrganizationId: { $in: orgIds } },
{ 'githubOrganizationMembers.login': comment.user.login },
{ 'githubOrganizationMembers.id': comment.user.id.$numberInt }
Comment thread
IslandRhythms marked this conversation as resolved.
Outdated
]
});

if (subscriber == null) {
return { ok: 1 };
}
await task.log('subscriber commented on issue');

// Send to Slack
const url = 'https://slack.com/api/chat.postMessage';
Comment thread
IslandRhythms marked this conversation as resolved.
Outdated
await axios.post(url, {
channel: '#pro-notifications',
blocks: [
{type: 'divider'},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `*COMMENT CREATED ON ISSUE!* \n\n ${comment.user.login} has posted a comment on issue: *${issue.title}*, ${issue.html_url}`
}
},
{type: 'divider'},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `*DESCRIPTION* \n\n ${comment.body}`
}
},
]
}, { headers: { authorization: `Bearer ${config.slackToken}` } });
}
15 changes: 13 additions & 2 deletions webhookGitHubComment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const createReleaseFromChangelog = require('../src/actions/createReleaseFromChan
const { createTokenAuth } = require('@octokit/auth-token');
const config = require('../.config');
const connect = require('../src/db');
const handleGithubComment = require('../src/actions/handleGithubComment');

const ignoreUsers = new Set(config.ignoreUsers);

Expand All @@ -22,7 +23,7 @@ module.exports = azureWrapper(async function webhookGitHubComment(context, req)

const { token } = await createTokenAuth(config.githubAccessTokenForMongoose)();

const { action, issue, sender, ref, ref_type } = req.body;
const { action, issue, sender, ref, ref_type, comment } = req.body;

await task.log(`Action: ${action}`);

Expand Down Expand Up @@ -69,7 +70,7 @@ module.exports = azureWrapper(async function webhookGitHubComment(context, req)
type: 'section',
text: {
type: 'mrkdwn',
text: `*NEW ISSUE CREATED!* \n\n ${issue.user.login} has posted an issue titled: ${issue.title}`
text: `*NEW ISSUE CREATED!* \n\n ${issue.user.login} has posted an issue titled: *${issue.title}*, Link: ${issue.html_url}`
}
},
{type: 'divider'},
Expand All @@ -82,6 +83,16 @@ module.exports = azureWrapper(async function webhookGitHubComment(context, req)
},
]
}, { headers: { authorization: `Bearer ${config.slackToken}` } });
} else if (action === 'created') {
Comment thread
IslandRhythms marked this conversation as resolved.
Outdated

if (ignoreUsers.has(comment.user.login)) {
return { ok: 1 };
}

await task.log('comment on issue');

await handleGithubComment({task, conn})(req.body)

} else if (ref != null && ref_type === 'tag') {
// Assume tag was created, so create a release
await createReleaseFromChangelog(task)(ref);
Expand Down