Skip to content

Commit

Permalink
Add Vercel build comment workflow (#49)
Browse files Browse the repository at this point in the history
* 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
AtlantisPleb authored Aug 27, 2024
1 parent ca03dd7 commit b12f1ff
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 45 deletions.
9 changes: 6 additions & 3 deletions components/input/InputSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export function InputSettings({ className, ...props }: React.ComponentProps<'div
'view_hierarchy',
'create_pull_request',
'create_branch',
'search_codebase'
'fetch_github_issue',
'update_pull_request',
'close_pull_request',
'list_pull_requests'
]

const buttonClasses = "opacity-75 bg-background text-foreground hover:bg-accent/60 hover:text-accent-foreground rounded px-2 py-1 flex items-center space-x-1 focus:outline-none focus:ring-0 transition-colors duration-200"
Expand Down Expand Up @@ -244,7 +247,7 @@ export function InputSettings({ className, ...props }: React.ComponentProps<'div
<DialogContent>
<DialogHeader>
<DialogTitle>Add Credits</DialogTitle>
s <DialogDescription>
<DialogDescription>
Advanced models require credits. Select the amount of credits to buy. Min $5, max $1000
</DialogDescription>
</DialogHeader>
Expand All @@ -263,4 +266,4 @@ export function InputSettings({ className, ...props }: React.ComponentProps<'div
</Dialog>
</div>
)
}
}
14 changes: 13 additions & 1 deletion lib/systemPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,25 @@ ACTIVE BRANCH: ${repo.branch}
Additional functions:
1. Assist with pull request creation and management
2. Help with branch management
3. Handle GitHub issues and create corresponding pull requests
Additional tools:
- \`create_pull_request\` - Create a new pull request with specified title, description, and branches
- \`create_branch\` - Creates a new branch in the repository
- \`fetch_github_issue\` - Fetch details of a GitHub issue
- \`post_github_comment\` - Post a comment on a GitHub issue
Additional guidelines:
- Use the create_branch tool to create new branches for features or bug fixes
- Use the create_pull_request tool to submit changes when ready
- When handling GitHub issues, follow this workflow:
1. Use fetch_github_issue to get issue details and comments
2. Analyze the issue and gather necessary context from the repository
3. Create a new branch for the issue using create_branch
4. Make necessary changes to address the issue
5. Use create_pull_request to open a pull request for the changes
6. Use post_github_comment to update the original issue with the pull request link
- Always provide clear and concise explanations of the changes made in the pull request description
- If additional information or clarification is needed, use post_github_comment to ask questions on the issue
`;
}
}
18 changes: 8 additions & 10 deletions panes/Pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const Pane: React.FC<PaneProps> = ({
titleBarButtons,
dismissable = true
}) => {
const [bounds, setBounds] = useState({ right: 0, bottom: 0 })
const [bounds, setBounds] = useState({ left: 0, top: 0, right: 0, bottom: 0 })
const updatePanePosition = usePaneStore(state => state.updatePanePosition)
const updatePaneSize = usePaneStore(state => state.updatePaneSize)
const removePane = usePaneStore(state => state.removePane)
Expand All @@ -125,9 +125,12 @@ export const Pane: React.FC<PaneProps> = ({

useEffect(() => {
const updateBounds = () => {
const handleSize = 50 // Size of the handle that remains on screen
setBounds({
right: window.innerWidth - size.width,
bottom: window.innerHeight - size.height,
left: -size.width + handleSize,
top: -size.height + handleSize,
right: window.innerWidth - handleSize,
bottom: window.innerHeight - handleSize,
})
}

Expand All @@ -141,12 +144,7 @@ export const Pane: React.FC<PaneProps> = ({
updatePanePosition(id, ox, oy)
}, {
from: () => [position.x, position.y],
bounds: {
left: 0,
top: 0,
right: bounds.right,
bottom: bounds.bottom,
},
bounds: bounds,
})

const handleClose = (e: React.MouseEvent) => {
Expand Down Expand Up @@ -210,4 +208,4 @@ export const Pane: React.FC<PaneProps> = ({
<div {...resizeHandlers.left()} className="absolute top-3 -left-1 w-4 bottom-3 cursor-ew-resize touch-none" />
</div>
)
}
}
59 changes: 59 additions & 0 deletions tools/close-pull-request.ts
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}`,
};
}
},
});
75 changes: 75 additions & 0 deletions tools/fetch-github-issue.ts
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}`
};
}
},
});
16 changes: 11 additions & 5 deletions tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import { createPullRequestTool } from "./create-pull-request"
import { listReposTool } from "./list-repos"
import { rewriteFileTool } from "./rewrite-file"
import { scrapeWebpageTool } from "./scrape-webpage"
import { searchCodebaseTool } from "./search-codebase"
import { viewFileTool } from "./view-file"
import { viewHierarchyTool } from "./view-hierarchy"
import { fetchGitHubIssueTool } from "./fetch-github-issue"
import { postGitHubCommentTool } from "./post-github-comment"
import { updatePullRequest } from "./update-pull-request"
import { closePullRequest } from "./close-pull-request"
import { listPullRequestsTool } from "./list-pull-requests"

const allTools = {
create_file: createFileTool,
Expand All @@ -24,7 +28,11 @@ const allTools = {
view_hierarchy: viewHierarchyTool,
create_pull_request: createPullRequestTool,
create_branch: createBranchTool,
search_codebase: searchCodebaseTool
fetch_github_issue: fetchGitHubIssueTool,
post_github_comment: postGitHubCommentTool,
update_pull_request: updatePullRequest,
close_pull_request: closePullRequest,
list_pull_requests: listPullRequestsTool
} as const;

type ToolName = keyof typeof allTools;
Expand Down Expand Up @@ -56,7 +64,6 @@ export const getToolContext = async (body: ToolContextBody): Promise<ToolContext
const user = await currentUser();
const gitHubToken = user ? await getGitHubToken(user) : undefined;
const firecrawlToken = process.env.FIRECRAWL_API_KEY;
const greptileToken = process.env.GREPTILE_API_KEY;

// Find the full model object based on the provided model ID
const modelObj = models.find((m: Model) => m.id === modelId);
Expand Down Expand Up @@ -84,7 +91,6 @@ export const getToolContext = async (body: ToolContextBody): Promise<ToolContext
user: user as User | null,
gitHubToken,
firecrawlToken,
greptileToken,
model
};
};
};
74 changes: 74 additions & 0 deletions tools/list-pull-requests.ts
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}`,
};
}
},
});
Loading

0 comments on commit b12f1ff

Please sign in to comment.