-
Hi Probot team! Working on a GitHub App (using Probot of course 💪🏽 ) as an Express middleware. I would like to know what would be the easiest and best practice to verify requests received by my GitHub App. I know there's Click to expand file structure!// server.ts
import express from "express";
import eventHandler from "./routes/event-handler";
const app = express();
const port = process.env.PORT;
app.use("/event_handler", eventHandler);
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
}); // routes/event-handler.ts
import express from "express";
import { probotMiddleware } from "../middlewares/probot";
const router = express.Router();
router.use(express.json());
router.use(probotMiddleware);
router.post("/", async (_req, res) => {
res.status(200).end();
});
export default router; // middlewares/probot.ts
import { createNodeMiddleware, createProbot } from "probot";
import app from "../vcs/github/github-app";
export const probotMiddleware = createNodeMiddleware(app, {
probot: createProbot(),
}); // vcs/github/github-app.ts
import { Probot } from "probot";
import { checkSuiteEventHandler } from "./event-handlers/check-suite";
export default (app: Probot) => {
app.on(
["check_suite.requested", "check_suite.rerequested"],
checkSuiteEventHandler
);
}; // event-handlers/check-suite.ts
import { Context } from "probot";
export const checkSuiteEventHandler = async (
context: Context<"check_suite.requested" | "check_suite.rerequested">
) => {
const startTime = new Date();
const payload = context.payload.check_suite;
const { head_branch: headBranch, head_sha: headSha } = payload;
return context.octokit.checks.create(...);
}; In my mind there should be an option I found issues which are kind of related but I'm not sure if they plan to solve this exactly issue:
Let me know your thoughts on this 💪🏽 🧠 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The No need to enable it explicitly |
Beta Was this translation helpful? Give feedback.
The
createNodeMiddleware
should do the verification for you:https://github.com/octokit/webhooks.js/blob/4ca8267bce6ac94b027746403aa707eeaf5e53c7/src/middleware/node/middleware.ts#L80-L85
No need to enable it explicitly