-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Vercel build comment workflow (#49)
* Create file tools/fetch-github-issue.ts * Add 1 lines in index.ts * Remove 0 lines in InputSettings.tsx * Add 36 lines in fetch-github-issue.ts * Remove 4 lines in index.ts * Remove 1 lines in InputSettings.tsx * Create file tools/post-github-comment.ts * Add 2 lines in index.ts * Add 11 lines in systemPrompt.ts * Remove 3 lines in Pane.tsx * Remove 0 lines in Pane.tsx * Remove 0 lines in Pane.tsx * Add 6 lines in rewrite-file.ts * Add 6 lines in view-file.ts * Add 7 lines in view-hierarchy.ts * Update file-related tools to support custom repo and branch (issuetopr) (#50) * Create file vercel-build-comment.yml * Create file tools/update-pull-request.ts * Create file tools/close-pull-request.ts * Add 4 lines in index.ts * Add 22 lines in update-pull-request.ts * Add 24 lines in close-pull-request.ts * Add 2 lines in InputSettings.tsx * Create file tools/list-pull-requests.ts * Add 2 lines in index.ts * Remove 0 lines in list-pull-requests.ts * Add 1 lines in InputSettings.tsx * Add 36 lines in list-pull-requests.ts * Remove 0 lines in index.ts
- Loading branch information
1 parent
ca03dd7
commit b12f1ff
Showing
13 changed files
with
449 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { z } from 'zod'; | ||
import { tool, CoreTool } from 'ai'; | ||
import { Octokit } from '@octokit/rest'; | ||
import { ToolContext } from '@/types'; | ||
|
||
const params = z.object({ | ||
pull_number: z.number().describe('The number of the pull request to close'), | ||
}); | ||
|
||
type Params = z.infer<typeof params>; | ||
|
||
type Result = { | ||
success: boolean; | ||
content: string; | ||
summary: string; | ||
details: string; | ||
}; | ||
|
||
export const closePullRequestTool = (context: ToolContext): CoreTool<typeof params, Result> => tool({ | ||
description: 'Closes an open pull request', | ||
parameters: params, | ||
execute: async ({ pull_number }: Params): Promise<Result> => { | ||
if (!context.repo || !context.gitHubToken) { | ||
return { | ||
success: false, | ||
content: 'Missing repository information or GitHub token', | ||
summary: 'Failed to close pull request due to missing context', | ||
details: 'The tool context is missing required repository information or GitHub token.' | ||
}; | ||
} | ||
|
||
const octokit = new Octokit({ auth: context.gitHubToken }); | ||
|
||
try { | ||
const { data } = await octokit.pulls.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.name, | ||
pull_number, | ||
state: 'closed', | ||
}); | ||
|
||
return { | ||
success: true, | ||
content: `Pull request #${pull_number} closed successfully.`, | ||
summary: `Closed pull request #${pull_number}`, | ||
details: `Pull request #${pull_number} was closed in the repository ${context.repo.owner}/${context.repo.name}.`, | ||
}; | ||
} catch (error) { | ||
console.error('Error closing pull request:', error); | ||
const errorMessage = error instanceof Error ? error.message : String(error); | ||
return { | ||
success: false, | ||
content: 'Failed to close pull request.', | ||
summary: 'Error closing pull request', | ||
details: `Error: ${errorMessage}`, | ||
}; | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { tool, CoreTool } from 'ai'; | ||
import { z } from 'zod'; | ||
import { Octokit } from "@octokit/rest"; | ||
import { ToolContext } from "@/types"; | ||
|
||
const params = z.object({ | ||
issueNumber: z.number().describe("The number of the GitHub issue to fetch"), | ||
}); | ||
|
||
type Params = z.infer<typeof params>; | ||
|
||
type Result = { | ||
success: boolean; | ||
name?: string; | ||
description?: string; | ||
comments?: Array<{ user: string; body: string; created_at: string }>; | ||
error?: string; | ||
summary: string; | ||
details: string; | ||
}; | ||
|
||
export const fetchGitHubIssueTool = (context: ToolContext): CoreTool<typeof params, Result> => tool({ | ||
description: "Fetch details of a GitHub issue", | ||
parameters: params, | ||
execute: async ({ issueNumber }: Params): Promise<Result> => { | ||
if (!context.gitHubToken) { | ||
return { | ||
success: false, | ||
error: "GitHub token is required to fetch issue details", | ||
summary: "Failed to fetch GitHub issue due to missing token", | ||
details: "The GitHub token is missing from the tool context." | ||
}; | ||
} | ||
|
||
const octokit = new Octokit({ auth: context.gitHubToken }); | ||
|
||
try { | ||
const { data: issue } = await octokit.issues.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.name, | ||
issue_number: issueNumber, | ||
}); | ||
|
||
const { data: comments } = await octokit.issues.listComments({ | ||
owner: context.repo.owner, | ||
repo: context.repo.name, | ||
issue_number: issueNumber, | ||
}); | ||
|
||
const result: Result = { | ||
success: true, | ||
name: issue.title, | ||
description: issue.body, | ||
comments: comments.map((comment) => ({ | ||
user: comment.user.login, | ||
body: comment.body, | ||
created_at: comment.created_at, | ||
})), | ||
summary: `Fetched GitHub issue #${issueNumber}`, | ||
details: `Successfully retrieved details for GitHub issue #${issueNumber} in ${context.repo.owner}/${context.repo.name}` | ||
}; | ||
|
||
return result; | ||
} catch (error: unknown) { | ||
const errorMessage = error instanceof Error ? error.message : String(error); | ||
console.error("Error fetching GitHub issue:", errorMessage); | ||
return { | ||
success: false, | ||
error: errorMessage, | ||
summary: `Failed to fetch GitHub issue #${issueNumber}`, | ||
details: `An error occurred while fetching GitHub issue #${issueNumber} in ${context.repo.owner}/${context.repo.name}. Error: ${errorMessage}` | ||
}; | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { z } from 'zod'; | ||
import { tool, CoreTool } from 'ai'; | ||
import { Octokit } from '@octokit/rest'; | ||
import { ToolContext } from '@/types'; | ||
|
||
const params = z.object({ | ||
owner: z.string().describe('The owner of the repository'), | ||
repo: z.string().describe('The name of the repository'), | ||
}); | ||
|
||
type Params = z.infer<typeof params>; | ||
|
||
type Result = { | ||
success: boolean; | ||
pullRequests?: Array<{ | ||
number: number; | ||
title: string; | ||
url: string; | ||
created_at: string; | ||
user?: string; | ||
}>; | ||
summary: string; | ||
details: string; | ||
error?: string; | ||
}; | ||
|
||
export const listPullRequestsTool = (context: ToolContext): CoreTool<typeof params, Result> => tool({ | ||
description: 'Lists open pull requests in a repository', | ||
parameters: params, | ||
execute: async ({ owner, repo }: Params): Promise<Result> => { | ||
if (!context.gitHubToken) { | ||
return { | ||
success: false, | ||
summary: 'Failed to list pull requests due to missing GitHub token', | ||
details: 'The tool context is missing the required GitHub token.', | ||
}; | ||
} | ||
|
||
const octokit = new Octokit({ auth: context.gitHubToken }); | ||
|
||
try { | ||
const response = await octokit.pulls.list({ | ||
owner, | ||
repo, | ||
state: 'open', | ||
sort: 'created', | ||
direction: 'desc', | ||
}); | ||
|
||
const pullRequests = response.data.map((pr) => ({ | ||
number: pr.number, | ||
title: pr.title, | ||
url: pr.html_url, | ||
created_at: pr.created_at, | ||
user: pr.user?.login, | ||
})); | ||
|
||
return { | ||
success: true, | ||
pullRequests, | ||
summary: `Listed ${pullRequests.length} open pull requests for ${owner}/${repo}`, | ||
details: `Successfully retrieved open pull requests for ${owner}/${repo}`, | ||
}; | ||
} catch (error) { | ||
const errorMessage = error instanceof Error ? error.message : String(error); | ||
return { | ||
success: false, | ||
summary: `Error listing pull requests for ${owner}/${repo}`, | ||
details: `An error occurred while trying to list pull requests for ${owner}/${repo}: ${errorMessage}`, | ||
error: `Failed to list pull requests: ${errorMessage}`, | ||
}; | ||
} | ||
}, | ||
}); |
Oops, something went wrong.