-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathupdate_pr.ts
More file actions
167 lines (159 loc) · 5.03 KB
/
Copy pathupdate_pr.ts
File metadata and controls
167 lines (159 loc) · 5.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
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
import type { PRResponse, UpdatePRParams } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const updatePRTool: ToolConfig<UpdatePRParams, PRResponse> = {
id: 'github_update_pr',
name: 'GitHub Update Pull Request',
description: 'Update an existing pull request in a GitHub repository',
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',
},
title: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New pull request title',
},
body: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New pull request description (Markdown)',
},
state: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New state (open or closed)',
},
base: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'New base branch 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}/pulls/${params.pullNumber}`,
method: 'PATCH',
headers: (params) => ({
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}),
body: (params) => {
const body: Record<string, any> = {}
if (params.title !== undefined) body.title = params.title
if (params.body !== undefined) body.body = params.body
if (params.state !== undefined) body.state = params.state
if (params.base !== undefined) body.base = params.base
return body
},
},
transformResponse: async (response) => {
const pr = await response.json()
const content = `PR #${pr.number} updated: "${pr.title}" (${pr.state})
URL: ${pr.html_url}`
return {
success: true,
output: {
content,
metadata: {
number: pr.number,
title: pr.title,
state: pr.state,
html_url: pr.html_url,
merged: pr.merged,
draft: pr.draft,
created_at: pr.created_at,
updated_at: pr.updated_at,
},
},
}
},
outputs: {
content: { type: 'string', description: 'Human-readable PR update confirmation' },
metadata: {
type: 'object',
description: 'Updated pull request metadata',
properties: {
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' },
merged: { type: 'boolean', description: 'Whether PR is merged' },
draft: { type: 'boolean', description: 'Whether PR is draft' },
created_at: { type: 'string', description: 'Creation timestamp' },
updated_at: { type: 'string', description: 'Last update timestamp' },
},
},
},
}
export const updatePRV2Tool: ToolConfig = {
id: 'github_update_pr_v2',
name: updatePRTool.name,
description: updatePRTool.description,
version: '2.0.0',
params: updatePRTool.params,
request: updatePRTool.request,
oauth: updatePRTool.oauth,
transformResponse: async (response: Response) => {
const pr = await response.json()
return {
success: true,
output: {
id: pr.id,
number: pr.number,
title: pr.title,
state: pr.state,
html_url: pr.html_url,
body: pr.body ?? null,
user: pr.user,
head: pr.head,
base: pr.base,
draft: pr.draft,
merged: pr.merged,
created_at: pr.created_at,
updated_at: pr.updated_at,
},
}
},
outputs: {
id: { type: 'number', description: 'PR ID' },
number: { type: 'number', description: 'PR number' },
title: { type: 'string', description: 'PR title' },
state: { type: 'string', description: 'PR state' },
html_url: { type: 'string', description: 'GitHub web URL' },
body: { type: 'string', description: 'PR description', optional: true },
user: { type: 'json', description: 'User who created the PR' },
head: { type: 'json', description: 'Head branch info' },
base: { type: 'json', description: 'Base branch info' },
draft: { type: 'boolean', description: 'Whether PR is a draft' },
merged: { type: 'boolean', description: 'Whether PR is merged' },
created_at: { type: 'string', description: 'Creation timestamp' },
updated_at: { type: 'string', description: 'Last update timestamp' },
},
}