forked from simstudioai/sim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr.ts
More file actions
126 lines (117 loc) · 4.03 KB
/
Copy pathpr.ts
File metadata and controls
126 lines (117 loc) · 4.03 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
import type { PROperationParams, PullRequestResponse } 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()
// Fetch the PR diff
const diffResponse = await fetch(pr.diff_url)
const _diff = await diffResponse.text()
// 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()
// Create a human-readable content string
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)' },
},
},
},
},
},
},
}