Skip to content

Commit

Permalink
Merge pull request #212 from Alokit-Innovations/akg/setup_envvar_fix
Browse files Browse the repository at this point in the history
Install fix: Get TOPIC_NAME from the database instead of environment variable
  • Loading branch information
tapishr authored Jan 8, 2024
2 parents 164c125 + 902a1e0 commit 3e5126a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vibinex-website",
"version": "0.1.14",
"version": "0.1.15",
"private": false,
"homepage": "https://vibinex.com",
"description": "A plugin that works with GitHub, Bitbucket and GitLab to personalize and data-enrich their code review interfaces",
Expand Down
26 changes: 25 additions & 1 deletion pages/api/bitbucket/callbacks/install.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { publishMessage } from '../../../../utils/pubsub/pubsubClient';
import constructHtml from '../../../../utils/serverSideHTML';
import { getServerSession } from 'next-auth';
import { authOptions } from '../../auth/[...nextauth]';
import { getAuthUserId } from '../../../../utils/auth';
import { getUserById, type DbUser } from '../../../../utils/db/users';

const installHandler = async (req: NextApiRequest, res: NextApiResponse) => {
const topicName = process.env.TOPIC_NAME;
const session = await getServerSession(req, res, authOptions).catch((err) => {
console.error('[github/installHandler] Failed to get session', err);
return null;
});
if (!session) {
res.status(500).send(constructHtml("Internal Server Error", "error")); // TODO: user is not logged in - redirect to login page with the correct callback URL
return;
}
const userId = getAuthUserId(session);
const userData: DbUser = await getUserById(userId);
if (!userData) {
console.error(`[github/installHandler] cannot get user data`);
res.status(500).send(constructHtml("Internal Server Error", "error"));
return;
}
if (!userData.topic_name) {
console.error(`[github/installHandler] user topic name not set`);
res.status(400).send(constructHtml("Set up your DPU first", "error")); // TODO: alternatively, we can create the topic name here itself
return;
}
const topicName = userData.topic_name
if (!topicName) {
console.error('[bitbucket/installHandler] TOPIC_NAME not set');
res.status(500).send(constructHtml("Internal Server Error", "error"));
Expand Down
27 changes: 26 additions & 1 deletion pages/api/github/callbacks/install.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { publishMessage } from '../../../../utils/pubsub/pubsubClient';
import constructHtml from '../../../../utils/serverSideHTML';
import { getServerSession } from 'next-auth';
import { authOptions } from '../../auth/[...nextauth]';
import { getAuthUserId } from '../../../../utils/auth';
import { getUserById, type DbUser } from '../../../../utils/db/users';

const installHandler = async (req: NextApiRequest, res: NextApiResponse) => {
const topicName = process.env.TOPIC_NAME;
const session = await getServerSession(req, res, authOptions).catch((err) => {
console.error('[github/installHandler] Failed to get session', err);
return null;
});
if (!session) {
res.status(500).send(constructHtml("Internal Server Error", "error")); // TODO: user is not logged in - redirect to login page with the correct callback URL
return;
}
const userId = getAuthUserId(session);
const userData: DbUser = await getUserById(userId);
if (!userData) {
console.error(`[github/installHandler] cannot get user data`);
res.status(500).send(constructHtml("Internal Server Error", "error"));
return;
}
if (!userData.topic_name) {
console.error(`[github/installHandler] user topic name not set`);
res.status(400).send(constructHtml("Set up your DPU first", "error")); // TODO: alternatively, we can create the topic name here itself
return;
}
const topicName = userData.topic_name
console.log('[github/installHandler] topicName', topicName);
if (!topicName) {
console.error('[github/installHandler] TOPIC_NAME not set');
res.status(500).send(constructHtml("Internal Server Error", "error"));
Expand Down

1 comment on commit 3e5126a

@vercel
Copy link

@vercel vercel bot commented on 3e5126a Jan 8, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.