From d6f57d605878c6c018f6a101cffc7cba6ca7981f Mon Sep 17 00:00:00 2001 From: Christophe Hurpeau Date: Fri, 1 Oct 2021 18:11:43 +0200 Subject: [PATCH] fix: update slack home with slackTeams collection --- dist/index-node12-dev.cjs.js | 2 +- dist/index-node12.cjs.js | 2 +- src/slack/home.ts | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/dist/index-node12-dev.cjs.js b/dist/index-node12-dev.cjs.js index 46cb04caf..696186dd6 100644 --- a/dist/index-node12-dev.cjs.js +++ b/dist/index-node12-dev.cjs.js @@ -18,7 +18,7 @@ const slackifyMarkdown = require('slackify-markdown'); const parse$1 = require('@commitlint/parse'); const liwiMongo = require('liwi-mongo'); -function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; } +function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; } const cookieParser__default = /*#__PURE__*/_interopDefaultLegacy(cookieParser); const React__default = /*#__PURE__*/_interopDefaultLegacy(React); diff --git a/dist/index-node12.cjs.js b/dist/index-node12.cjs.js index 07e8b52de..64fa228c7 100644 --- a/dist/index-node12.cjs.js +++ b/dist/index-node12.cjs.js @@ -18,7 +18,7 @@ const slackifyMarkdown = require('slackify-markdown'); const parse$1 = require('@commitlint/parse'); const liwiMongo = require('liwi-mongo'); -function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; } +function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; } const cookieParser__default = /*#__PURE__*/_interopDefaultLegacy(cookieParser); const React__default = /*#__PURE__*/_interopDefaultLegacy(React); diff --git a/src/slack/home.ts b/src/slack/home.ts index 00a2d0862..6e8fff146 100644 --- a/src/slack/home.ts +++ b/src/slack/home.ts @@ -213,9 +213,22 @@ export const createSlackHomeWorker = (mongoStores: MongoStores) => { const scheduleUpdateOrg = async ( github: Octokit, org: Org, - slackClient = new WebClient(org.slackToken), ): Promise => { - const cursor = await mongoStores.orgMembers.cursor(); + if (!org.slackTeamId || !org.slackToken) return; + const [slackClient, cursor] = await Promise.all([ + org.slackToken + ? new WebClient(org.slackToken) + : mongoStores.slackTeams + .findByKey(org.slackTeamId) + .then((slackTeam) => { + if (!slackTeam || !slackTeam.botAccessToken) return undefined; + return new WebClient(slackTeam.botAccessToken); + }), + mongoStores.orgMembers.cursor(), + ]); + + if (!slackClient) return; + cursor.forEach((member) => { scheduleUpdateMember(github, slackClient, member); }); @@ -226,7 +239,7 @@ export const createSlackHomeWorker = (mongoStores: MongoStores) => { ): Promise => { const cursor = await mongoStores.orgs.cursor(); cursor.forEach(async (org) => { - if (!org.slackToken || !org.installationId) return; + if (!(org.slackToken || org.slackTeamId) || !org.installationId) return; const github = await auth(org.installationId); await scheduleUpdateOrg(github, org); });