-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathremove_label.ts
More file actions
144 lines (134 loc) · 4 KB
/
Copy pathremove_label.ts
File metadata and controls
144 lines (134 loc) · 4 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
import type { LabelsResponse, RemoveLabelParams } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const removeLabelTool: ToolConfig<RemoveLabelParams, LabelsResponse> = {
id: 'github_remove_label',
name: 'GitHub Remove Label',
description: 'Remove a label from an issue 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',
},
issue_number: {
type: 'number',
required: true,
visibility: 'user-or-llm',
description: 'Issue number',
},
name: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Label name to remove',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitHub API token',
},
},
request: {
url: (params) =>
`https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}/labels/${encodeURIComponent(params.name)}`,
method: 'DELETE',
headers: (params) => ({
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}),
},
transformResponse: async (response, params) => {
if (!params) {
return {
success: false,
error: 'Missing parameters',
output: {
content: '',
metadata: {
labels: [],
issue_number: 0,
html_url: '',
},
},
}
}
const labelsData = await response.json()
const labels = labelsData.map((label: any) => label.name)
const content = `Label "${params.name}" removed from issue #${params.issue_number}
${labels.length > 0 ? `Remaining labels: ${labels.join(', ')}` : 'No labels remaining on this issue'}`
return {
success: true,
output: {
content,
metadata: {
labels,
issue_number: params.issue_number,
html_url: `https://github.com/${params.owner}/${params.repo}/issues/${params.issue_number}`,
},
},
}
},
outputs: {
content: { type: 'string', description: 'Human-readable label removal confirmation' },
metadata: {
type: 'object',
description: 'Remaining labels metadata',
properties: {
labels: { type: 'array', description: 'Labels remaining on the issue after removal' },
issue_number: { type: 'number', description: 'Issue number' },
html_url: { type: 'string', description: 'GitHub issue URL' },
},
},
},
}
export const removeLabelV2Tool: ToolConfig = {
id: 'github_remove_label_v2',
name: removeLabelTool.name,
description: removeLabelTool.description,
version: '2.0.0',
params: removeLabelTool.params,
request: removeLabelTool.request,
oauth: removeLabelTool.oauth,
transformResponse: async (response: Response) => {
if (response.status === 200) {
const labels = await response.json()
return {
success: true,
output: {
items: labels.map((label: any) => ({
...label,
description: label.description ?? null,
})),
count: labels.length,
},
}
}
return { success: true, output: { items: [], count: 0 } }
},
outputs: {
items: {
type: 'array',
description: 'Remaining labels on the issue',
items: {
type: 'object',
properties: {
id: { type: 'number', description: 'Label ID' },
name: { type: 'string', description: 'Label name' },
color: { type: 'string', description: 'Label color' },
description: { type: 'string', description: 'Label description', optional: true },
},
},
},
count: { type: 'number', description: 'Number of remaining labels' },
},
}