From a3093de55b28b3e5a0bd56b794a59b7f2794c342 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Sat, 8 Apr 2023 00:17:24 +0300 Subject: [PATCH] Patch GitHub integration organization owner --- backend/src/integrations/apps.ts | 11 +++++---- backend/src/integrations/sync.ts | 2 +- .../src/pages/integrations/github/create.tsx | 24 ++++++++++--------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/backend/src/integrations/apps.ts b/backend/src/integrations/apps.ts index f7eef6263..1bd138a37 100644 --- a/backend/src/integrations/apps.ts +++ b/backend/src/integrations/apps.ts @@ -270,10 +270,13 @@ const getAppsGithub = async ({ accessToken }: { accessToken: string }) => { apps = repos .filter((a: any) => a.permissions.admin === true) - .map((a: any) => ({ - name: a.name, - owner: a.owner.login, - })); + .map((a: any) => { + return ({ + appId: a.id, + name: a.name, + owner: a.owner.login, + }); + }); } catch (err) { Sentry.setUser(null); Sentry.captureException(err); diff --git a/backend/src/integrations/sync.ts b/backend/src/integrations/sync.ts index 829b50531..53af1ac2c 100644 --- a/backend/src/integrations/sync.ts +++ b/backend/src/integrations/sync.ts @@ -1060,7 +1060,7 @@ const syncSecretsGitHub = async ({ "GET /repos/{owner}/{repo}/actions/secrets/public-key", { owner: integration.owner, - repo: integration.app, + repo: integration.app } ) ).data; diff --git a/frontend/src/pages/integrations/github/create.tsx b/frontend/src/pages/integrations/github/create.tsx index 5fbd8f780..c4368fe4f 100644 --- a/frontend/src/pages/integrations/github/create.tsx +++ b/frontend/src/pages/integrations/github/create.tsx @@ -27,8 +27,7 @@ export default function GitHubCreateIntegrationPage() { }); const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState(''); - const [owner, setOwner] = useState(null); - const [targetApp, setTargetApp] = useState(''); + const [targetAppId, setTargetAppId] = useState(''); const [isLoading, setIsLoading] = useState(false); @@ -41,10 +40,9 @@ export default function GitHubCreateIntegrationPage() { useEffect(() => { if (integrationAuthApps) { if (integrationAuthApps.length > 0) { - setTargetApp(integrationAuthApps[0].name); - setOwner(integrationAuthApps[0]?.owner ?? null); + setTargetAppId(integrationAuthApps[0].appId as string); } else { - setTargetApp('none'); + setTargetAppId('none'); } } }, [integrationAuthApps]); @@ -55,14 +53,18 @@ export default function GitHubCreateIntegrationPage() { if (!integrationAuth?._id) return; + const targetApp = integrationAuthApps?.find((integrationAuthApp) => integrationAuthApp.appId === targetAppId); + + if (!targetApp || !targetApp.owner) return; + await createIntegration({ integrationAuthId: integrationAuth?._id, isActive: true, - app: targetApp, + app: targetApp.name, appId: null, sourceEnvironment: selectedSourceEnvironment, targetEnvironment: null, - owner, + owner: targetApp.owner, path: null, region: null }); @@ -76,7 +78,7 @@ export default function GitHubCreateIntegrationPage() { } } - return (integrationAuth && workspace && selectedSourceEnvironment && integrationAuthApps && targetApp) ? ( + return (integrationAuth && workspace && selectedSourceEnvironment && integrationAuthApps && targetAppId) ? (
GitHub Integration @@ -101,14 +103,14 @@ export default function GitHubCreateIntegrationPage() { className='mt-4' >