Skip to content

Commit

Permalink
Check for repo field
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek committed May 5, 2024
1 parent cf61b6a commit 58a0b5a
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/probot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,34 @@ export default (app: Probot, {getRouter}: ApplicationFunctionOptions) => {
await marketplacePurchase(app, ctx);
})
app.onAny(async (ctx: any) => {
app.log(`Received webhook event: ${ctx.name}.${ctx.payload.action}`)
const webhookEvent: WebhookEvent = {
timestamp: new Date(),
name: ctx.name,
action: ctx.payload.action,
owner: ctx.payload.repository.owner.login,
repo: ctx.payload.repository.name
}
const connectionString = process.env.CREATE_ISSUE_BRANCH_MONGODB;
if (!connectionString) {
app.log('Environment variable CREATE_ISSUE_BRANCH_MONGODB not set, skipping database insert')
} else {
const dbService = new MongoDbService(connectionString);
app.log(`Inserting event into database: ${JSON.stringify(webhookEvent)}`);
await dbService.storeEvent(webhookEvent);
dbService.disconnect();
}
app.log(`Received webhook event: ${ctx.name}.${ctx.payload.action}`);
await insertEventIntoDatabase(app, ctx);
});
}

async function insertEventIntoDatabase(app: Probot, ctx: any) {
const repository = ctx.payload.repository;
if (!repository) {
return;
}
const webhookEvent: WebhookEvent = {
timestamp: new Date(),
name: ctx.name,
action: ctx.payload.action,
owner: repository.owner.login,
repo: repository.name
}
const connectionString = process.env.CREATE_ISSUE_BRANCH_MONGODB;
if (!connectionString) {
app.log('Environment variable CREATE_ISSUE_BRANCH_MONGODB not set, skipping database insert');
} else {
const dbService = new MongoDbService(connectionString);
app.log(`Inserting event into database: ${JSON.stringify(webhookEvent)}`);
await dbService.storeEvent(webhookEvent);
dbService.disconnect();
}
}

function addStatsRoute(getRouter: (path?: string) => express.Router) {
const router = getRouter('/probot')
router.get('/stats', (req, res) => {
Expand Down

0 comments on commit 58a0b5a

Please sign in to comment.