-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathget_commit.ts
More file actions
223 lines (208 loc) · 6.21 KB
/
get_commit.ts
File metadata and controls
223 lines (208 loc) · 6.21 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import {
COMMIT_DATA_OUTPUT,
COMMIT_FILE_OUTPUT_PROPERTIES,
COMMIT_PARENT_OUTPUT_PROPERTIES,
COMMIT_STATS_OUTPUT,
COMMIT_SUMMARY_OUTPUT_PROPERTIES,
USER_FULL_OUTPUT,
} from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
interface GetCommitParams {
owner: string
repo: string
ref: string
apiKey: string
}
interface GetCommitResponse {
success: boolean
output: {
content: string
metadata: {
sha: string
html_url: string
message: string
author: { name: string; email: string; date: string; login?: string }
committer: { name: string; email: string; date: string; login?: string }
stats: { additions: number; deletions: number; total: number }
files: Array<{
filename: string
status: string
additions: number
deletions: number
changes: number
patch?: string
}>
parents: Array<{ sha: string; html_url: string }>
}
}
}
export const getCommitTool: ToolConfig<GetCommitParams, GetCommitResponse> = {
id: 'github_get_commit',
name: 'GitHub Get Commit',
description: 'Get detailed information about a specific commit including files changed and stats',
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',
},
ref: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Commit SHA, branch name, or tag name',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitHub API token',
},
},
request: {
url: (params) =>
`https://api.github.com/repos/${params.owner}/${params.repo}/commits/${params.ref}`,
method: 'GET',
headers: (params) => ({
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}),
},
transformResponse: async (response) => {
const data = await response.json()
const files = (data.files ?? []).map((f: any) => ({
filename: f.filename,
status: f.status,
additions: f.additions,
deletions: f.deletions,
changes: f.changes,
patch: f.patch,
}))
const metadata = {
sha: data.sha,
html_url: data.html_url,
message: data.commit.message,
author: {
name: data.commit.author.name,
email: data.commit.author.email,
date: data.commit.author.date,
login: data.author?.login,
},
committer: {
name: data.commit.committer.name,
email: data.commit.committer.email,
date: data.commit.committer.date,
login: data.committer?.login,
},
stats: data.stats ?? { additions: 0, deletions: 0, total: 0 },
files,
parents: data.parents.map((p: any) => ({ sha: p.sha, html_url: p.html_url })),
}
const content = `Commit ${data.sha.substring(0, 7)}
Message: ${data.commit.message.split('\n')[0]}
Author: ${metadata.author.login ?? metadata.author.name} (${metadata.author.date})
Stats: +${metadata.stats.additions} -${metadata.stats.deletions} (${files.length} files)
${data.html_url}
Files changed:
${files.map((f: any) => ` ${f.status}: ${f.filename} (+${f.additions} -${f.deletions})`).join('\n')}`
return {
success: true,
output: {
content,
metadata,
},
}
},
outputs: {
content: { type: 'string', description: 'Human-readable commit details' },
metadata: {
type: 'object',
description: 'Commit metadata',
properties: {
sha: { type: 'string', description: 'Full commit SHA' },
html_url: { type: 'string', description: 'GitHub web URL' },
message: { type: 'string', description: 'Commit message' },
author: { type: 'object', description: 'Author info' },
committer: { type: 'object', description: 'Committer info' },
stats: {
type: 'object',
description: 'Change stats',
properties: {
additions: { type: 'number', description: 'Lines added' },
deletions: { type: 'number', description: 'Lines deleted' },
total: { type: 'number', description: 'Total changes' },
},
},
files: {
type: 'array',
description: 'Changed files',
items: {
type: 'object',
properties: {
filename: { type: 'string', description: 'File path' },
status: { type: 'string', description: 'Change type' },
additions: { type: 'number', description: 'Lines added' },
deletions: { type: 'number', description: 'Lines deleted' },
changes: { type: 'number', description: 'Total changes' },
patch: { type: 'string', description: 'Diff patch', optional: true },
},
},
},
parents: { type: 'array', description: 'Parent commits' },
},
},
},
}
export const getCommitV2Tool: ToolConfig<GetCommitParams, any> = {
id: 'github_get_commit_v2',
name: getCommitTool.name,
description: getCommitTool.description,
version: '2.0.0',
params: getCommitTool.params,
request: getCommitTool.request,
transformResponse: async (response: Response) => {
const data = await response.json()
return {
success: true,
output: {
...data,
author: data.author ?? null,
committer: data.committer ?? null,
stats: data.stats ?? null,
files: data.files ?? [],
},
}
},
outputs: {
...COMMIT_SUMMARY_OUTPUT_PROPERTIES,
commit: COMMIT_DATA_OUTPUT,
author: USER_FULL_OUTPUT,
committer: USER_FULL_OUTPUT,
stats: COMMIT_STATS_OUTPUT,
files: {
type: 'array',
description: 'Changed files (diff entries)',
items: {
type: 'object',
properties: COMMIT_FILE_OUTPUT_PROPERTIES,
},
},
parents: {
type: 'array',
description: 'Parent commits',
items: {
type: 'object',
properties: COMMIT_PARENT_OUTPUT_PROPERTIES,
},
},
},
}