diff --git a/app/api/actions/github/route.ts b/app/api/actions/github/route.ts index 85d95353..f0b95120 100644 --- a/app/api/actions/github/route.ts +++ b/app/api/actions/github/route.ts @@ -23,6 +23,7 @@ import { 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"; const app = new App({ appId: process.env.GITHUB_APP_ID!, privateKey: process.env.GITHUB_PRIVATE_KEY!, @@ -53,7 +54,7 @@ export async function POST(request: Request) { if (missingParams.length > 0) { return missingParamsResponse({ url: request.url, missingParams }); } - const { installation, repository, pull_request } = req; + const { installation, repository, pull_request, organization } = req; const installationId = installation.id; const { title, body } = req.pull_request; const owner = repository.owner.login; @@ -328,6 +329,12 @@ export async function POST(request: Request) { } } + const team = await createTeamAndMatchUser({ + name: organization.login, + id: organization.id, + watermelon_user, + }); + const count = await addActionCount({ owner }); textToWrite += `### WatermelonAI Summary \n`; diff --git a/utils/db/teams/createTeamAndMatchUser.ts b/utils/db/teams/createTeamAndMatchUser.ts new file mode 100644 index 00000000..d5739ad3 --- /dev/null +++ b/utils/db/teams/createTeamAndMatchUser.ts @@ -0,0 +1,8 @@ +import executeRequest from "../azuredb"; + +export default async ({ name, id, watermelon_user }) => { + let query = await executeRequest( + `EXEC dbo.create_new_team_and_match_user @name = '${name}', @id = '${id}', @user_id = '${watermelon_user}'` + ); + return query; +};