-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathget_milestone.ts
More file actions
160 lines (147 loc) · 4.6 KB
/
Copy pathget_milestone.ts
File metadata and controls
160 lines (147 loc) · 4.6 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
import { MILESTONE_CREATOR_OUTPUT, MILESTONE_V2_OUTPUT_PROPERTIES } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
interface GetMilestoneParams {
owner: string
repo: string
milestone_number: number
apiKey: string
}
interface GetMilestoneResponse {
success: boolean
output: {
content: string
metadata: {
number: number
title: string
description: string | null
state: string
html_url: string
due_on: string | null
open_issues: number
closed_issues: number
created_at: string
updated_at: string
closed_at: string | null
creator: { login: string }
}
}
}
export const getMilestoneTool: ToolConfig<GetMilestoneParams, GetMilestoneResponse> = {
id: 'github_get_milestone',
name: 'GitHub Get Milestone',
description: 'Get a specific milestone by number',
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',
},
milestone_number: {
type: 'number',
required: true,
visibility: 'user-or-llm',
description: 'Milestone 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}/milestones/${params.milestone_number}`,
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 progress =
data.open_issues + data.closed_issues > 0
? Math.round((data.closed_issues / (data.open_issues + data.closed_issues)) * 100)
: 0
const content = `Milestone: ${data.title} (#${data.number})
State: ${data.state} | Progress: ${progress}% (${data.closed_issues}/${data.open_issues + data.closed_issues} issues)
Due: ${data.due_on ?? 'No due date'}
Description: ${data.description ?? 'No description'}
${data.html_url}`
return {
success: true,
output: {
content,
metadata: {
number: data.number,
title: data.title,
description: data.description ?? null,
state: data.state,
html_url: data.html_url,
due_on: data.due_on ?? null,
open_issues: data.open_issues,
closed_issues: data.closed_issues,
created_at: data.created_at,
updated_at: data.updated_at,
closed_at: data.closed_at ?? null,
creator: { login: data.creator?.login ?? 'unknown' },
},
},
}
},
outputs: {
content: { type: 'string', description: 'Human-readable milestone details' },
metadata: {
type: 'object',
description: 'Milestone metadata',
properties: {
number: { type: 'number', description: 'Milestone number' },
title: { type: 'string', description: 'Title' },
description: { type: 'string', description: 'Description', optional: true },
state: { type: 'string', description: 'State' },
html_url: { type: 'string', description: 'Web URL' },
due_on: { type: 'string', description: 'Due date', optional: true },
open_issues: { type: 'number', description: 'Open issues count' },
closed_issues: { type: 'number', description: 'Closed issues count' },
created_at: { type: 'string', description: 'Creation date' },
updated_at: { type: 'string', description: 'Update date' },
closed_at: { type: 'string', description: 'Close date', optional: true },
creator: { type: 'object', description: 'Creator info' },
},
},
},
}
export const getMilestoneV2Tool: ToolConfig<GetMilestoneParams, any> = {
id: 'github_get_milestone_v2',
name: getMilestoneTool.name,
description: getMilestoneTool.description,
version: '2.0.0',
params: getMilestoneTool.params,
request: getMilestoneTool.request,
transformResponse: async (response: Response) => {
const data = await response.json()
return {
success: true,
output: {
...data,
description: data.description ?? null,
due_on: data.due_on ?? null,
closed_at: data.closed_at ?? null,
},
}
},
outputs: {
...MILESTONE_V2_OUTPUT_PROPERTIES,
creator: MILESTONE_CREATOR_OUTPUT,
},
}