Skip to content

Commit cb496b3

Browse files
authored
๐Ÿ”ฅ openai summarize ๊ธฐ๋Šฅ ์ œ๊ฑฐ (#105)
๋ˆ๋“ค์–ด์„œ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
1 parent 6e2ab36 commit cb496b3

11 files changed

Lines changed: 3 additions & 156 deletions

File tree

โ€Ž.github/workflows/deploy.ymlโ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
3737
--build-arg SLACK_BOT_TOKEN=${{ secrets.SLACK_BOT_TOKEN }} \
3838
--build-arg SLACK_AUTH_TOKEN=${{ secrets.SLACK_AUTH_TOKEN }} \
39-
--build-arg OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \
4039
--build-arg "MONGODB_URI=${{ secrets.MONGODB_URI }}" \
4140
--build-arg SLACK_WATCHER_CHANNEL_ID=C050TMDUSTA \
4241
--build-arg DEPLOY_WATCHER_CHANNEL_ID=C06H0PJPDNH \

โ€ŽDockerfileโ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ ARG SLACK_BOT_TOKEN
1414
ARG SLACK_AUTH_TOKEN
1515
ARG SLACK_WATCHER_CHANNEL_ID
1616
ARG DEPLOY_WATCHER_CHANNEL_ID
17-
ARG OPENAI_API_KEY
1817
ARG MONGODB_URI
1918

2019
COPY --from=builder /app/dist /app/dist
@@ -24,7 +23,6 @@ RUN echo "SLACK_BOT_TOKEN=${SLACK_BOT_TOKEN}" >> .env.local
2423
RUN echo "SLACK_AUTH_TOKEN=${SLACK_AUTH_TOKEN}" >> .env.local
2524
RUN echo "SLACK_WATCHER_CHANNEL_ID=${SLACK_WATCHER_CHANNEL_ID}" >> .env.local
2625
RUN echo "DEPLOY_WATCHER_CHANNEL_ID=${DEPLOY_WATCHER_CHANNEL_ID}" >> .env.local
27-
RUN echo "OPENAI_API_KEY=${OPENAI_API_KEY}" >> .env.local
2826
RUN echo "MONGODB_URI=${MONGODB_URI}" >> .env.local
2927

3028
EXPOSE 3000

โ€ŽREADME.mdโ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ SLACK_WATCHER_CHANNEL_ID=C051TJXA7UZ
4040
DEPLOY_WATCHER_CHANNEL_ID=C051TJXA7UZ
4141
SLACK_WEEKLY_CHANNEL_ID=C051TJXA7UZ
4242
GITHUB_ORGANIZATION=wafflestudio
43-
OPENAI_API_KEY=sk-...
4443
MONGODB_URI=mongodb+srv://...
4544
```
4645

โ€Žbun.lockโ€Ž

Lines changed: 0 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

โ€Žpackage.jsonโ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"@slack/web-api": "7.8.0",
2222
"mongodb": "6.14.2",
2323
"octokit": "4.1.2",
24-
"openai": "4.87.3",
2524
"zod": "3.24.2"
2625
},
2726
"devDependencies": {

โ€Žsrc/infrastructures/implementOpenAiSummarizeRepository.tsโ€Ž

Lines changed: 0 additions & 34 deletions
This file was deleted.

โ€Žsrc/main.test.tsโ€Ž

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const env: Env = {
1616
const mockChannel = 'C0101010101';
1717
const mockTs = randomUUIDv7();
1818
const mockPermalink = randomUUIDv7();
19-
const mockOpenaiContent = randomUUIDv7();
2019
const mockSlackPostMessage = mock(() => {
2120
return Promise.resolve({ ts: mockTs } as ChatPostMessageResponse);
2221
});
@@ -39,9 +38,6 @@ const mockMongoDbCollection = mock(() => {
3938
const mockMongoDb = mock(() => {
4039
return { collection: mockMongoDbCollection };
4140
});
42-
const mockOpenaiCreate = mock(() => {
43-
return { choices: [{ message: { content: mockOpenaiContent } }] };
44-
});
4541
const mockWadotListUsers = mock(() => {
4642
return Promise.resolve([
4743
{ slack_id: 'QWER', github_id: 'qwer' },
@@ -54,7 +50,6 @@ const flush = () => new Promise((r) => setTimeout(() => r(null), 100));
5450

5551
const deps = {
5652
slackClient: { postMessage: mockSlackPostMessage, getPermalink: mockSlackGetPermalink },
57-
openaiClient: { create: mockOpenaiCreate },
5853
mongoClient: { db: mockMongoDb as unknown as Deps['mongoClient']['db'] },
5954
wadotClient: { listUsers: mockWadotListUsers },
6055
} as unknown as Deps;
@@ -67,7 +62,6 @@ const clearMocks = () => {
6762
mockMongoDbCollectionInsertMany.mockClear();
6863
mockMongoDbCollection.mockClear();
6964
mockMongoDb.mockClear();
70-
mockOpenaiCreate.mockClear();
7165
};
7266

7367
beforeEach(() => {
@@ -338,15 +332,13 @@ describe('github webhook endpoint', () => {
338332
test('should 400 on invalid', async () => {
339333
const result = await handle(deps, env, getRequest({ body: {} }));
340334
expect(deps.slackClient.postMessage).toBeCalledTimes(0);
341-
expect(deps.openaiClient.create).toBeCalledTimes(0);
342335
expect(result.status).toBe(400);
343336
expect(result.body).toBe(null);
344337
});
345338

346339
test('should ignore others', async () => {
347340
const result = await handle(deps, env, getRequest({ body: { action: '1234' } }));
348341
expect(deps.slackClient.postMessage).toBeCalledTimes(0);
349-
expect(deps.openaiClient.create).toBeCalledTimes(0);
350342
expect(result.status).toBe(200);
351343
expect(result.body).toBe(null);
352344
});
@@ -363,25 +355,10 @@ describe('github webhook endpoint', () => {
363355
repository: { name: randomUUIDv7() },
364356
};
365357
const releaseResult = await handle(deps, env, getRequest({ body: releaseBody }));
366-
expect(deps.openaiClient.create).toBeCalledTimes(1);
367-
expect(deps.openaiClient.create).toBeCalledWith({
368-
model: 'gpt-3.5-turbo',
369-
messages: [
370-
{
371-
role: 'system',
372-
content:
373-
'์ด ๋‚ด์šฉ์€ ๋ฐฐํฌ์— ์“ฐ์ด๋Š” ๋ฆด๋ฆฌ์ฆˆ ๋…ธํŠธ์•ผ. ๊ฐœ๋ฐœ์ž๋“ค์„ ์œ„ํ•ด 100์ž ์ด๋‚ด์˜ ํ•œ๊ธ€ ๋ฌธ์žฅ ํ•œ ๊ฐœ๋กœ ์š”์•ฝํ•ด์ค˜.',
374-
},
375-
{ role: 'user', content: releaseBody.release.body },
376-
],
377-
temperature: 0.7,
378-
max_tokens: 100,
379-
top_p: 1,
380-
});
381358
expect(deps.slackClient.postMessage).toBeCalledTimes(2);
382359
expect(deps.slackClient.postMessage).toHaveBeenNthCalledWith(1, {
383360
channel: env.deployWatcherChannelId,
384-
text: `:rocket: *${releaseBody.repository.name}/${releaseBody.release.tag_name}* <@QWER>\n\n${mockOpenaiContent}`,
361+
text: `:rocket: *${releaseBody.repository.name}/${releaseBody.release.tag_name}* <@QWER>`,
385362
thread_ts: undefined,
386363
});
387364
expect(deps.slackClient.postMessage).toHaveBeenNthCalledWith(2, {
@@ -407,7 +384,6 @@ describe('github webhook endpoint', () => {
407384
const workflowStartResult = await handle(deps, env, getRequest({ body: workflowStartBody }));
408385
expect(workflowStartResult.status).toBe(200);
409386
expect(workflowStartResult.body).toBe(null);
410-
expect(deps.openaiClient.create).toBeCalledTimes(0);
411387
expect(deps.slackClient.postMessage).toBeCalledTimes(1);
412388
expect(deps.slackClient.postMessage).toBeCalledWith({
413389
channel: env.deployWatcherChannelId,
@@ -421,51 +397,13 @@ describe('github webhook endpoint', () => {
421397
const workflowEndResult = await handle(deps, env, getRequest({ body: workflowEndBody }));
422398
expect(workflowEndResult.status).toBe(200);
423399
expect(workflowEndResult.body).toBe(null);
424-
expect(deps.openaiClient.create).toBeCalledTimes(0);
425400
expect(deps.slackClient.postMessage).toBeCalledTimes(1);
426401
expect(deps.slackClient.postMessage).toBeCalledWith({
427402
channel: env.deployWatcherChannelId,
428403
text: `:tada: deployment completed <${workflowEndBody.workflow_run.html_url}|${workflowEndBody.workflow_run.id}>`,
429404
thread_ts: mockTs,
430405
});
431406
});
432-
433-
test('failed to summarize', async () => {
434-
const releaseBody = {
435-
action: 'released',
436-
release: {
437-
author: { login: 'qwer' },
438-
body: randomUUIDv7(),
439-
tag_name: randomUUIDv7(),
440-
html_url: randomUUIDv7(),
441-
},
442-
repository: { name: randomUUIDv7() },
443-
};
444-
const releaseResult = await handle(
445-
{
446-
...deps,
447-
openaiClient: {
448-
create: () => {
449-
throw new Error('quota exceeded');
450-
},
451-
},
452-
},
453-
env,
454-
getRequest({ body: releaseBody }),
455-
);
456-
expect(releaseResult.status).toBe(200);
457-
expect(deps.slackClient.postMessage).toBeCalledTimes(2);
458-
expect(deps.slackClient.postMessage).toHaveBeenNthCalledWith(1, {
459-
channel: env.deployWatcherChannelId,
460-
text: `:rocket: *${releaseBody.repository.name}/${releaseBody.release.tag_name}* <@QWER>\n\n์š”์•ฝํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: quota exceeded`,
461-
thread_ts: undefined,
462-
});
463-
expect(deps.slackClient.postMessage).toHaveBeenNthCalledWith(2, {
464-
channel: env.deployWatcherChannelId,
465-
text: `:memo: <${releaseBody.release.html_url}|๋ฆด๋ฆฌ์ฆˆ ๋…ธํŠธ>\n\n\`\`\`${releaseBody.release.body}\`\`\``,
466-
thread_ts: mockTs,
467-
});
468-
});
469407
});
470408

