mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { NextApiRequest, NextApiResponse } from 'next';
|
|
import { env } from '@/env/backend';
|
|
import { graphql } from '@/lib/api/utils';
|
|
|
|
export async function ensureGithubIntegration(
|
|
req: NextApiRequest,
|
|
input: {
|
|
installationId: string;
|
|
orgId: string;
|
|
},
|
|
) {
|
|
const { orgId, installationId } = input;
|
|
await graphql({
|
|
url: `${env.appBaseUrl}/api/proxy`,
|
|
headers: {
|
|
...req.headers,
|
|
'content-type': 'application/json',
|
|
},
|
|
operationName: 'addGitHubIntegration',
|
|
query: /* GraphQL */ `
|
|
mutation addGitHubIntegration($input: AddGitHubIntegrationInput!) {
|
|
addGitHubIntegration(input: $input)
|
|
}
|
|
`,
|
|
variables: {
|
|
input: {
|
|
organization: orgId,
|
|
installationId,
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
export default async function githubCallback(req: NextApiRequest, res: NextApiResponse) {
|
|
console.log('GitHub Integration Callback');
|
|
const installationId = req.query.installation_id as string;
|
|
const orgId = req.query.state as string;
|
|
|
|
await ensureGithubIntegration(req, {
|
|
installationId,
|
|
orgId,
|
|
});
|
|
res.redirect(`/${orgId}/settings`);
|
|
}
|