Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Feature/uninstall email #366

Merged
merged 7 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions app/api/actions/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { NextResponse } from "next/server";
import getAllServices from "../../../../utils/actions/getAllServices";
import randomText from "../../../../utils/actions/markdownHelpers/randomText";
import createTeamAndMatchUser from "../../../../utils/db/teams/createTeamAndMatchUser";
import sendUninstall from "../../../../utils/sendgrid/sendUninstall";

const app = new App({
appId: process.env.GITHUB_APP_ID!,
Expand All @@ -41,11 +42,11 @@ export async function POST(request: Request) {
try {
// Verify and parse the webhook event
const eventName = headers["x-github-event"];

let actionName = req.action;
if (
req.action === "opened" ||
req.action === "reopened" ||
req.action === "synchronize"
actionName === "opened" ||
actionName === "reopened" ||
actionName === "synchronize"
) {
const { missingParams } = validateParams(req, [
"pull_request",
Expand Down Expand Up @@ -511,7 +512,7 @@ export async function POST(request: Request) {
repo,
owner,
number,
action: req.action,
action: actionName,
textToWrite,
},
});
Expand Down Expand Up @@ -566,15 +567,15 @@ export async function POST(request: Request) {
repo,
owner,
number,
action: req.action,
action: actionName,
textToWrite,
},
});
return NextResponse.json({
message: "success",
textToWrite,
});
} else if (req.action === "created" || req.action === "edited") {
} else if (actionName === "created" || actionName === "edited") {
console.log("comment keys", Object.keys(req));
const { missingParams } = validateParams(req, [
"installation",
Expand Down Expand Up @@ -632,11 +633,13 @@ export async function POST(request: Request) {
repo,
owner,
number,
action: req.action,
action: actionName,
businessLogicSummary,
},
});
}
} else if (actionName === "deleted") {
sendUninstall({ emails: [req.sender.email] });
}
return NextResponse.json({
message: "wat",
Expand Down
18 changes: 18 additions & 0 deletions utils/sendgrid/sendUninstall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default async function sendUninstall({ emails }: { emails: string[] }) {
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: emails,
from: "[email protected]",
templateId: "d-21dcf37205e4479d830dbcfd35cb41d6",
};
sgMail
.sendMultiple(msg)
.then(() => {
console.log("Email sent");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There you go! just fix this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh so should it be sent to Posthog or...?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a plan, but don't be too strict about it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains at least one console log. Please remove any present.

return { success: true };
})
.catch((error) => {
console.error(error);
});
}