Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fix GH signin

Tomas Valentaf72e1dd6b8b5
diff --git a/components/Repos.tsx b/components/Repos.tsx
index e602098ad..f5326413f 100644
--- a/components/Repos.tsx
+++ b/components/Repos.tsx
@@ -13,6 +13,7 @@ import { openPopupModal } from 'utils/popupModal'
import TitleButton from 'components/TitleButton'
import Input from 'components/Input'
import SpinnerIcon from 'components/Spinner'
+import { useLocalStorage } from 'hooks/useLocalStorage'
export interface PostProjectBody {
repositoryID: number
@@ -23,14 +24,21 @@ export interface PostProjectBody {
id: string
}
+export interface RepoSetup extends Pick<PostProjectBody, 'installationID' | 'repositoryID'> {
+ fullName: string
+ defaultBranch: string
+ branches?: string[]
+ url: string
+ owner: string
+ repo: string
+}
export interface Props {
- onRepoSelection: (repoSetup: Pick<PostProjectBody, 'accessToken' | 'installationID' | 'repositoryID'> & { fullName: string, defaultBranch: string, branches?: string[], url: string }) => void
- accessToken?: string
+ onRepoSelection: (repoSetup: RepoSetup) => void
}
-function Repos({ onRepoSelection, accessToken }: Props) {
- // const [accessToken, setAccessToken] = useLocalStorage<string | undefined>('gh_access_token', undefined)
+function Repos({ onRepoSelection }: Props) {
+ const [accessToken, setAccessToken] = useLocalStorage<string | undefined>('gh_access_token', undefined)
const gitHub = useGitHubClient(accessToken)
const { repos, refetch } = useRepositories(gitHub)
const [query, setQuery] = useState<string>()
@@ -46,18 +54,17 @@ function Repos({ onRepoSelection, accessToken }: Props) {
const handleEvent = useCallback((event: MessageEvent) => {
if (event.data.accessToken) {
- // setAccessToken(event.data.accessToken)
+ setAccessToken(event.data.accessToken)
} else if (event.data.installationID) {
refetch()
}
- }, [refetch])
+ }, [refetch, setAccessToken])
useListenMessage(handleEvent)
- async function selectRepository(r: Pick<PostProjectBody, 'installationID' | 'repositoryID'> & { fullName: string, defaultBranch: string, url: string }) {
+ async function selectRepository(r: Omit<RepoSetup, 'branches'>) {
if (!accessToken) return
onRepoSelection({
...r,
- accessToken,
branches: [r.defaultBranch],
})
@@ -71,7 +78,6 @@ function Repos({ onRepoSelection, accessToken }: Props) {
onRepoSelection({
...r,
branches,
- accessToken,
})
}
@@ -101,7 +107,7 @@ function Repos({ onRepoSelection, accessToken }: Props) {
<div className="flex flex-1 justify-center items-center">
<Button
variant={Button.variant.Full}
- onClick={signWithGitHubOAuth}
+ onClick={configureGitHubApp}
text="Add GitHub Repository"
icon={<GithubIcon />}
/>
@@ -129,7 +135,7 @@ function Repos({ onRepoSelection, accessToken }: Props) {
}
{repos && repos.length === 0 &&
- <div className="flex flex-1 items-center justify-center">
+ <div className="flex flex-1 items-center justify-center flex-col space-y-1">
<Text text="No connected repositories found" />
<Button
variant={Button.variant.Full}
@@ -171,6 +177,8 @@ function Repos({ onRepoSelection, accessToken }: Props) {
repositoryID: r.id,
fullName: r.full_name,
url: r.html_url,
+ owner: r.owner.name || r.organization?.name as string,
+ repo: r.name,
})}
text="Select"
/>
diff --git a/hooks/useRepositories.ts b/hooks/useRepositories.ts
index 23532f5cb..e3e9b38a0 100644
--- a/hooks/useRepositories.ts
+++ b/hooks/useRepositories.ts
@@ -1,5 +1,4 @@
import { useEffect, useReducer, useState } from 'react'
-
import { GitHubClient } from 'github/client'
async function fetchRepos(client: GitHubClient) {
diff --git a/pages/_app.tsx b/pages/_app.tsx
index 47592b2a5..bb9a9388f 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -22,7 +22,9 @@ function App({ Component, pageProps }: AppProps<{ initialSession: Session, proje
const router = useRouter()
const [supabaseClient] = useState(() => createBrowserSupabaseClient<Database>(clientCreds))
- const hasHeader = !router.pathname.startsWith('/sign') && !router.pathname.startsWith('/agent')
+ const hasHeader =
+ !router.pathname.startsWith('/sign') &&
+ !router.pathname.startsWith('/agent')
return (
<main className={clsx(
diff --git a/pages/agent/smol-developer/setup.tsx b/pages/agent/smol-developer/setup.tsx
index 49c3fa57c..c97574704 100644
--- a/pages/agent/smol-developer/setup.tsx
+++ b/pages/agent/smol-developer/setup.tsx
@@ -8,8 +8,9 @@ import {
import useSWRMutation from 'swr/mutation'
import { serverCreds } from 'db/credentials'
-import Repos from 'components/Repos'
+import Repos, { RepoSetup } from 'components/Repos'
import Button from 'components/Button'
+import { useState } from 'react'
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const supabase = createServerSupabaseClient(ctx, serverCreds)
@@ -25,6 +26,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
},
}
}
+
return { props: {} }
}
@@ -65,6 +67,7 @@ function Repo() {
const user = useUser()
const session = useSession()
const sessionCtx = useSessionContext()
+ const [selectedRepo, setSelectedRepo] = useState<RepoSetup>()
async function signOut() {
await supabaseClient.auth.signOut()
@@ -76,16 +79,18 @@ function Repo() {
} = useSWRMutation('/api/agent', handlePostAgent)
async function deployAgent() {
+ if (!selectedRepo) return
+
await createAgent({
- body,
- defaultBranch,
- installationID,
- owner,
- repo,
+ defaultBranch: selectedRepo.defaultBranch,
+ installationID: selectedRepo.installationID,
+ owner: selectedRepo.owner,
+ repo: selectedRepo.repo,
+ repositoryID: selectedRepo.repositoryID,
+ title,
branch,
+ body,
commitMessage,
- repositoryID,
- title,
})
}
@@ -121,8 +126,7 @@ function Repo() {
Select repo
{user &&
<Repos
- onRepoSelection={r => console.log(r)}
- accessToken={session?.provider_token || undefined}
+ onRepoSelection={setSelectedRepo}
/>
}
</div>
diff --git a/pages/api/github/oauth.ts b/pages/api/github/oauth.ts
index c01ba9812..8b26e0e3b 100644
--- a/pages/api/github/oauth.ts
+++ b/pages/api/github/oauth.ts
@@ -1,4 +1,3 @@
-// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
import url from 'url'
@@ -19,8 +18,6 @@ export default async function handler(
return
}
- const callbackURL = 'https://ntjfcwpzsxugrykskdgi.supabase.co/auth/v1/callback'
-
const exchangeURL = new URL('login/oauth/access_token', 'https://github.com')
exchangeURL.searchParams.set('client_id', process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID!)
exchangeURL.searchParams.set('client_secret', process.env.GITHUB_CLIENT_SECRET!)
@@ -32,15 +29,11 @@ export default async function handler(
Accept: 'application/json',
}
})
- const {
- access_token,
- }: {
- access_token: string,
- } = await response.json()
+ const { access_token }: { access_token: string } = await response.json()
- const redirectionURL = new URL('github/callback', `https://${req.headers.host}`)
+ const redirectionURL = new URL('github/callback', `${process.env.NODE_ENV === 'production' ? 'https' : 'http'}://${req.headers.host}`)
- redirectionURL.searchParams.set('access_token', access_token)
+ redirectionURL.searchParams.set('gha_access_token', access_token)
res.writeHead(302, { 'Location': redirectionURL.toString() })
res.end()
diff --git a/pages/github/callback.ts b/pages/github/callback.ts
index cc987c167..834e2df21 100644
--- a/pages/github/callback.ts
+++ b/pages/github/callback.ts
@@ -5,9 +5,9 @@ function GitHubCallback() {
const router = useRouter()
useEffect(function message() {
- if (router.query.access_token) {
+ if (router.query.gha_access_token) {
if (window && window.opener) {
- window.opener.postMessage({ accessToken: router.query.access_token }, '*')
+ window.opener.postMessage({ accessToken: router.query.gha_access_token }, '*')
window.close()
}
}
@@ -17,7 +17,7 @@ function GitHubCallback() {
window.close()
}
}
- }, [router.query.access_token, router.query.installation_id])
+ }, [router.query.gha_access_token, router.query.installation_id])
return null
}