Skip to content

Commit e829adc

Browse files
authored
Merge pull request #685 from keymanapp/chore/probot
chore: probot use must be before express.json
2 parents 98812c7 + 0f57910 commit e829adc

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

server/code.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ Sentry.init({
9191

9292
const debugTestBot = false;
9393

94-
if(debugTestBot) {
95-
testUserTestComment();
96-
}
94+
// if(debugTestBot) {
95+
// testUserTestComment();
96+
// }
9797

9898
const port = environment == Environment.Development ? 3000 : 80;
9999
const REFRESH_INTERVAL = environment == Environment.Development ? 180000 : 60000;
@@ -320,6 +320,9 @@ function sendInitialRefreshMessages(socket) {
320320

321321
/* Static Endpoints */
322322

323+
// must be before express.json()!
324+
app.use(keymanAppTestBotMiddleware); // '/webhook/keymanapp-test-bot', (request, response) => { keymanAppTestBotMiddleware(request, response); } );
325+
323326
app.use(express.json({ limit: '10mb' })); // for parsing application/json
324327

325328
app.use('/', express.static((environment == Environment.Development ? '' : '../') + '../../public/dist/public'));
@@ -365,8 +368,6 @@ app.post('/webhook/discourse', (request, response) => {
365368
response.send('ok');
366369
});
367370

368-
app.use('/webhook/keymanapp-test-bot', (request, response) => { keymanAppTestBotMiddleware(request, response); } );
369-
370371
export function sendWsAlert(hasChanged: boolean, message: string): boolean {
371372
if(hasChanged) {
372373
wsServer.clients.forEach((client) => {
@@ -620,7 +621,7 @@ app.all('/{*splat}', (request, response) => {
620621
// The error handler must be before any other error middleware and after all controllers
621622
// app.use(Sentry.Handlers.errorHandler());
622623

623-
if(!debugTestBot) {
624+
// if(!debugTestBot) {
624625
consoleLog('main', null, `Starting app listening on ${port}`);
625626
const server = app.listen(port);
626627

@@ -631,4 +632,4 @@ if(!debugTestBot) {
631632
wsServer.emit('connection', socket, request);
632633
});
633634
});
634-
}
635+
// }

server/keymanapp-test-bot/keymanapp-test-bot-middleware.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as keymanappTestBot from './keymanapp-test-bot.js';
1313
import { dirname } from 'node:path';
1414
import { fileURLToPath } from 'node:url';
1515
import { consoleError, consoleLog } from "../util/console-log.js";
16+
import { inspect } from "node:util";
1617

1718
const __dirname = dirname(fileURLToPath(import.meta.url));
1819

@@ -49,13 +50,19 @@ const probot = new Probot({
4950
});
5051

5152
const middleware = await createNodeMiddleware(keymanappTestBot.default, { probot,
52-
webhooksPath: "/",
53+
webhooksPath: "/webhook/keymanapp-test-bot",
5354
});
5455

5556
export default (req, res) => {
56-
middleware(req, res, () => {
57-
res.writeHead(404);
58-
res.end();
59-
});
57+
consoleLog(`test-bot`, null, `Request received ${req}`);
58+
try {
59+
debugger;
60+
middleware(req, res, () => {
61+
consoleLog(`test-bot`, null, 'Failed to process request');
62+
res.writeHead(404);
63+
res.end();
64+
});
65+
} catch(e) {
66+
consoleError('test-bot', null, inspect(e));
67+
}
6068
};
61-

server/keymanapp-test-bot/keymanapp-test-bot.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function shouldProcessEvent(sender: components["schemas"]["simple-user"], state:
204204
}
205205

206206
const exports = (app: Probot) => {
207-
app.on(['pull_request.edited', 'pull_request.opened', 'pull_request.synchronize'], (context) => {
207+
app.on(['pull_request.edited', 'pull_request.opened', 'pull_request.synchronize'], async (context) => {
208208
log('pull_request ENTER: '+context.id+', '+context.payload.pull_request.number);
209209
if(!shouldProcessEvent(context.payload.sender!, context.payload.pull_request.state)) {
210210
log('pull_request EXIT: '+context.id+' -- skipping');
@@ -223,7 +223,7 @@ const exports = (app: Probot) => {
223223
return 'ok';
224224
});
225225

226-
app.on(['issues.labeled'], (context) => {
226+
app.on(['issues.labeled'], async (context) => {
227227
log('issues.labeled ENTER: '+context.id+', '+context.payload.issue.number);
228228
if(!shouldProcessEvent(context.payload.sender, context.payload.issue.state!)) {
229229
log('issues.labeled EXIT: '+context.id+' -- skipping');
@@ -242,7 +242,7 @@ const exports = (app: Probot) => {
242242
return 'ok';
243243
});
244244

245-
app.on(['issues.opened', 'issues.edited'], (context) => {
245+
app.on(['issues.opened', 'issues.edited'], async (context) => {
246246
log('issue ENTER: '+context.id+', '+context.payload.issue.number);
247247
if(!shouldProcessEvent(context.payload.sender, context.payload.issue.state!)) {
248248
log('issue EXIT: '+context.id+' -- skipping');
@@ -281,7 +281,7 @@ const exports = (app: Probot) => {
281281
return 'ok';
282282
});
283283

284-
app.on(['issue_comment.created', 'issue_comment.edited', 'issue_comment.deleted'], (context) => {
284+
app.on(['issue_comment.created', 'issue_comment.edited', 'issue_comment.deleted'], async (context) => {
285285
log('issue_comment ENTER: '+context.id+', '+context.payload.comment.id);
286286
if(!shouldProcessEvent(context.payload.sender, context.payload.issue.state)) {
287287
log('issue_comment EXIT: '+context.id+' -- skipping');
@@ -300,7 +300,7 @@ const exports = (app: Probot) => {
300300
return 'ok';
301301
});
302302

303-
app.on(['status'], (context) => {
303+
app.on(['status'], async (context) => {
304304
log('status ENTER: '+context.id+', '+context.payload.sha);
305305
if(context.payload.context == 'user_testing' || context.payload.state != 'success') {
306306
log('status EXIT: '+context.id+' -- ignoring event');

0 commit comments

Comments
 (0)