Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions server/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ Sentry.init({

const debugTestBot = false;

if(debugTestBot) {
testUserTestComment();
}
// if(debugTestBot) {
// testUserTestComment();
// }

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

/* Static Endpoints */

// must be before express.json()!
app.use(keymanAppTestBotMiddleware); // '/webhook/keymanapp-test-bot', (request, response) => { keymanAppTestBotMiddleware(request, response); } );

app.use(express.json({ limit: '10mb' })); // for parsing application/json

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

app.use('/webhook/keymanapp-test-bot', (request, response) => { keymanAppTestBotMiddleware(request, response); } );

export function sendWsAlert(hasChanged: boolean, message: string): boolean {
if(hasChanged) {
wsServer.clients.forEach((client) => {
Expand Down Expand Up @@ -620,7 +621,7 @@ app.all('/{*splat}', (request, response) => {
// The error handler must be before any other error middleware and after all controllers
// app.use(Sentry.Handlers.errorHandler());

if(!debugTestBot) {
// if(!debugTestBot) {
consoleLog('main', null, `Starting app listening on ${port}`);
const server = app.listen(port);

Expand All @@ -631,4 +632,4 @@ if(!debugTestBot) {
wsServer.emit('connection', socket, request);
});
});
}
// }
19 changes: 13 additions & 6 deletions server/keymanapp-test-bot/keymanapp-test-bot-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as keymanappTestBot from './keymanapp-test-bot.js';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { consoleError, consoleLog } from "../util/console-log.js";
import { inspect } from "node:util";

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

Expand Down Expand Up @@ -49,13 +50,19 @@ const probot = new Probot({
});

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

export default (req, res) => {
middleware(req, res, () => {
res.writeHead(404);
res.end();
});
consoleLog(`test-bot`, null, `Request received ${req}`);
try {
debugger;
middleware(req, res, () => {
consoleLog(`test-bot`, null, 'Failed to process request');
res.writeHead(404);
res.end();
});
} catch(e) {
consoleError('test-bot', null, inspect(e));
}
};

10 changes: 5 additions & 5 deletions server/keymanapp-test-bot/keymanapp-test-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function shouldProcessEvent(sender: components["schemas"]["simple-user"], state:
}

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

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

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

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

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