Skip to content

Commit

Permalink
node 버전업
Browse files Browse the repository at this point in the history
  • Loading branch information
woohm402 committed Jul 2, 2024
1 parent 0d9c6c9 commit ce5515a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/weekly-dashboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '20.11.1'
node-version: '20.15.0'
cache: 'yarn'

# cron job을 실행합니다.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"dependencies": {
"express": "4.19.2",
"octokit": "4.0.2",
"openai": "4.52.1"
"openai": "4.52.1",
"p-limit": "5.0.0"
},
"devDependencies": {
"@types/express": "4.17.21",
Expand Down
48 changes: 25 additions & 23 deletions src/infrastructures/implementMemberSlackRepository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pLimit from 'p-limit';

import { Member } from '../entities/Member';

export const implementMemberSlackRepository = ({
Expand All @@ -14,30 +16,30 @@ export const implementMemberSlackRepository = ({

if (!users.ok) throw new Error('Failed to fetch users');

const limit = pLimit(10);

const fetchMemberProfile = async (member: { id: string }) => {
const profile = await fetch(`https://slack.com/api/users.profile.get?user=${member.id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${slackAuthToken}` },
}).then(
(res) =>
res.json() as Promise<
{ ok: true; profile: { fields: { [githubField]?: { value: string } } } } | { ok: false }
>,
);

if (!profile.ok) throw new Error('Failed to fetch profile: ' + JSON.stringify(profile));

const githubUsername = profile.profile.fields[githubField]?.value;

if (!githubUsername) return [];

return [{ githubUsername: githubUsername.replace('https://github.com/', ''), slackUserId: member.id }];
};

return {
members: (
await Promise.all(
users.members.flatMap(async (member) => {
const profile = await fetch(`https://slack.com/api/users.profile.get?user=${member.id}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${slackAuthToken}` },
}).then(
(res) =>
res.json() as Promise<
{ ok: true; profile: { fields: { [githubField]?: { value: string } } } } | { ok: false }
>,
);

if (!profile.ok) throw new Error('Failed to fetch profile: ' + JSON.stringify(profile));

const githubUsername = profile.profile.fields[githubField]?.value;

if (!githubUsername) return [];

return [{ githubUsername: githubUsername.replace('https://github.com/', ''), slackUserId: member.id }];
}),
)
).flat(),
members: (await Promise.all(users.members.map((member) => limit(() => fetchMemberProfile(member))))).flat(),
};
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/services/DashboardService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const implementDashboardService = ({
return {
text: [
divider,
`${formatBold(`${formatEmoji('tada')} Top Contributors & Users Last Week`)} ${formatEmoji('blob-clap')}`,
`${formatBold(`${formatEmoji('tada')} Top Contributors & Repositories Last Week`)} ${formatEmoji('blob-clap')}`,
divider,

'\n',
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1901,20 +1901,20 @@ optionator@^0.9.3:
type-check "^0.4.0"
word-wrap "^1.2.5"

[email protected], p-limit@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-5.0.0.tgz#6946d5b7140b649b7a33a027d89b4c625b3a5985"
integrity sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ==
dependencies:
yocto-queue "^1.0.0"

p-limit@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==
dependencies:
yocto-queue "^0.1.0"

p-limit@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-5.0.0.tgz#6946d5b7140b649b7a33a027d89b4c625b3a5985"
integrity sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ==
dependencies:
yocto-queue "^1.0.0"

p-locate@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834"
Expand Down

0 comments on commit ce5515a

Please sign in to comment.