Skip to content

Commit 7862914

Browse files
authored
Merge pull request #17 from ncdcdev/refactor/extract-src-and-add-tests
refactor: ソースコードをsrcに移動し疎結合化・テスト追加
2 parents 0f85ef6 + b18370e commit 7862914

28 files changed

Lines changed: 634 additions & 146 deletions

.github/workflows/_reusable_check.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- name: Biome Check
2626
run: npm run check
2727

28+
- name: Test
29+
run: npm test
30+
2831
- name: TypeCheck
2932
run: npm run typecheck
3033

.github/workflows/_reusable_lambda_rie_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- run: npm ci
1919

2020
- name: Bundle handler
21-
run: npx esbuild index.ts --bundle --platform=node --target=node24 --external:@slack/bolt --outfile=dist/index.js
21+
run: npx esbuild src/handler.ts --bundle --platform=node --target=node24 --external:@slack/bolt --outfile=dist/index.js
2222

2323
- name: Prepare Lambda artifact
2424
run: cp -R node_modules dist/

index.ts

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

infra/lib/times-all-bot-stack.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,26 @@ import * as iam from 'aws-cdk-lib/aws-iam';
66
import * as runtime from 'aws-cdk-lib/aws-lambda';
77
import * as lambda from 'aws-cdk-lib/aws-lambda-nodejs';
88
import type { Construct } from 'constructs';
9+
import { loadEnv } from '../../src/env.ts';
910

1011
export class TimesAllBotStack extends cdk.Stack {
1112
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
1213
super(scope, id, props);
1314

14-
const slackBotToken = process.env['SLACK_BOT_TOKEN'];
15-
if (!slackBotToken) throw new Error('SLACK_BOT_TOKEN is required');
16-
const slackSigningSecret = process.env['SLACK_SIGNING_SECRET'];
17-
if (!slackSigningSecret)
18-
throw new Error('SLACK_SIGNING_SECRET is required');
19-
const timesAllChannelId = process.env['TIMES_ALL_CHANNEL_ID'];
20-
if (!timesAllChannelId) throw new Error('TIMES_ALL_CHANNEL_ID is required');
21-
const workspaceUrl = process.env['WORKSPACE_URL'];
22-
if (!workspaceUrl) throw new Error('WORKSPACE_URL is required');
15+
const env = loadEnv();
2316

2417
const projectRoot = path.join(import.meta.dirname, '../..');
2518

2619
const fn = new lambda.NodejsFunction(this, 'SlackHandler', {
27-
entry: path.join(projectRoot, 'index.ts'),
20+
entry: path.join(projectRoot, 'src/handler.ts'),
2821
handler: 'handler',
2922
runtime: runtime.Runtime.NODEJS_24_X,
3023
timeout: cdk.Duration.seconds(30),
3124
environment: {
32-
SLACK_BOT_TOKEN: slackBotToken,
33-
SLACK_SIGNING_SECRET: slackSigningSecret,
34-
TIMES_ALL_CHANNEL_ID: timesAllChannelId,
35-
WORKSPACE_URL: workspaceUrl,
25+
SLACK_BOT_TOKEN: env.slackBotToken,
26+
SLACK_SIGNING_SECRET: env.slackSigningSecret,
27+
TIMES_ALL_CHANNEL_ID: env.timesAllChannelId,
28+
WORKSPACE_URL: env.workspaceUrl,
3629
},
3730
bundling: {
3831
nodeModules: ['@slack/bolt'],

infra/package-lock.json

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

infra/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"dependencies": {
1313
"aws-cdk-lib": "^2.245.0",
14-
"constructs": "^10.6.0"
14+
"constructs": "^10.6.0",
15+
"valibot": "^1.3.1"
1516
},
1617
"devDependencies": {
1718
"@tsconfig/strictest": "^2.0.8",

infra/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"types": ["node"],
1010
"resolveJsonModule": true
1111
},
12-
"include": ["bin/**/*.ts", "lib/**/*.ts"]
12+
"include": ["bin/**/*.ts", "lib/**/*.ts", "../src/env.ts"]
1313
}

joinBotToTimesChannels.ts

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

package-lock.json

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

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
"description": "repost times-* channel to \"time-all\"",
55
"type": "module",
66
"scripts": {
7-
"dev": "node --env-file=.env index.ts",
7+
"dev": "node --env-file=.env src/handler.ts",
88
"lint": "biome check --write .",
99
"format": "biome format .",
1010
"check": "biome check .",
11-
"typecheck": "tsc --noEmit"
11+
"typecheck": "tsc",
12+
"test": "node --test 'src/**/*.test.ts'"
1213
},
1314
"keywords": [],
1415
"author": "",
1516
"license": "ISC",
1617
"dependencies": {
17-
"@slack/bolt": "^4.6.0"
18+
"@slack/bolt": "^4.6.0",
19+
"valibot": "^1.3.1"
1820
},
1921
"devDependencies": {
2022
"@biomejs/biome": "2.4.9",

0 commit comments

Comments
 (0)