Skip to content

Commit

Permalink
fix: update slack home with slackTeams collection
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Oct 1, 2021
1 parent 708ddb2 commit d6f57d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/index-node12-dev.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index-node12.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions src/slack/home.ts
Expand Up @@ -213,9 +213,22 @@ export const createSlackHomeWorker = (mongoStores: MongoStores) => {
const scheduleUpdateOrg = async (
github: Octokit,
org: Org,
slackClient = new WebClient(org.slackToken),
): Promise<void> => {
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);
});
Expand All @@ -226,7 +239,7 @@ export const createSlackHomeWorker = (mongoStores: MongoStores) => {
): Promise<void> => {
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);
});
Expand Down

0 comments on commit d6f57d6

Please sign in to comment.