fix: replace deprecated ephemeral flag and add error handling across modules

- Replace `ephemeral: true` with `flags: [ MessageFlags.Ephemeral ]` in all command files
- Add try/catch with logger.error to logMenteeJoin, checkAchievements, processMentorshipRole
- Extract handleIssueOpened and handlePrOpened helpers in processGitHubEvent to reduce complexity
- Add logger.error calls in all newly introduced catch blocks
This commit is contained in:
2026-03-03 12:04:20 -08:00
parent 5beebeff44
commit 3f89b7eb4f
8 changed files with 149 additions and 95 deletions
+68 -33
View File
@@ -21,13 +21,78 @@ const isPull = (body: GithubPayload): body is PullRequestCreated => {
return "pull_request" in body;
};
/**
* Handles a newly opened GitHub issue by auto-assigning Naomi.
* @param amari - Amari's instance.
* @param body - The parsed issue webhook payload.
*/
const handleIssueOpened = async(
amari: Amari,
body: IssueCreated,
): Promise<void> => {
await logger.log("info", "Processing new issue");
const { issue, repository } = body;
const { number, user } = issue;
const { owner, name } = repository;
try {
await amari.github.rest.issues.addAssignees({
assignees: [ "naomi-lgbt" ],
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github SDK requirement.
issue_number: number,
owner: owner.login,
repo: name,
});
await logger.metric("processed_github_event", 1, {
action: "opened",
event: "issue",
user: user.login,
});
} catch (error) {
if (error instanceof Error) {
await logger.error("processGitHubEvent module", error);
}
}
};
/**
* Handles a newly opened GitHub pull request by requesting Naomi's review.
* @param amari - Amari's instance.
* @param body - The parsed pull request webhook payload.
*/
const handlePrOpened = async(
amari: Amari,
body: PullRequestCreated,
): Promise<void> => {
const { pull_request: pr, repository } = body;
const { number, user } = pr;
await logger.log("info", "Processing new PR");
const { owner, name } = repository;
try {
await amari.github.rest.pulls.requestReviewers({
owner: owner.login,
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github SDK requirement.
pull_number: number,
repo: name,
reviewers: [ "naomi-lgbt" ],
});
await logger.metric("processed_github_event", 1, {
action: "opened",
event: "pull_request",
user: user.login,
});
} catch (error) {
if (error instanceof Error) {
await logger.error("processGitHubEvent module", error);
}
}
};
/**
* Handles a payload from a GitHub webhook.
* @param amari - Amari's instance.
* @param request - The Fastify request payload.
* @param response - The Fastify reply class.
*/
// eslint-disable-next-line max-statements, max-lines-per-function -- STFU.
export const processGithubEvent = async(
amari: Amari,
request: FastifyRequest<{
@@ -58,40 +123,10 @@ export const processGithubEvent = async(
const { action } = request.body;
await response.status(200).send({ message: "Payload received!" });
if (action === "opened" && event === "issues" && isIssue(request.body)) {
await logger.log("info", "Processing new issue");
const { issue, repository } = request.body;
const { number, user } = issue;
const { owner, name } = repository;
await amari.github.rest.issues.addAssignees({
assignees: [ "naomi-lgbt" ],
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github SDK requirement.
issue_number: number,
owner: owner.login,
repo: name,
});
await logger.metric("processed_github_event", 1, {
action: "opened",
event: "issue",
user: user.login,
});
await handleIssueOpened(amari, request.body);
return;
}
if (action === "opened" && event === "pull_request" && isPull(request.body)) {
const { pull_request: pr, repository } = request.body;
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,
// eslint-disable-next-line @typescript-eslint/naming-convention -- Github SDK requirement.
pull_number: number,
repo: name,
reviewers: [ "naomi-lgbt" ],
});
await handlePrOpened(amari, request.body);
}
};