Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fix dynamic repo name; Add PR edit handler [WIP]

Tomas Valentadafe7972fc12
diff --git a/github/pullRequest.ts b/github/pullRequest.ts
index a72daba9f..0a9b25baf 100644
--- a/github/pullRequest.ts
+++ b/github/pullRequest.ts
@@ -190,7 +190,11 @@ export async function triggerSmolDevAgentRun({
prompt,
accessToken,
commitMessage,
+ owner,
+ repo,
}: {
+ owner: string,
+ repo: string,
commitMessage: string,
deployment: deployments,
prompt: string,
@@ -207,8 +211,8 @@ export async function triggerSmolDevAgentRun({
Prompt: prompt,
GitHubAppName: (deployment?.auth as any)?.['github']?.['app_name'],
GitHubAppEmail: (deployment?.auth as any)?.['github']?.['app_email'],
- Owner: (deployment?.auth as any)?.['github']?.['owner'],
- Repo: (deployment?.auth as any)?.['github']?.['repo'],
+ Owner: owner,
+ Repo: repo,
Branch: (deployment?.auth as any)?.['github']?.['branch'],
},
} as any,
diff --git a/github/webhooks.ts b/github/webhooks.ts
index e8305fce4..453a5f412 100644
--- a/github/webhooks.ts
+++ b/github/webhooks.ts
@@ -14,11 +14,51 @@ export async function getGitHubWebhooksMiddleware() {
})
webhooks.on('issue_comment', issueCommentHandler)
+ webhooks.on('pull_request.edited', pullRequestEditHandler)
// TODO: Add handling for review comments
return createNodeMiddleware(webhooks, { path: '/api/github/webhook' })
}
+const pullRequestEditHandler: HandlerFunction<'pull_request.edited', unknown> = async (event) => {
+ const { payload } = event
+
+ const installationID = payload.installation?.id
+ const repositoryID = payload.repository.id
+ const { owner, repo } = parseRepoName(payload.repository.full_name)
+
+ // Every PR is also an issues - GH API endpoint for issues is used for the shared functionality
+ const issueID = payload.pull_request.id
+ const prompt = payload.pull_request.body as string
+
+ if (!installationID) {
+ throw new Error('InstallationID not found')
+ }
+
+ const client = getGHInstallationClient({ installationID })
+
+ const [deployments] = await Promise.all([
+ getDeploymentsForPR({ issueID, installationID, repositoryID }),
+ ])
+
+ await Promise.allSettled(
+ deployments.map(async deployment => {
+ const accessToken = await getGHAccessToken({
+ client,
+ installationID,
+ repositoryID,
+ })
+ await triggerSmolDevAgentRun({
+ prompt,
+ deployment,
+ accessToken,
+ commitMessage: 'Update based on PR comments',
+ owner,
+ repo,
+ })
+ }))
+}
+
const issueCommentHandler: HandlerFunction<'issue_comment', unknown> = async (event) => {
const { payload } = event
@@ -47,6 +87,13 @@ const issueCommentHandler: HandlerFunction<'issue_comment', unknown> = async (ev
installationID,
repositoryID,
})
- await triggerSmolDevAgentRun({ prompt, deployment, accessToken, commitMessage: 'Update based on PR comments' })
+ await triggerSmolDevAgentRun({
+ prompt,
+ deployment,
+ accessToken,
+ owner,
+ repo,
+ commitMessage: 'Update based on PR comments',
+ })
}))
}
diff --git a/pages/agent/smol-developer/setup.tsx b/pages/agent/smol-developer/setup.tsx
index 5aa5ed0aa..2c47a30d7 100644
--- a/pages/agent/smol-developer/setup.tsx
+++ b/pages/agent/smol-developer/setup.tsx
@@ -57,14 +57,14 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
}
async function handlePostAgent(url: string, { arg }: { arg: PostAgentBody }) {
- return await fetch(url, {
+ const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(arg),
-
headers: {
'Content-Type': 'application/json',
},
- }).then(r => r.json())
+ })
+ return await response.json() as { issueID: string }
}
function getSmolDevModelConfig(creds: Creds): ModelConfig & { templateID: TemplateID } {
diff --git a/pages/api/agent.ts b/pages/api/agent.ts
index dab26d42c..907d38a0b 100644
--- a/pages/api/agent.ts
+++ b/pages/api/agent.ts
@@ -87,8 +87,6 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {
repository_id: repositoryID,
issue_id: issueID,
branch,
- owner,
- repo,
},
},
enabled: false,
@@ -135,11 +133,11 @@ async function postAgent(req: NextApiRequest, res: NextApiResponse) {
prompt: body,
accessToken,
commitMessage: 'Add code based on the PR description',
+ owner,
+ repo,
})
res.status(200).json({
- owner,
- repo,
issueID,
})
} catch (err: any) {