11import dotenv from 'dotenv' ;
22import express from 'express' ;
33
4+ import { implementDeploymentService } from './infrastructures/implementDeploymentService' ;
45import { implementSlackEventService } from './infrastructures/implementSlackEventService' ;
56import { implementSlackHttpClient } from './infrastructures/implementSlackHttpClient' ;
67
@@ -9,10 +10,12 @@ dotenv.config({ path: '.env.local' });
910const slackAuthToken = process . env . SLACK_AUTH_TOKEN ;
1011const slackBotToken = process . env . SLACK_BOT_TOKEN ;
1112const slackWatcherChannelId = process . env . SLACK_WATCHER_CHANNEL_ID ;
13+ const deployWatcherChannelId = process . env . DEPLOY_WATCHER_CHANNEL_ID ;
1214
1315if ( ! slackAuthToken ) throw new Error ( 'Missing Slack Auth Token' ) ;
1416if ( ! slackBotToken ) throw new Error ( 'Missing Slack Bot Token' ) ;
1517if ( ! slackWatcherChannelId ) throw new Error ( 'Missing Slack Watcher Channel ID' ) ;
18+ if ( ! deployWatcherChannelId ) throw new Error ( 'Missing Deploy Watcher Channel ID' ) ;
1619
1720const PORT = 3000 ;
1821const app = express ( ) ;
@@ -25,11 +28,18 @@ const app = express();
2528██████╔╝███████╗██║ ███████╗██║ ╚████║██████╔╝███████╗██║ ╚████║╚██████╗██║███████╗███████║
2629╚═════╝ ╚══════╝╚═╝ ╚══════╝╚═╝ ╚═══╝╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝╚═╝╚══════╝╚══════╝
2730 */
28- const slackClient = implementSlackHttpClient ( {
29- external : { slackAuthToken } ,
30- channelId : slackWatcherChannelId ,
31+ const slackService = implementSlackEventService ( {
32+ slackClient : implementSlackHttpClient ( {
33+ external : { slackAuthToken } ,
34+ channelId : slackWatcherChannelId ,
35+ } ) ,
36+ } ) ;
37+ const deploymentService = implementDeploymentService ( {
38+ slackClient : implementSlackHttpClient ( {
39+ external : { slackAuthToken } ,
40+ channelId : deployWatcherChannelId ,
41+ } ) ,
3142} ) ;
32- const slackService = implementSlackEventService ( { slackClient } ) ;
3343
3444/**
3545██████╗ ███████╗ ██████╗██╗ █████╗ ██████╗ ███████╗
@@ -56,6 +66,15 @@ app.post('/slack/action-endpoint', express.json(), (req, res) => {
5666 }
5767} ) ;
5868
69+ app . post ( '/github/webhook-endpoint' , express . json ( ) , async ( req , res ) => {
70+ if ( 'release' in req . body && req . body . action === 'released' ) await deploymentService . handleCreateRelease ( req . body ) ;
71+ if ( 'workflow_run' in req . body && req . body . action === 'requested' )
72+ await deploymentService . handleActionStart ( req . body ) ;
73+ if ( 'workflow_run' in req . body && req . body . action === 'completed' )
74+ await deploymentService . handleActionComplete ( req . body ) ;
75+ res . sendStatus ( 200 ) ;
76+ } ) ;
77+
5978/**
6079███████╗████████╗ █████╗ ██████╗ ████████╗
6180██╔════╝╚══██╔══╝██╔══██╗██╔══██╗╚══██╔══╝
0 commit comments