feat(github): add github read pr & write comment tools to the github block, tested & works

This commit is contained in:
Waleed Latif
2025-02-24 00:03:58 -08:00
parent 3f4e6041ce
commit 9ff1783dcf
5 changed files with 387 additions and 19 deletions
+110 -19
View File
@@ -1,15 +1,29 @@
import { RepoInfoResponse } from '@/tools/github/repo'
import { GithubIcon } from '../../components/icons'
import { GithubIcon } from '@/components/icons'
import { CreateCommentResponse, PullRequestResponse } from '@/tools/github/types'
import { BlockConfig } from '../types'
export const GitHubBlock: BlockConfig<RepoInfoResponse> = {
type GitHubResponse = PullRequestResponse | CreateCommentResponse
export const GitHubBlock: BlockConfig<GitHubResponse> = {
type: 'github',
name: 'GitHub',
description: 'Fetch GitHub repository',
description: 'Interact with GitHub repositories and PRs',
category: 'tools',
bgColor: '#181C1E',
icon: GithubIcon,
subBlocks: [
{
id: 'operation',
title: 'Operation',
type: 'dropdown',
layout: 'full',
options: [
{ label: 'Get PR details', id: 'github_pr' },
{ label: 'Create PR comment', id: 'github_comment' },
{ label: 'Get repository info', id: 'github_repoinfo' },
],
value: () => 'github_pr',
},
{
id: 'owner',
title: 'Repository Owner',
@@ -25,15 +39,20 @@ export const GitHubBlock: BlockConfig<RepoInfoResponse> = {
placeholder: 'e.g., vscode',
},
{
id: 'action',
title: 'Action',
type: 'dropdown',
id: 'pullNumber',
title: 'Pull Request Number',
type: 'short-input',
layout: 'half',
placeholder: 'e.g., 123',
condition: { field: 'operation', value: 'github_pr' },
},
{
id: 'body',
title: 'Comment',
type: 'long-input',
layout: 'full',
options: [
{ label: 'Get general info', id: 'general_info' },
{ label: 'Get pull requests', id: 'pull_requests' },
],
value: () => 'general_info',
placeholder: 'Enter comment text',
condition: { field: 'operation', value: 'github_comment' },
},
{
id: 'apiKey',
@@ -43,23 +62,95 @@ export const GitHubBlock: BlockConfig<RepoInfoResponse> = {
placeholder: 'Enter GitHub Token',
password: true,
},
{
id: 'commentType',
title: 'Comment Type',
type: 'dropdown',
layout: 'half',
options: [
{ label: 'General PR Comment', id: 'pr_comment' },
{ label: 'File-specific Comment', id: 'file_comment' },
],
condition: { field: 'operation', value: 'github_comment' },
},
{
id: 'path',
title: 'File Path',
type: 'short-input',
layout: 'half',
placeholder: 'e.g., src/main.ts',
condition: {
field: 'operation',
value: 'github_comment',
and: {
field: 'commentType',
value: 'file_comment',
},
},
},
{
id: 'line',
title: 'Line Number',
type: 'short-input',
layout: 'half',
placeholder: 'e.g., 42',
condition: {
field: 'operation',
value: 'github_comment',
and: {
field: 'commentType',
value: 'file_comment',
},
},
},
],
tools: {
access: ['github_repoinfo'],
access: ['github_pr', 'github_comment', 'github_repoinfo'],
config: {
tool: (params) => {
switch (params.operation) {
case 'github_pr':
return 'github_pr'
case 'github_comment':
return 'github_comment'
case 'github_repoinfo':
default:
return 'github_repoinfo'
}
},
},
},
inputs: {
operation: { type: 'string', required: true },
owner: { type: 'string', required: true },
repo: { type: 'string', required: true },
pullNumber: { type: 'number', required: false },
body: { type: 'string', required: false },
apiKey: { type: 'string', required: true },
commentType: { type: 'string', required: false },
path: { type: 'string', required: false },
line: { type: 'number', required: false },
side: { type: 'string', required: false },
commitId: { type: 'string', required: false },
},
outputs: {
response: {
type: {
name: 'string',
description: 'string',
stars: 'number',
forks: 'number',
openIssues: 'number',
language: 'string',
body: 'string',
html_url: 'string',
created_at: 'string',
updated_at: 'string',
number: 'number',
title: 'string',
state: 'string',
diff_url: 'string',
files: 'any',
comments: 'any',
id: 'number',
path: 'any',
line: 'any',
side: 'any',
commit_id: 'any',
},
},
},