Preliminary Vercel integration

This commit is contained in:
Tuan Dang
2022-12-13 13:59:21 -05:00
parent 271c810692
commit 3e623922b4
19 changed files with 521 additions and 118 deletions
+43 -4
View File
@@ -2,7 +2,9 @@ import axios from 'axios';
import * as Sentry from '@sentry/node';
import {
INTEGRATION_HEROKU,
INTEGRATION_HEROKU_APPS_URL
INTEGRATION_VERCEL,
INTEGRATION_HEROKU_API_URL,
INTEGRATION_VERCEL_API_URL
} from '../variables';
/**
@@ -28,6 +30,11 @@ const getApps = async ({
accessToken
});
break;
case INTEGRATION_VERCEL:
apps = await getAppsVercel({
accessToken
});
break;
}
} catch (err) {
@@ -53,14 +60,14 @@ const getAppsHeroku = async ({
}) => {
let apps;
try {
const res = await axios.get(INTEGRATION_HEROKU_APPS_URL, {
const res = (await axios.get(`${INTEGRATION_HEROKU_API_URL}/apps`, {
headers: {
Accept: 'application/vnd.heroku+json; version=3',
Authorization: `Bearer ${accessToken}`
}
});
})).data;
apps = res.data.map((a: any) => ({
apps = res.map((a: any) => ({
name: a.name
}));
} catch (err) {
@@ -72,6 +79,38 @@ const getAppsHeroku = async ({
return apps;
}
/**
* Return list of names of apps for Vercel integration
* @param {Object} obj
* @param {String} obj.accessToken - access token for Heroku API
* @returns {Object[]} apps - names of Heroku apps
* @returns {String} apps.name - name of Heroku app
*/
const getAppsVercel = async ({
accessToken
}: {
accessToken: string;
}) => {
let apps;
try {
const res = (await axios.get(`${INTEGRATION_VERCEL_API_URL}/v9/projects`, {
headers: {
Authorization: `Bearer ${accessToken}`
}
})).data;
apps = res.projects.map((a: any) => ({
name: a.name
}));
} catch (err) {
Sentry.setUser(null);
Sentry.captureException(err);
throw new Error('Failed to get Vercel integration apps');
}
return apps;
}
export {
getApps
}