@@ -11,10 +11,13 @@ import { releaseHandler } from "./handlers/release.ts";
1111const config = loadConfig ( ) ;
1212const port = parseInt ( process . env . PORT || "3000" , 10 ) ;
1313
14- const connection : SlashworkConnection = {
15- graphqlUrl : config . slashwork . graphqlUrl ,
16- authToken : config . slashwork . authToken ,
17- } ;
14+ function connectionForRoute ( routeName : string ) : SlashworkConnection {
15+ const route = config . routes [ routeName ] ! ;
16+ return {
17+ graphqlUrl : config . slashwork . graphqlUrl ,
18+ authToken : route . authToken ,
19+ } ;
20+ }
1821
1922const handlers : Record < EventType , EventHandler > = {
2023 pull_request : pullRequestHandler ,
@@ -28,7 +31,9 @@ function log(level: string, message: string) {
2831 console . log ( `[${ new Date ( ) . toISOString ( ) } ] [${ level } ] ${ message } ` ) ;
2932}
3033
31- async function handleWebhook ( req : Request , groupId : string ) : Promise < Response > {
34+ async function handleWebhook ( req : Request , routeName : string ) : Promise < Response > {
35+ const route = config . routes [ routeName ] ! ;
36+ const connection = connectionForRoute ( routeName ) ;
3237 if ( req . method !== "POST" ) {
3338 return new Response ( "Method not allowed" , { status : 405 } ) ;
3439 }
@@ -76,7 +81,7 @@ async function handleWebhook(req: Request, groupId: string): Promise<Response> {
7681
7782 try {
7883 const { markdown } = handler . format ( payload ) ;
79- await postToSlashwork ( connection , groupId , markdown ) ;
84+ await postToSlashwork ( connection , route . groupId , markdown ) ;
8085 log ( "info" , `Posted ${ eventType } event: ${ payload . action ?? "n/a" } ` ) ;
8186 } catch ( err ) {
8287 log ( "error" , `Failed to post to Slashwork: ${ err } ` ) ;
@@ -102,7 +107,7 @@ Bun.serve({
102107 log ( "warn" , `No route configured for: ${ name } ` ) ;
103108 return new Response ( "Not found" , { status : 404 } ) ;
104109 }
105- return handleWebhook ( req , route . groupId ) ;
110+ return handleWebhook ( req , name ) ;
106111 }
107112
108113 return new Response ( "Not found" , { status : 404 } ) ;
@@ -113,9 +118,12 @@ const routeNames = Object.keys(config.routes);
113118log ( "info" , `Server running on port ${ port } ` ) ;
114119log ( "info" , `Routes: ${ routeNames . map ( n => `/github/${ n } ` ) . join ( ", " ) } ` ) ;
115120log ( "info" , `Slashwork URL: ${ config . slashwork . graphqlUrl } ` ) ;
116- log ( "info" , `Auth token loaded: ${ config . slashwork . authToken . slice ( 0 , 8 ) } ...` ) ;
117121
118- validateConnection ( connection ) . then (
119- ( ) => log ( "info" , "Slashwork auth validated" ) ,
120- ( err ) => log ( "error" , `${ err } ` ) ,
121- ) ;
122+ for ( const name of routeNames ) {
123+ const conn = connectionForRoute ( name ) ;
124+ log ( "info" , `Route ${ name } : token ${ conn . authToken . slice ( 0 , 8 ) } ...` ) ;
125+ validateConnection ( conn ) . then (
126+ ( ) => log ( "info" , `Route ${ name } : auth validated` ) ,
127+ ( err ) => log ( "error" , `Route ${ name } : ${ err } ` ) ,
128+ ) ;
129+ }
0 commit comments