471409
describe('status 500 on error', () => {

โ€Žsrc/main.tsโ€Ž

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ import type { SlackID } from './entities/Slack';
33
import { implementGitHubDeployWebhookController } from './infrastructures/implementGitHubDeployWebhookController';
44
import { implementMemberWaffleDotComRepository } from './infrastructures/implementMemberWaffleDotComRepository';
55
import { implementMongoAtlasWaffleRepository } from './infrastructures/implementMongoAtlasWaffleRepository';
6-
import { implementOpenAiSummarizeRepository } from './infrastructures/implementOpenAiSummarizeRepository';
76
import { implementSlackPresenter } from './infrastructures/implementSlackPresenter';
87
import { implementDeploymentService } from './services/GithubDeploymentService';
98
import { implementSlackEventService } from './services/SlackEventService';
109
import { implementWaffleService } from './services/WaffleService';
1110

1211
import type { MongoClient } from 'mongodb';
13-
import type OpenAI from 'openai';
1412
import { z } from 'zod';
1513

1614
export const handle = async (
1715
dependencies: {
1816
slackClient: Pick<WebClient['chat'], 'postMessage' | 'getPermalink'>;
19-
openaiClient: Pick<OpenAI['chat']['completions'], 'create'>;
2017
mongoClient: Pick<MongoClient, 'db'>;
2118
wadotClient: { listUsers: () => Promise<{ github_id: string; slack_id: string }[]> };
2219
},
@@ -59,7 +56,6 @@ export const handle = async (
5956
slackClient: dependencies.slackClient,
6057
channelId: env.deployWatcherChannelId,
6158
}),
62-
summarizeLLMRepository: implementOpenAiSummarizeRepository(dependencies),
6359
memberRepository: implementMemberWaffleDotComRepository(dependencies),
6460
}),
6561
});

0 commit comments

Comments
ย (0)