feat: analytics
Node.js CI / Lint and Test (push) Successful in 49s

This commit is contained in:
2025-10-08 08:41:37 -07:00
parent 36ad30e4a2
commit 5cadb9bbee
12 changed files with 77 additions and 34 deletions
+19 -6
View File
@@ -6,9 +6,11 @@
import { logger } from "../utils/logger.js";
import type { Amari } from "../interfaces/amari.js";
import type { IssueCreated,
import type {
IssueCreated,
PullRequestCreated,
GithubPayload } from "../interfaces/github.js";
GithubPayload,
} from "../interfaces/github.js";
import type { FastifyRequest, FastifyReply } from "fastify";
const isIssue = (body: GithubPayload): body is IssueCreated => {
@@ -44,7 +46,8 @@ export const processGithubEvent = async(
}
const event = request.headers["x-github-event"];
if (typeof event !== "string") {
await response.status(400).
await response.
status(400).
send({ message: "Invalid GitHub event header." });
return;
}
@@ -57,7 +60,7 @@ export const processGithubEvent = async(
if (action === "opened" && event === "issues" && isIssue(request.body)) {
await logger.log("info", "Processing new issue");
const { issue, repository } = request.body;
const { number } = issue;
const { number, user } = issue;
const { owner, name } = repository;
await amari.github.rest.issues.addAssignees({
assignees: [ "naomi-lgbt" ],
@@ -66,12 +69,22 @@ export const processGithubEvent = async(
owner: owner.login,
repo: name,
});
await logger.metric("processed_github_event", 1, {
action: "opened",
event: "issue",
user: user.login,
});
return;
}
if (action === "opened" && event === "pull_request" && isPull(request.body)) {
await logger.log("info", "Processing new PR");
const { pull_request: pr, repository } = request.body;
const { number } = pr;
const { number, user } = pr;
await logger.log("info", "Processing new PR");
await logger.metric("processed_github_event", 1, {
action: "opened",
event: "pull_request",
user: user.login,
});
const { owner, name } = repository;
await amari.github.rest.pulls.requestReviewers({
owner: owner.login,