-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathcreate_branch.ts
More file actions
118 lines (108 loc) · 3.13 KB
/
Copy pathcreate_branch.ts
File metadata and controls
118 lines (108 loc) · 3.13 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
import type { CreateBranchParams, RefResponse } from '@/tools/github/types'
import { GIT_REF_OUTPUT_PROPERTIES } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const createBranchTool: ToolConfig<CreateBranchParams, RefResponse> = {
id: 'github_create_branch',
name: 'GitHub Create Branch',
description:
'Create a new branch in a GitHub repository by creating a git reference pointing to a specific commit SHA.',
version: '1.0.0',
params: {
owner: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository owner (user or organization)',
},
repo: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository name',
},
branch: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Name of the branch to create',
},
sha: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Commit SHA to point the branch to',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitHub Personal Access Token',
},
},
request: {
url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}/git/refs`,
method: 'POST',
headers: (params) => ({
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
'Content-Type': 'application/json',
}),
body: (params) => ({
ref: `refs/heads/${params.branch}`,
sha: params.sha,
}),
},
transformResponse: async (response) => {
const ref = await response.json()
// Create a human-readable content string
const content = `Branch created successfully:
Branch: ${ref.ref.replace('refs/heads/', '')}
SHA: ${ref.object.sha}
URL: ${ref.url}`
return {
success: true,
output: {
content,
metadata: {
ref: ref.ref,
url: ref.url,
sha: ref.object.sha,
},
},
}
},
outputs: {
content: { type: 'string', description: 'Human-readable branch creation confirmation' },
metadata: {
type: 'object',
description: 'Git reference metadata',
properties: {
ref: { type: 'string', description: 'Full reference name (refs/heads/branch)' },
url: { type: 'string', description: 'API URL for the reference' },
sha: { type: 'string', description: 'Commit SHA the branch points to' },
},
},
},
}
export const createBranchV2Tool: ToolConfig<CreateBranchParams, any> = {
id: 'github_create_branch_v2',
name: createBranchTool.name,
description: createBranchTool.description,
version: '2.0.0',
params: createBranchTool.params,
request: createBranchTool.request,
transformResponse: async (response: Response) => {
const ref = await response.json()
return {
success: true,
output: {
ref: ref.ref,
node_id: ref.node_id,
url: ref.url,
object: ref.object,
},
}
},
outputs: GIT_REF_OUTPUT_PROPERTIES,
}