feat: set up github endpoint
Node.js CI / Lint and Test (push) Successful in 38s

This commit is contained in:
2025-08-27 17:13:29 -07:00
parent d51b1bed89
commit c48242a141
3 changed files with 729 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { IssueCreated,
PullRequestCreated,
GithubPayload } from "../interfaces/github.js";
import type { FastifyRequest, FastifyReply } from "fastify";
const isIssue = (body: GithubPayload): body is IssueCreated => {
return "issue" in body;
};
const isPull = (body: GithubPayload): body is PullRequestCreated => {
return "pull_request" in body;
};
/**
* Handles a payload from a GitHub webhook.
* @param request - The Fastify request payload.
* @param response - The Fastify reply class.
*/
export const processGithubEvent = async(
// eslint-disable-next-line @typescript-eslint/naming-convention -- Fastify standard.
request: FastifyRequest<{ Body: GithubPayload }>,
response: FastifyReply,
): Promise<void> => {
const event = request.headers["x-github-event"];
if (typeof event !== "string") {
await response.status(400).
send({ message: "Invalid GitHub event header." });
return;
}
if (event === "ping") {
await response.status(200).send({ message: "Pong!" });
return;
}
const { action: _action } = request.body;
isIssue(request.body);
isPull(request.body);
};