-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathpr.ts
More file actions
204 lines (191 loc) · 6.84 KB
/
Copy pathpr.ts
File metadata and controls
204 lines (191 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import type { PROperationParams, PullRequestResponse } from '@/tools/github/types'
import { BRANCH_REF_OUTPUT, PR_FILE_OUTPUT_PROPERTIES, USER_OUTPUT } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const prTool: ToolConfig<PROperationParams, PullRequestResponse> = {
id: 'github_pr',
name: 'GitHub PR Reader',
description: 'Fetch PR details including diff and files changed',
version: '1.0.0',
params: {
owner: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository owner',
},
repo: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository name',
},
pullNumber: {
type: 'number',
required: true,
visibility: 'user-or-llm',
description: 'Pull request number',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitHub API token',
},
},
request: {
url: (params) =>
`https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}`,
method: 'GET',
headers: (params) => ({
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${params.apiKey}`,
}),
},
transformResponse: async (response) => {
const pr = await response.json()
const filesResponse = await fetch(
`https://api.github.com/repos/${pr.base.repo.owner.login}/${pr.base.repo.name}/pulls/${pr.number}/files`
)
const files = await filesResponse.json()
const content = `PR #${pr.number}: "${pr.title}" (${pr.state}) - Created: ${pr.created_at}, Updated: ${pr.updated_at}
Description: ${pr.body || 'No description'}
Files changed: ${files.length}
URL: ${pr.html_url}`
return {
success: true,
output: {
content,
metadata: {
number: pr.number,
title: pr.title,
state: pr.state,
html_url: pr.html_url,
diff_url: pr.diff_url,
created_at: pr.created_at,
updated_at: pr.updated_at,
files: files.map((file: any) => ({
filename: file.filename,
additions: file.additions,
deletions: file.deletions,
changes: file.changes,
patch: file.patch,
blob_url: file.blob_url,
raw_url: file.raw_url,
status: file.status,
})),
},
},
}
},
outputs: {
content: { type: 'string', description: 'Human-readable PR summary' },
metadata: {
type: 'object',
description: 'Detailed PR metadata including file changes',
properties: {
number: { type: 'number', description: 'Pull request number' },
title: { type: 'string', description: 'PR title' },
state: { type: 'string', description: 'PR state (open/closed/merged)' },
html_url: { type: 'string', description: 'GitHub web URL' },
diff_url: { type: 'string', description: 'Raw diff URL' },
created_at: { type: 'string', description: 'Creation timestamp' },
updated_at: { type: 'string', description: 'Last update timestamp' },
files: {
type: 'array',
description: 'Files changed in the PR',
items: {
type: 'object',
properties: {
filename: { type: 'string', description: 'File path' },
additions: { type: 'number', description: 'Lines added' },
deletions: { type: 'number', description: 'Lines deleted' },
changes: { type: 'number', description: 'Total changes' },
patch: { type: 'string', description: 'File diff patch' },
blob_url: { type: 'string', description: 'GitHub blob URL' },
raw_url: { type: 'string', description: 'Raw file URL' },
status: { type: 'string', description: 'Change type (added/modified/deleted)' },
},
},
},
},
},
},
}
export const prV2Tool: ToolConfig<PROperationParams, any> = {
id: 'github_pr_v2',
name: prTool.name,
description: prTool.description,
version: '2.0.0',
params: prTool.params,
request: prTool.request,
transformResponse: async (response: Response) => {
const pr = await response.json()
// Fetch files changed
const filesResponse = await fetch(
`https://api.github.com/repos/${pr.base.repo.owner.login}/${pr.base.repo.name}/pulls/${pr.number}/files`
)
const files = await filesResponse.json()
return {
success: true,
output: {
id: pr.id,
number: pr.number,
title: pr.title,
state: pr.state,
html_url: pr.html_url,
diff_url: pr.diff_url,
body: pr.body ?? null,
user: pr.user,
head: pr.head,
base: pr.base,
merged: pr.merged,
mergeable: pr.mergeable ?? null,
merged_by: pr.merged_by ?? null,
comments: pr.comments,
review_comments: pr.review_comments,
commits: pr.commits,
additions: pr.additions,
deletions: pr.deletions,
changed_files: pr.changed_files,
created_at: pr.created_at,
updated_at: pr.updated_at,
closed_at: pr.closed_at ?? null,
merged_at: pr.merged_at ?? null,
files: files ?? [],
},
}
},
outputs: {
id: { type: 'number', description: 'Pull request ID' },
number: { type: 'number', description: 'Pull request number' },
title: { type: 'string', description: 'PR title' },
state: { type: 'string', description: 'PR state (open/closed)' },
html_url: { type: 'string', description: 'GitHub web URL' },
diff_url: { type: 'string', description: 'Raw diff URL' },
body: { type: 'string', description: 'PR description' },
user: USER_OUTPUT,
head: BRANCH_REF_OUTPUT,
base: BRANCH_REF_OUTPUT,
merged: { type: 'boolean', description: 'Whether PR is merged' },
mergeable: { type: 'boolean', description: 'Whether PR is mergeable' },
merged_by: USER_OUTPUT,
comments: { type: 'number', description: 'Number of comments' },
review_comments: { type: 'number', description: 'Number of review comments' },
commits: { type: 'number', description: 'Number of commits' },
additions: { type: 'number', description: 'Lines added' },
deletions: { type: 'number', description: 'Lines deleted' },
changed_files: { type: 'number', description: 'Number of changed files' },
created_at: { type: 'string', description: 'Creation timestamp' },
updated_at: { type: 'string', description: 'Last update timestamp' },
closed_at: { type: 'string', description: 'Close timestamp' },
merged_at: { type: 'string', description: 'Merge timestamp' },
files: {
type: 'array',
description: 'Array of changed file objects',
items: {
type: 'object',
properties: PR_FILE_OUTPUT_PROPERTIES,
},
},
},
}