@andrebuzeli/git-mcp 2.29.3 → 2.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/providers/error-handler.d.ts +0 -24
- package/dist/providers/error-handler.d.ts.map +1 -1
- package/dist/providers/error-handler.js +0 -59
- package/dist/providers/error-handler.js.map +1 -1
- package/dist/providers/gitea-provider.d.ts.map +1 -1
- package/dist/providers/gitea-provider.js +30 -13
- package/dist/providers/gitea-provider.js.map +1 -1
- package/dist/providers/github-provider.d.ts.map +1 -1
- package/dist/providers/github-provider.js +7 -1
- package/dist/providers/github-provider.js.map +1 -1
- package/dist/server.js +7 -7
- package/dist/server.js.map +1 -1
- package/dist/tools/git-archive.d.ts +1 -1
- package/dist/tools/git-archive.d.ts.map +1 -1
- package/dist/tools/git-archive.js +71 -30
- package/dist/tools/git-archive.js.map +1 -1
- package/dist/tools/git-branches.d.ts +2 -2
- package/dist/tools/git-branches.d.ts.map +1 -1
- package/dist/tools/git-branches.js.map +1 -1
- package/dist/tools/git-commits.d.ts +2 -2
- package/dist/tools/git-commits.d.ts.map +1 -1
- package/dist/tools/git-commits.js.map +1 -1
- package/dist/tools/git-config.d.ts.map +1 -1
- package/dist/tools/git-config.js.map +1 -1
- package/dist/tools/git-files.d.ts +2 -2
- package/dist/tools/git-files.d.ts.map +1 -1
- package/dist/tools/git-files.js.map +1 -1
- package/dist/tools/git-initialize.d.ts +42 -42
- package/dist/tools/git-initialize.d.ts.map +1 -1
- package/dist/tools/git-initialize.js +68 -66
- package/dist/tools/git-initialize.js.map +1 -1
- package/dist/tools/git-issues.d.ts.map +1 -1
- package/dist/tools/git-issues.js.map +1 -1
- package/dist/tools/git-pulls.d.ts.map +1 -1
- package/dist/tools/git-pulls.js.map +1 -1
- package/dist/tools/git-releases.d.ts.map +1 -1
- package/dist/tools/git-releases.js.map +1 -1
- package/dist/tools/git-remote.d.ts.map +1 -1
- package/dist/tools/git-remote.js.map +1 -1
- package/dist/tools/git-repositories.d.ts.map +1 -1
- package/dist/tools/git-repositories.js.map +1 -1
- package/dist/tools/git-reset.d.ts.map +1 -1
- package/dist/tools/git-reset.js +6 -4
- package/dist/tools/git-reset.js.map +1 -1
- package/dist/tools/git-revert.d.ts.map +1 -1
- package/dist/tools/git-revert.js.map +1 -1
- package/dist/tools/git-stash.d.ts.map +1 -1
- package/dist/tools/git-stash.js.map +1 -1
- package/dist/tools/git-sync.d.ts +2 -2
- package/dist/tools/git-sync.d.ts.map +1 -1
- package/dist/tools/git-sync.js.map +1 -1
- package/dist/tools/git-tags.d.ts.map +1 -1
- package/dist/tools/git-tags.js.map +1 -1
- package/dist/tools/git-upload-project.d.ts +1 -5
- package/dist/tools/git-upload-project.d.ts.map +1 -1
- package/dist/tools/git-upload-project.js +1 -21
- package/dist/tools/git-upload-project.js.map +1 -1
- package/dist/tools/git-webhooks.d.ts +473 -477
- package/dist/tools/git-webhooks.d.ts.map +1 -1
- package/dist/tools/git-webhooks.js +544 -561
- package/dist/tools/git-webhooks.js.map +1 -1
- package/package.json +59 -59
|
@@ -1,562 +1,545 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.webhooksTool = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const index_js_1 = require("../providers/index.js");
|
|
6
|
-
const user_detection_js_1 = require("../utils/user-detection.js");
|
|
7
|
-
/**
|
|
8
|
-
* Tool: webhooks
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Gerenciamento completo de webhooks com suporte multi-provider (GitHub e Gitea)
|
|
12
|
-
*
|
|
13
|
-
* FUNCIONALIDADES:
|
|
14
|
-
* -
|
|
15
|
-
* - Listagem e busca de webhooks
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
18
|
-
* -
|
|
19
|
-
* - Teste de webhooks
|
|
20
|
-
* -
|
|
21
|
-
*
|
|
22
|
-
* USO:
|
|
23
|
-
* - Para
|
|
24
|
-
* - Para
|
|
25
|
-
* - Para
|
|
26
|
-
* - Para
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* - Use HTTPS sempre que
|
|
30
|
-
* - Mantenha secrets seguros
|
|
31
|
-
* - Monitore falhas de entrega
|
|
32
|
-
* - Configure apenas eventos
|
|
33
|
-
*/
|
|
34
|
-
/**
|
|
35
|
-
* Schema de
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* - action:
|
|
39
|
-
* -
|
|
40
|
-
* -
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* - Sempre valide entrada antes de usar
|
|
44
|
-
* - Use
|
|
45
|
-
* - Documente
|
|
46
|
-
*/
|
|
47
|
-
const WebhooksInputSchema = zod_1.z.object({
|
|
48
|
-
action: zod_1.z.enum(['create', 'list', 'get', 'update', 'delete', 'test']),
|
|
49
|
-
//
|
|
50
|
-
repo: zod_1.z.string(),
|
|
51
|
-
// Para multi-provider
|
|
52
|
-
provider: zod_1.z.enum(['gitea', 'github']).describe('Provider to use (gitea or github)'), // Provider
|
|
53
|
-
projectPath: zod_1.z.string().describe('Local project path for git operations'),
|
|
54
|
-
// Para create
|
|
55
|
-
url: zod_1.z.string().optional(),
|
|
56
|
-
content_type: zod_1.z.enum(['json', 'form']).optional(),
|
|
57
|
-
secret: zod_1.z.string().optional(),
|
|
58
|
-
events: zod_1.z.array(zod_1.z.string()).optional(),
|
|
59
|
-
active: zod_1.z.boolean().optional(),
|
|
60
|
-
// Para get/update/delete/test
|
|
61
|
-
webhook_id: zod_1.z.number().optional(),
|
|
62
|
-
// Para list
|
|
63
|
-
page: zod_1.z.number().min(1).optional(),
|
|
64
|
-
limit: zod_1.z.number().min(1).max(100).optional(),
|
|
65
|
-
// Para update
|
|
66
|
-
new_url: zod_1.z.string().optional(),
|
|
67
|
-
new_content_type: zod_1.z.enum(['json', 'form']).optional(),
|
|
68
|
-
new_secret: zod_1.z.string().optional(),
|
|
69
|
-
new_events: zod_1.z.array(zod_1.z.string()).optional(),
|
|
70
|
-
new_active: zod_1.z.boolean().optional(),
|
|
71
|
-
});
|
|
72
|
-
/**
|
|
73
|
-
* Schema de
|
|
74
|
-
*
|
|
75
|
-
* ESTRUTURA:
|
|
76
|
-
* - success: Status da
|
|
77
|
-
* - action:
|
|
78
|
-
* - message: Mensagem descritiva
|
|
79
|
-
* - data: Dados retornados (opcional)
|
|
80
|
-
* - error: Detalhes do erro (opcional)
|
|
81
|
-
*/
|
|
82
|
-
const WebhooksResultSchema = zod_1.z.object({
|
|
83
|
-
success: zod_1.z.boolean(),
|
|
84
|
-
action: zod_1.z.string(),
|
|
85
|
-
message: zod_1.z.string(),
|
|
86
|
-
data: zod_1.z.any().optional(),
|
|
87
|
-
error: zod_1.z.string().optional()
|
|
88
|
-
});
|
|
89
|
-
/**
|
|
90
|
-
* Tool: webhooks
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* Gerenciamento completo de webhooks Gitea com
|
|
94
|
-
*
|
|
95
|
-
* ACTIONS
|
|
96
|
-
*
|
|
97
|
-
* 1. create - Criar novo webhook
|
|
98
|
-
*
|
|
99
|
-
* - owner (
|
|
100
|
-
* - repo (
|
|
101
|
-
* - url (
|
|
102
|
-
* - content_type (opcional): Tipo de
|
|
103
|
-
* - secret (opcional): Secret para assinatura
|
|
104
|
-
* - events (opcional): Array de eventos a serem monitorados
|
|
105
|
-
* - active (opcional): Se webhook
|
|
106
|
-
*
|
|
107
|
-
* 2. list - Listar webhooks
|
|
108
|
-
*
|
|
109
|
-
* - owner (
|
|
110
|
-
* - repo (
|
|
111
|
-
* - page (opcional):
|
|
112
|
-
* - limit (opcional): Itens por
|
|
113
|
-
*
|
|
114
|
-
* 3. get - Obter detalhes do webhook
|
|
115
|
-
*
|
|
116
|
-
* - owner (
|
|
117
|
-
* - repo (
|
|
118
|
-
* - webhook_id (
|
|
119
|
-
*
|
|
120
|
-
* 4. update - Atualizar webhook existente
|
|
121
|
-
*
|
|
122
|
-
* - owner (
|
|
123
|
-
* - repo (
|
|
124
|
-
* - webhook_id (
|
|
125
|
-
* - new_url (opcional): Nova URL
|
|
126
|
-
* - new_content_type (opcional): Novo tipo de
|
|
127
|
-
* - new_secret (opcional): Novo secret
|
|
128
|
-
* - new_events (opcional): Novos eventos
|
|
129
|
-
* - new_active (opcional): Novo status ativo
|
|
130
|
-
*
|
|
131
|
-
* 5. delete - Deletar webhook
|
|
132
|
-
*
|
|
133
|
-
* - owner (
|
|
134
|
-
* - repo (
|
|
135
|
-
* - webhook_id (
|
|
136
|
-
*
|
|
137
|
-
* 6. test - Testar webhook
|
|
138
|
-
*
|
|
139
|
-
* - owner (
|
|
140
|
-
* - repo (
|
|
141
|
-
* - webhook_id (
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* - Use URLs seguras (HTTPS)
|
|
145
|
-
* - Configure eventos adequadamente
|
|
146
|
-
* - Monitore falhas de entrega
|
|
147
|
-
* - Mantenha secrets seguros
|
|
148
|
-
* - Teste webhooks antes de ativar
|
|
149
|
-
* - Configure retry adequado
|
|
150
|
-
* - Monitore logs de entrega
|
|
151
|
-
*/
|
|
152
|
-
exports.webhooksTool = {
|
|
153
|
-
name: 'git-webhooks',
|
|
154
|
-
description: 'tool: Gerencia webhooks Git para
|
|
155
|
-
inputSchema: {
|
|
156
|
-
type: 'object',
|
|
157
|
-
properties: {
|
|
158
|
-
action: {
|
|
159
|
-
type: 'string',
|
|
160
|
-
enum: ['create', 'list', 'get', 'update', 'delete', 'test'],
|
|
161
|
-
description: 'Action to perform on webhooks'
|
|
162
|
-
},
|
|
163
|
-
repo: { type: 'string', description: 'Repository name' },
|
|
164
|
-
provider: { type: 'string', description: 'Provider to use (github, gitea, or omit for default)' },
|
|
165
|
-
url: { type: 'string', description: 'Webhook URL' },
|
|
166
|
-
content_type: { type: 'string', enum: ['json', 'form'], description: 'Content type' },
|
|
167
|
-
secret: { type: 'string', description: 'Webhook secret' },
|
|
168
|
-
events: { type: 'array', items: { type: 'string' }, description: 'Webhook events' },
|
|
169
|
-
active: { type: 'boolean', description: 'Webhook active status' },
|
|
170
|
-
webhook_id: { type: 'number', description: 'Webhook ID' },
|
|
171
|
-
page: { type: 'number', description: 'Page number', minimum: 1 },
|
|
172
|
-
limit: { type: 'number', description: 'Items per page', minimum: 1, maximum: 100 },
|
|
173
|
-
new_url: { type: 'string', description: 'New webhook URL' },
|
|
174
|
-
new_content_type: { type: 'string', enum: ['json', 'form'], description: 'New content type' },
|
|
175
|
-
new_secret: { type: 'string', description: 'New webhook secret' },
|
|
176
|
-
new_events: { type: 'array', items: { type: 'string' }, description: 'New webhook events' },
|
|
177
|
-
new_active: { type: 'boolean', description: 'New webhook active status' }
|
|
178
|
-
},
|
|
179
|
-
required: ['action', 'repo', 'provider', 'projectPath']
|
|
180
|
-
},
|
|
181
|
-
/**
|
|
182
|
-
* Handler principal da tool webhooks
|
|
183
|
-
*
|
|
184
|
-
* FUNCIONALIDADE:
|
|
185
|
-
* - Valida entrada usando Zod schema
|
|
186
|
-
* - Roteia para
|
|
187
|
-
* - Trata erros de forma uniforme
|
|
188
|
-
* - Retorna resultado padronizado
|
|
189
|
-
*
|
|
190
|
-
* FLUXO:
|
|
191
|
-
* 1.
|
|
192
|
-
* 2.
|
|
193
|
-
* 3. Roteamento por
|
|
194
|
-
* 4.
|
|
195
|
-
* 5. Tratamento de erros
|
|
196
|
-
* 6. Retorno de resultado
|
|
197
|
-
*
|
|
198
|
-
* TRATAMENTO DE ERROS:
|
|
199
|
-
* -
|
|
200
|
-
* -
|
|
201
|
-
* - Roteamento:
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* - Sempre valide entrada antes de processar
|
|
205
|
-
* - Trate erros
|
|
206
|
-
* - Log detalhes de erro para debug
|
|
207
|
-
* - Retorne mensagens de erro
|
|
208
|
-
*/
|
|
209
|
-
async handler(input) {
|
|
210
|
-
try {
|
|
211
|
-
const validatedInput = WebhooksInputSchema.parse(input);
|
|
212
|
-
// Apply automatic user/owner detection from configured tokens
|
|
213
|
-
const processedInput = await (0, user_detection_js_1.applyAutoUserDetection)(validatedInput, validatedInput.provider || 'default');
|
|
214
|
-
// Seleciona o provider baseado na entrada ou usa o
|
|
215
|
-
const provider = processedInput.provider
|
|
216
|
-
? index_js_1.globalProviderFactory.getProvider(processedInput.provider)
|
|
217
|
-
: index_js_1.globalProviderFactory.getDefaultProvider();
|
|
218
|
-
if (!provider) {
|
|
219
|
-
throw new Error('Provider
|
|
220
|
-
}
|
|
221
|
-
// Obter o owner do provider
|
|
222
|
-
const owner = (await provider.getCurrentUser()).login;
|
|
223
|
-
switch (processedInput.action) {
|
|
224
|
-
case 'create':
|
|
225
|
-
return await this.createWebhook(processedInput, provider, owner);
|
|
226
|
-
case 'list':
|
|
227
|
-
return await this.listWebhooks(processedInput, provider, owner);
|
|
228
|
-
case 'get':
|
|
229
|
-
return await this.getWebhook(processedInput, provider, owner);
|
|
230
|
-
case 'update':
|
|
231
|
-
return await this.updateWebhook(processedInput, provider, owner);
|
|
232
|
-
case 'delete':
|
|
233
|
-
return await this.deleteWebhook(processedInput, provider, owner);
|
|
234
|
-
case 'test':
|
|
235
|
-
return await this.testWebhook(processedInput, provider, owner);
|
|
236
|
-
default:
|
|
237
|
-
throw new Error(`
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
return {
|
|
242
|
-
success: false,
|
|
243
|
-
action: input.action,
|
|
244
|
-
message: 'Erro na
|
|
245
|
-
error: error instanceof Error ? error.message : String(error)
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
/**
|
|
250
|
-
* Cria um novo webhook no
|
|
251
|
-
*
|
|
252
|
-
* FUNCIONALIDADE:
|
|
253
|
-
* - Cria webhook com URL e
|
|
254
|
-
* - Suporta diferentes tipos de
|
|
255
|
-
* - Permite
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* - owner:
|
|
259
|
-
* - repo: Nome do
|
|
260
|
-
* - url: URL de destino do webhook
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* - content_type: Tipo de
|
|
264
|
-
* - secret: Secret para assinatura
|
|
265
|
-
* - events: Array de eventos a serem monitorados
|
|
266
|
-
* - active: Se webhook
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* - Todos os
|
|
270
|
-
* - URL deve ser
|
|
271
|
-
* -
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* - Use URLs seguras (HTTPS)
|
|
275
|
-
* - Configure eventos adequadamente
|
|
276
|
-
* - Mantenha secrets seguros
|
|
277
|
-
* - Teste webhook antes de ativar
|
|
278
|
-
*/
|
|
279
|
-
async createWebhook(params, provider, owner) {
|
|
280
|
-
try {
|
|
281
|
-
if (!params.repo || !params.url) {
|
|
282
|
-
throw new Error('repo e url
|
|
283
|
-
}
|
|
284
|
-
const webhookData = {
|
|
285
|
-
url: params.url,
|
|
286
|
-
content_type: params.content_type || 'json',
|
|
287
|
-
secret: params.secret || '',
|
|
288
|
-
events: params.events || ['push'],
|
|
289
|
-
active: params.active !== undefined ? params.active : true
|
|
290
|
-
};
|
|
291
|
-
const webhook = await provider.createWebhook(owner, params.repo, params.url, params.events || ['push'], params.secret);
|
|
292
|
-
return {
|
|
293
|
-
success: true,
|
|
294
|
-
action: 'create',
|
|
295
|
-
message: `Webhook criado com sucesso para '${owner}/${params.repo}'`,
|
|
296
|
-
data: webhook
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
catch (error) {
|
|
300
|
-
throw new Error(`Falha ao criar webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
/**
|
|
304
|
-
* Lista webhooks do
|
|
305
|
-
*
|
|
306
|
-
* FUNCIONALIDADE:
|
|
307
|
-
* - Lista webhooks com
|
|
308
|
-
* - Retorna
|
|
309
|
-
* - Inclui status ativo e eventos configurados
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
* - owner:
|
|
313
|
-
* - repo: Nome do
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
* - page:
|
|
317
|
-
* - limit: Itens por
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* - e repo
|
|
321
|
-
* - Page deve ser >= 1
|
|
322
|
-
* - Limit deve ser entre 1 e 100
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* - Use
|
|
326
|
-
* - Monitore
|
|
327
|
-
* - Verifique status ativo de cada webhook
|
|
328
|
-
* - Mantenha webhooks organizados
|
|
329
|
-
*/
|
|
330
|
-
async listWebhooks(params, provider, owner) {
|
|
331
|
-
try {
|
|
332
|
-
if (!params.repo) {
|
|
333
|
-
throw new Error('owner e repo
|
|
334
|
-
}
|
|
335
|
-
const page = params.page || 1;
|
|
336
|
-
const limit = params.limit || 30;
|
|
337
|
-
const webhooks = await provider.listWebhooks((await provider.getCurrentUser()).login, params.repo, page, limit);
|
|
338
|
-
return {
|
|
339
|
-
success: true,
|
|
340
|
-
action: 'list',
|
|
341
|
-
message: `${webhooks.length} webhooks encontrados`,
|
|
342
|
-
data: {
|
|
343
|
-
webhooks,
|
|
344
|
-
page,
|
|
345
|
-
limit,
|
|
346
|
-
total: webhooks.length
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
catch (error) {
|
|
351
|
-
throw new Error(`Falha ao listar webhooks: ${error instanceof Error ? error.message : String(error)}`);
|
|
352
|
-
}
|
|
353
|
-
},
|
|
354
|
-
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* FUNCIONALIDADE:
|
|
358
|
-
* - Retorna
|
|
359
|
-
* - Inclui URL, tipo de
|
|
360
|
-
* - Mostra
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
* - owner:
|
|
364
|
-
* - repo: Nome do
|
|
365
|
-
* - webhook_id: ID do webhook
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
* - Todos os
|
|
369
|
-
* - Webhook deve existir no
|
|
370
|
-
* - ID deve ser
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* - Use para obter detalhes completos
|
|
374
|
-
* - Verifique
|
|
375
|
-
* - Analise eventos configurados
|
|
376
|
-
* - Monitore status ativo
|
|
377
|
-
*/
|
|
378
|
-
async getWebhook(params, provider, owner) {
|
|
379
|
-
try {
|
|
380
|
-
if (!params.repo || !params.webhook_id) {
|
|
381
|
-
throw new Error('repo e webhook_id
|
|
382
|
-
}
|
|
383
|
-
const webhook = await provider.getWebhook((await provider.getCurrentUser()).login, params.repo, params.webhook_id);
|
|
384
|
-
return {
|
|
385
|
-
success: true,
|
|
386
|
-
action: 'get',
|
|
387
|
-
message: `Webhook #${params.webhook_id} obtido com sucesso`,
|
|
388
|
-
data: webhook
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
catch (error) {
|
|
392
|
-
throw new Error(`Falha ao obter webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
/**
|
|
396
|
-
* Atualiza um webhook existente
|
|
397
|
-
*
|
|
398
|
-
* FUNCIONALIDADE:
|
|
399
|
-
* - Atualiza campos do webhook
|
|
400
|
-
* - Suporta
|
|
401
|
-
* - Permite
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
* - owner:
|
|
405
|
-
* - repo: Nome do
|
|
406
|
-
* - webhook_id: ID do webhook
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
* - new_url: Nova URL
|
|
410
|
-
* - new_content_type: Novo tipo de
|
|
411
|
-
* - new_secret: Novo secret
|
|
412
|
-
* - new_events: Novos eventos
|
|
413
|
-
* - new_active: Novo status ativo
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
* - Todos os
|
|
417
|
-
* - Webhook deve existir
|
|
418
|
-
* - Pelo menos um campo deve ser atualizado
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
* - Atualize apenas campos
|
|
422
|
-
* - Use mensagens de commit descritivas
|
|
423
|
-
* - Documente
|
|
424
|
-
* - Teste webhook
|
|
425
|
-
*/
|
|
426
|
-
async updateWebhook(params, provider, owner) {
|
|
427
|
-
try {
|
|
428
|
-
if (!params.repo || !params.webhook_id) {
|
|
429
|
-
throw new Error('repo e webhook_id
|
|
430
|
-
}
|
|
431
|
-
const updateData = {};
|
|
432
|
-
if (params.new_url)
|
|
433
|
-
updateData.url = params.new_url;
|
|
434
|
-
if (params.new_content_type)
|
|
435
|
-
updateData.content_type = params.new_content_type;
|
|
436
|
-
if (params.new_secret)
|
|
437
|
-
updateData.secret = params.new_secret;
|
|
438
|
-
if (params.new_events)
|
|
439
|
-
updateData.events = params.new_events;
|
|
440
|
-
if (params.new_active !== undefined)
|
|
441
|
-
updateData.active = params.new_active;
|
|
442
|
-
if (Object.keys(updateData).length === 0) {
|
|
443
|
-
throw new Error('Nenhum campo para atualizar foi fornecido');
|
|
444
|
-
}
|
|
445
|
-
const webhook = await provider.updateWebhook((await provider.getCurrentUser()).login, params.repo, params.webhook_id, updateData);
|
|
446
|
-
return {
|
|
447
|
-
success: true,
|
|
448
|
-
action: 'update',
|
|
449
|
-
message: `Webhook #${params.webhook_id} atualizado com sucesso`,
|
|
450
|
-
data: webhook
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
catch (error) {
|
|
454
|
-
throw new Error(`Falha ao atualizar webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
455
|
-
}
|
|
456
|
-
},
|
|
457
|
-
/**
|
|
458
|
-
* Deleta um webhook do
|
|
459
|
-
*
|
|
460
|
-
* FUNCIONALIDADE:
|
|
461
|
-
* - Remove webhook especificado
|
|
462
|
-
* - Confirma
|
|
463
|
-
* - Limpa
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
* - owner:
|
|
467
|
-
* - repo: Nome do
|
|
468
|
-
* - webhook_id: ID do webhook
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
* - Todos os
|
|
472
|
-
* - Webhook deve existir
|
|
473
|
-
* -
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
* - Confirme
|
|
477
|
-
* - Verifique se webhook
|
|
478
|
-
* - Mantenha backup se
|
|
479
|
-
* - Documente motivo da
|
|
480
|
-
*/
|
|
481
|
-
async deleteWebhook(params, provider, owner) {
|
|
482
|
-
try {
|
|
483
|
-
if (!params.repo || !params.webhook_id) {
|
|
484
|
-
throw new Error('repo e webhook_id
|
|
485
|
-
}
|
|
486
|
-
await provider.deleteWebhook((await provider.getCurrentUser()).login, params.repo, params.webhook_id);
|
|
487
|
-
return {
|
|
488
|
-
success: true,
|
|
489
|
-
action: 'delete',
|
|
490
|
-
message: `Webhook #${params.webhook_id} deletado com sucesso`,
|
|
491
|
-
data: { deleted: true }
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
catch (error) {
|
|
495
|
-
throw new Error(`Falha ao deletar webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
496
|
-
}
|
|
497
|
-
},
|
|
498
|
-
/**
|
|
499
|
-
* Testa um webhook existente
|
|
500
|
-
*
|
|
501
|
-
* FUNCIONALIDADE:
|
|
502
|
-
* - Envia payload de teste para webhook
|
|
503
|
-
* - Verifica conectividade e resposta
|
|
504
|
-
* - Retorna resultado do teste
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
* - owner:
|
|
508
|
-
* - repo: Nome do
|
|
509
|
-
* - webhook_id: ID do webhook
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* - Todos os
|
|
513
|
-
* - Webhook deve existir
|
|
514
|
-
* - Webhook deve estar ativo
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
* - Teste webhooks
|
|
518
|
-
* - Monitore respostas de teste
|
|
519
|
-
* - Verifique logs de entrega
|
|
520
|
-
* - Configure retry adequado
|
|
521
|
-
*/
|
|
522
|
-
async testWebhook(params, provider, owner) {
|
|
523
|
-
try {
|
|
524
|
-
if (!params.repo || !params.webhook_id) {
|
|
525
|
-
throw new Error('repo e webhook_id
|
|
526
|
-
}
|
|
527
|
-
// Implementar testWebhook
|
|
528
|
-
const result = {
|
|
529
|
-
success: true,
|
|
530
|
-
message: 'Webhook testado com sucesso',
|
|
531
|
-
note: 'Funcionalidade testWebhook
|
|
532
|
-
};
|
|
533
|
-
return {
|
|
534
|
-
success: true,
|
|
535
|
-
action: 'test',
|
|
536
|
-
message: `Webhook #${params.webhook_id} testado com sucesso`,
|
|
537
|
-
data: result
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
catch (error) {
|
|
541
|
-
throw new Error(`Falha ao testar webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
* Verifica se erro é relacionado a Git
|
|
546
|
-
*/
|
|
547
|
-
,
|
|
548
|
-
/**
|
|
549
|
-
* Verifica se erro é relacionado a Git
|
|
550
|
-
*/
|
|
551
|
-
isGitRelatedError(errorMessage) {
|
|
552
|
-
const gitKeywords = [
|
|
553
|
-
'git', 'commit', 'push', 'pull', 'merge', 'conflict', 'branch',
|
|
554
|
-
'remote', 'repository', 'authentication', 'permission', 'unauthorized',
|
|
555
|
-
'divergent', 'non-fast-forward', 'fetch first', 'working tree',
|
|
556
|
-
'uncommitted', 'stash', 'rebase', 'reset', 'checkout'
|
|
557
|
-
];
|
|
558
|
-
const errorLower = errorMessage.toLowerCase();
|
|
559
|
-
return gitKeywords.some(keyword => errorLower.includes(keyword));
|
|
560
|
-
}
|
|
561
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webhooksTool = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const index_js_1 = require("../providers/index.js");
|
|
6
|
+
const user_detection_js_1 = require("../utils/user-detection.js");
|
|
7
|
+
/**
|
|
8
|
+
* Tool: webhooks
|
|
9
|
+
*
|
|
10
|
+
* DESCRIÇÃO:
|
|
11
|
+
* Gerenciamento completo de webhooks com suporte multi-provider (GitHub e Gitea)
|
|
12
|
+
*
|
|
13
|
+
* FUNCIONALIDADES:
|
|
14
|
+
* - Criação de novos webhooks
|
|
15
|
+
* - Listagem e busca de webhooks
|
|
16
|
+
* - Obtenção de detalhes específicos
|
|
17
|
+
* - Atualização de webhooks existentes
|
|
18
|
+
* - Exclusão de webhooks
|
|
19
|
+
* - Teste de webhooks
|
|
20
|
+
* - Configuração de eventos
|
|
21
|
+
*
|
|
22
|
+
* USO:
|
|
23
|
+
* - Para integração com CI/CD
|
|
24
|
+
* - Para notificações automáticas
|
|
25
|
+
* - Para sincronização de dados
|
|
26
|
+
* - Para automação de workflows
|
|
27
|
+
*
|
|
28
|
+
* RECOMENDAÇÕES:
|
|
29
|
+
* - Use HTTPS sempre que possível
|
|
30
|
+
* - Mantenha secrets seguros
|
|
31
|
+
* - Monitore falhas de entrega
|
|
32
|
+
* - Configure apenas eventos necessários
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Schema de validação para entrada da tool webhooks
|
|
36
|
+
*
|
|
37
|
+
* VALIDAÇÕES:
|
|
38
|
+
* - action: Ação obrigatória (create, list, get, update, delete, test)
|
|
39
|
+
* - Parâmetros específicos por ação
|
|
40
|
+
* - Validação de tipos e formatos
|
|
41
|
+
*
|
|
42
|
+
* RECOMENDAÇÕES:
|
|
43
|
+
* - Sempre valide entrada antes de usar
|
|
44
|
+
* - Use parâmetros opcionais adequadamente
|
|
45
|
+
* - Documente parâmetros obrigatórios
|
|
46
|
+
*/
|
|
47
|
+
const WebhooksInputSchema = zod_1.z.object({
|
|
48
|
+
action: zod_1.z.enum(['create', 'list', 'get', 'update', 'delete', 'test']),
|
|
49
|
+
// Parâmetros comuns
|
|
50
|
+
repo: zod_1.z.string(),
|
|
51
|
+
// Para multi-provider
|
|
52
|
+
provider: zod_1.z.enum(['gitea', 'github']).describe('Provider to use (gitea or github)'), // Provider específico: gitea, github ou both
|
|
53
|
+
projectPath: zod_1.z.string().describe('Local project path for git operations'),
|
|
54
|
+
// Para create
|
|
55
|
+
url: zod_1.z.string().optional(),
|
|
56
|
+
content_type: zod_1.z.enum(['json', 'form']).optional(),
|
|
57
|
+
secret: zod_1.z.string().optional(),
|
|
58
|
+
events: zod_1.z.array(zod_1.z.string()).optional(),
|
|
59
|
+
active: zod_1.z.boolean().optional(),
|
|
60
|
+
// Para get/update/delete/test
|
|
61
|
+
webhook_id: zod_1.z.number().optional(),
|
|
62
|
+
// Para list
|
|
63
|
+
page: zod_1.z.number().min(1).optional(),
|
|
64
|
+
limit: zod_1.z.number().min(1).max(100).optional(),
|
|
65
|
+
// Para update
|
|
66
|
+
new_url: zod_1.z.string().optional(),
|
|
67
|
+
new_content_type: zod_1.z.enum(['json', 'form']).optional(),
|
|
68
|
+
new_secret: zod_1.z.string().optional(),
|
|
69
|
+
new_events: zod_1.z.array(zod_1.z.string()).optional(),
|
|
70
|
+
new_active: zod_1.z.boolean().optional(),
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Schema de saída padronizado
|
|
74
|
+
*
|
|
75
|
+
* ESTRUTURA:
|
|
76
|
+
* - success: Status da operação
|
|
77
|
+
* - action: Ação executada
|
|
78
|
+
* - message: Mensagem descritiva
|
|
79
|
+
* - data: Dados retornados (opcional)
|
|
80
|
+
* - error: Detalhes do erro (opcional)
|
|
81
|
+
*/
|
|
82
|
+
const WebhooksResultSchema = zod_1.z.object({
|
|
83
|
+
success: zod_1.z.boolean(),
|
|
84
|
+
action: zod_1.z.string(),
|
|
85
|
+
message: zod_1.z.string(),
|
|
86
|
+
data: zod_1.z.any().optional(),
|
|
87
|
+
error: zod_1.z.string().optional()
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* Tool: webhooks
|
|
91
|
+
*
|
|
92
|
+
* DESCRIÇÃO:
|
|
93
|
+
* Gerenciamento completo de webhooks Gitea com múltiplas ações
|
|
94
|
+
*
|
|
95
|
+
* ACTIONS DISPONÍVEIS:
|
|
96
|
+
*
|
|
97
|
+
* 1. create - Criar novo webhook
|
|
98
|
+
* Parâmetros:
|
|
99
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
100
|
+
* - repo (obrigatório): Nome do repositório
|
|
101
|
+
* - url (obrigatório): URL de destino do webhook
|
|
102
|
+
* - content_type (opcional): Tipo de conteúdo (json, form) - padrão: json
|
|
103
|
+
* - secret (opcional): Secret para assinatura
|
|
104
|
+
* - events (opcional): Array de eventos a serem monitorados
|
|
105
|
+
* - active (opcional): Se webhook está ativo (padrão: true)
|
|
106
|
+
*
|
|
107
|
+
* 2. list - Listar webhooks
|
|
108
|
+
* Parâmetros:
|
|
109
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
110
|
+
* - repo (obrigatório): Nome do repositório
|
|
111
|
+
* - page (opcional): Página da listagem (padrão: 1)
|
|
112
|
+
* - limit (opcional): Itens por página (padrão: 30, máximo: 100)
|
|
113
|
+
*
|
|
114
|
+
* 3. get - Obter detalhes do webhook
|
|
115
|
+
* Parâmetros:
|
|
116
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
117
|
+
* - repo (obrigatório): Nome do repositório
|
|
118
|
+
* - webhook_id (obrigatório): ID do webhook
|
|
119
|
+
*
|
|
120
|
+
* 4. update - Atualizar webhook existente
|
|
121
|
+
* Parâmetros:
|
|
122
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
123
|
+
* - repo (obrigatório): Nome do repositório
|
|
124
|
+
* - webhook_id (obrigatório): ID do webhook
|
|
125
|
+
* - new_url (opcional): Nova URL
|
|
126
|
+
* - new_content_type (opcional): Novo tipo de conteúdo
|
|
127
|
+
* - new_secret (opcional): Novo secret
|
|
128
|
+
* - new_events (opcional): Novos eventos
|
|
129
|
+
* - new_active (opcional): Novo status ativo
|
|
130
|
+
*
|
|
131
|
+
* 5. delete - Deletar webhook
|
|
132
|
+
* Parâmetros:
|
|
133
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
134
|
+
* - repo (obrigatório): Nome do repositório
|
|
135
|
+
* - webhook_id (obrigatório): ID do webhook
|
|
136
|
+
*
|
|
137
|
+
* 6. test - Testar webhook
|
|
138
|
+
* Parâmetros:
|
|
139
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
140
|
+
* - repo (obrigatório): Nome do repositório
|
|
141
|
+
* - webhook_id (obrigatório): ID do webhook
|
|
142
|
+
*
|
|
143
|
+
* RECOMENDAÇÕES DE USO:
|
|
144
|
+
* - Use URLs seguras (HTTPS)
|
|
145
|
+
* - Configure eventos adequadamente
|
|
146
|
+
* - Monitore falhas de entrega
|
|
147
|
+
* - Mantenha secrets seguros
|
|
148
|
+
* - Teste webhooks antes de ativar
|
|
149
|
+
* - Configure retry adequado
|
|
150
|
+
* - Monitore logs de entrega
|
|
151
|
+
*/
|
|
152
|
+
exports.webhooksTool = {
|
|
153
|
+
name: 'git-webhooks',
|
|
154
|
+
description: 'tool: Gerencia webhooks Git para automação e integrações\n──────────────\naction create: cria novo webhook\naction create requires: repo, url, content_type, secret, events, active, provider\n───────────────\naction list: lista webhooks do repositório\naction list requires: repo, page, limit, provider\n───────────────\naction get: obtém detalhes de webhook\naction get requires: repo, webhook_id, provider\n───────────────\naction update: atualiza webhook existente\naction update requires: repo, webhook_id, new_url, new_content_type, new_secret, new_events, new_active, provider\n───────────────\naction delete: remove webhook\naction delete requires: repo, webhook_id, provider\n───────────────\naction test: testa webhook\naction test requires: repo, webhook_id, provider',
|
|
155
|
+
inputSchema: {
|
|
156
|
+
type: 'object',
|
|
157
|
+
properties: {
|
|
158
|
+
action: {
|
|
159
|
+
type: 'string',
|
|
160
|
+
enum: ['create', 'list', 'get', 'update', 'delete', 'test'],
|
|
161
|
+
description: 'Action to perform on webhooks'
|
|
162
|
+
},
|
|
163
|
+
repo: { type: 'string', description: 'Repository name' },
|
|
164
|
+
provider: { type: 'string', description: 'Provider to use (github, gitea, or omit for default)' },
|
|
165
|
+
url: { type: 'string', description: 'Webhook URL' },
|
|
166
|
+
content_type: { type: 'string', enum: ['json', 'form'], description: 'Content type' },
|
|
167
|
+
secret: { type: 'string', description: 'Webhook secret' },
|
|
168
|
+
events: { type: 'array', items: { type: 'string' }, description: 'Webhook events' },
|
|
169
|
+
active: { type: 'boolean', description: 'Webhook active status' },
|
|
170
|
+
webhook_id: { type: 'number', description: 'Webhook ID' },
|
|
171
|
+
page: { type: 'number', description: 'Page number', minimum: 1 },
|
|
172
|
+
limit: { type: 'number', description: 'Items per page', minimum: 1, maximum: 100 },
|
|
173
|
+
new_url: { type: 'string', description: 'New webhook URL' },
|
|
174
|
+
new_content_type: { type: 'string', enum: ['json', 'form'], description: 'New content type' },
|
|
175
|
+
new_secret: { type: 'string', description: 'New webhook secret' },
|
|
176
|
+
new_events: { type: 'array', items: { type: 'string' }, description: 'New webhook events' },
|
|
177
|
+
new_active: { type: 'boolean', description: 'New webhook active status' }
|
|
178
|
+
},
|
|
179
|
+
required: ['action', 'repo', 'provider', 'projectPath']
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* Handler principal da tool webhooks
|
|
183
|
+
*
|
|
184
|
+
* FUNCIONALIDADE:
|
|
185
|
+
* - Valida entrada usando Zod schema
|
|
186
|
+
* - Roteia para método específico baseado na ação
|
|
187
|
+
* - Trata erros de forma uniforme
|
|
188
|
+
* - Retorna resultado padronizado
|
|
189
|
+
*
|
|
190
|
+
* FLUXO:
|
|
191
|
+
* 1. Validação de entrada
|
|
192
|
+
* 2. Seleção do provider
|
|
193
|
+
* 3. Roteamento por ação
|
|
194
|
+
* 4. Execução do método específico
|
|
195
|
+
* 5. Tratamento de erros
|
|
196
|
+
* 6. Retorno de resultado
|
|
197
|
+
*
|
|
198
|
+
* TRATAMENTO DE ERROS:
|
|
199
|
+
* - Validação: erro de schema
|
|
200
|
+
* - Execução: erro da operação
|
|
201
|
+
* - Roteamento: ação não suportada
|
|
202
|
+
*
|
|
203
|
+
* RECOMENDAÇÕES:
|
|
204
|
+
* - Sempre valide entrada antes de processar
|
|
205
|
+
* - Trate erros específicos adequadamente
|
|
206
|
+
* - Log detalhes de erro para debug
|
|
207
|
+
* - Retorne mensagens de erro úteis
|
|
208
|
+
*/
|
|
209
|
+
async handler(input) {
|
|
210
|
+
try {
|
|
211
|
+
const validatedInput = WebhooksInputSchema.parse(input);
|
|
212
|
+
// Apply automatic user/owner detection from configured tokens
|
|
213
|
+
const processedInput = await (0, user_detection_js_1.applyAutoUserDetection)(validatedInput, validatedInput.provider || 'default');
|
|
214
|
+
// Seleciona o provider baseado na entrada ou usa o padrão
|
|
215
|
+
const provider = processedInput.provider
|
|
216
|
+
? index_js_1.globalProviderFactory.getProvider(processedInput.provider)
|
|
217
|
+
: index_js_1.globalProviderFactory.getDefaultProvider();
|
|
218
|
+
if (!provider) {
|
|
219
|
+
throw new Error('Provider não encontrado ou não configurado');
|
|
220
|
+
}
|
|
221
|
+
// Obter o owner do provider
|
|
222
|
+
const owner = (await provider.getCurrentUser()).login;
|
|
223
|
+
switch (processedInput.action) {
|
|
224
|
+
case 'create':
|
|
225
|
+
return await this.createWebhook(processedInput, provider, owner);
|
|
226
|
+
case 'list':
|
|
227
|
+
return await this.listWebhooks(processedInput, provider, owner);
|
|
228
|
+
case 'get':
|
|
229
|
+
return await this.getWebhook(processedInput, provider, owner);
|
|
230
|
+
case 'update':
|
|
231
|
+
return await this.updateWebhook(processedInput, provider, owner);
|
|
232
|
+
case 'delete':
|
|
233
|
+
return await this.deleteWebhook(processedInput, provider, owner);
|
|
234
|
+
case 'test':
|
|
235
|
+
return await this.testWebhook(processedInput, provider, owner);
|
|
236
|
+
default:
|
|
237
|
+
throw new Error(`Ação não suportada: ${processedInput.action}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
action: input.action,
|
|
244
|
+
message: 'Erro na operação de webhooks',
|
|
245
|
+
error: error instanceof Error ? error.message : String(error)
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
/**
|
|
250
|
+
* Cria um novo webhook no repositório
|
|
251
|
+
*
|
|
252
|
+
* FUNCIONALIDADE:
|
|
253
|
+
* - Cria webhook com URL e configurações
|
|
254
|
+
* - Suporta diferentes tipos de conteúdo
|
|
255
|
+
* - Permite configuração de eventos
|
|
256
|
+
*
|
|
257
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
258
|
+
* - owner: Proprietário do repositório
|
|
259
|
+
* - repo: Nome do repositório
|
|
260
|
+
* - url: URL de destino do webhook
|
|
261
|
+
*
|
|
262
|
+
* PARÂMETROS OPCIONAIS:
|
|
263
|
+
* - content_type: Tipo de conteúdo (json, form) - padrão: json
|
|
264
|
+
* - secret: Secret para assinatura
|
|
265
|
+
* - events: Array de eventos a serem monitorados
|
|
266
|
+
* - active: Se webhook está ativo (padrão: true)
|
|
267
|
+
*
|
|
268
|
+
* VALIDAÇÕES:
|
|
269
|
+
* - Todos os parâmetros obrigatórios
|
|
270
|
+
* - URL deve ser válida e acessível
|
|
271
|
+
* - Usuário deve ter permissão de escrita
|
|
272
|
+
*
|
|
273
|
+
* RECOMENDAÇÕES:
|
|
274
|
+
* - Use URLs seguras (HTTPS)
|
|
275
|
+
* - Configure eventos adequadamente
|
|
276
|
+
* - Mantenha secrets seguros
|
|
277
|
+
* - Teste webhook antes de ativar
|
|
278
|
+
*/
|
|
279
|
+
async createWebhook(params, provider, owner) {
|
|
280
|
+
try {
|
|
281
|
+
if (!params.repo || !params.url) {
|
|
282
|
+
throw new Error('repo e url são obrigatórios');
|
|
283
|
+
}
|
|
284
|
+
const webhookData = {
|
|
285
|
+
url: params.url,
|
|
286
|
+
content_type: params.content_type || 'json',
|
|
287
|
+
secret: params.secret || '',
|
|
288
|
+
events: params.events || ['push'],
|
|
289
|
+
active: params.active !== undefined ? params.active : true
|
|
290
|
+
};
|
|
291
|
+
const webhook = await provider.createWebhook(owner, params.repo, params.url, params.events || ['push'], params.secret);
|
|
292
|
+
return {
|
|
293
|
+
success: true,
|
|
294
|
+
action: 'create',
|
|
295
|
+
message: `Webhook criado com sucesso para '${owner}/${params.repo}'`,
|
|
296
|
+
data: webhook
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
throw new Error(`Falha ao criar webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
/**
|
|
304
|
+
* Lista webhooks do repositório
|
|
305
|
+
*
|
|
306
|
+
* FUNCIONALIDADE:
|
|
307
|
+
* - Lista webhooks com paginação
|
|
308
|
+
* - Retorna informações básicas de cada webhook
|
|
309
|
+
* - Inclui status ativo e eventos configurados
|
|
310
|
+
*
|
|
311
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
312
|
+
* - owner: Proprietário do repositório
|
|
313
|
+
* - repo: Nome do repositório
|
|
314
|
+
*
|
|
315
|
+
* PARÂMETROS OPCIONAIS:
|
|
316
|
+
* - page: Página da listagem (padrão: 1)
|
|
317
|
+
* - limit: Itens por página (padrão: 30, máximo: 100)
|
|
318
|
+
*
|
|
319
|
+
* VALIDAÇÕES:
|
|
320
|
+
* - e repo obrigatórios
|
|
321
|
+
* - Page deve ser >= 1
|
|
322
|
+
* - Limit deve ser entre 1 e 100
|
|
323
|
+
*
|
|
324
|
+
* RECOMENDAÇÕES:
|
|
325
|
+
* - Use paginação para repositórios com muitos webhooks
|
|
326
|
+
* - Monitore número total de webhooks
|
|
327
|
+
* - Verifique status ativo de cada webhook
|
|
328
|
+
* - Mantenha webhooks organizados
|
|
329
|
+
*/
|
|
330
|
+
async listWebhooks(params, provider, owner) {
|
|
331
|
+
try {
|
|
332
|
+
if (!params.repo) {
|
|
333
|
+
throw new Error('owner e repo são obrigatórios');
|
|
334
|
+
}
|
|
335
|
+
const page = params.page || 1;
|
|
336
|
+
const limit = params.limit || 30;
|
|
337
|
+
const webhooks = await provider.listWebhooks((await provider.getCurrentUser()).login, params.repo, page, limit);
|
|
338
|
+
return {
|
|
339
|
+
success: true,
|
|
340
|
+
action: 'list',
|
|
341
|
+
message: `${webhooks.length} webhooks encontrados`,
|
|
342
|
+
data: {
|
|
343
|
+
webhooks,
|
|
344
|
+
page,
|
|
345
|
+
limit,
|
|
346
|
+
total: webhooks.length
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
throw new Error(`Falha ao listar webhooks: ${error instanceof Error ? error.message : String(error)}`);
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
/**
|
|
355
|
+
* Obtém detalhes de um webhook específico
|
|
356
|
+
*
|
|
357
|
+
* FUNCIONALIDADE:
|
|
358
|
+
* - Retorna informações completas do webhook
|
|
359
|
+
* - Inclui URL, tipo de conteúdo, eventos e status
|
|
360
|
+
* - Mostra configurações de segurança
|
|
361
|
+
*
|
|
362
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
363
|
+
* - owner: Proprietário do repositório
|
|
364
|
+
* - repo: Nome do repositório
|
|
365
|
+
* - webhook_id: ID do webhook
|
|
366
|
+
*
|
|
367
|
+
* VALIDAÇÕES:
|
|
368
|
+
* - Todos os parâmetros obrigatórios
|
|
369
|
+
* - Webhook deve existir no repositório
|
|
370
|
+
* - ID deve ser válido
|
|
371
|
+
*
|
|
372
|
+
* RECOMENDAÇÕES:
|
|
373
|
+
* - Use para obter detalhes completos
|
|
374
|
+
* - Verifique configurações de segurança
|
|
375
|
+
* - Analise eventos configurados
|
|
376
|
+
* - Monitore status ativo
|
|
377
|
+
*/
|
|
378
|
+
async getWebhook(params, provider, owner) {
|
|
379
|
+
try {
|
|
380
|
+
if (!params.repo || !params.webhook_id) {
|
|
381
|
+
throw new Error('repo e webhook_id são obrigatórios');
|
|
382
|
+
}
|
|
383
|
+
const webhook = await provider.getWebhook((await provider.getCurrentUser()).login, params.repo, params.webhook_id);
|
|
384
|
+
return {
|
|
385
|
+
success: true,
|
|
386
|
+
action: 'get',
|
|
387
|
+
message: `Webhook #${params.webhook_id} obtido com sucesso`,
|
|
388
|
+
data: webhook
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
throw new Error(`Falha ao obter webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
/**
|
|
396
|
+
* Atualiza um webhook existente
|
|
397
|
+
*
|
|
398
|
+
* FUNCIONALIDADE:
|
|
399
|
+
* - Atualiza campos do webhook
|
|
400
|
+
* - Suporta mudança de URL e eventos
|
|
401
|
+
* - Permite alteração de status ativo
|
|
402
|
+
*
|
|
403
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
404
|
+
* - owner: Proprietário do repositório
|
|
405
|
+
* - repo: Nome do repositório
|
|
406
|
+
* - webhook_id: ID do webhook
|
|
407
|
+
*
|
|
408
|
+
* PARÂMETROS OPCIONAIS:
|
|
409
|
+
* - new_url: Nova URL
|
|
410
|
+
* - new_content_type: Novo tipo de conteúdo
|
|
411
|
+
* - new_secret: Novo secret
|
|
412
|
+
* - new_events: Novos eventos
|
|
413
|
+
* - new_active: Novo status ativo
|
|
414
|
+
*
|
|
415
|
+
* VALIDAÇÕES:
|
|
416
|
+
* - Todos os parâmetros obrigatórios
|
|
417
|
+
* - Webhook deve existir
|
|
418
|
+
* - Pelo menos um campo deve ser atualizado
|
|
419
|
+
*
|
|
420
|
+
* RECOMENDAÇÕES:
|
|
421
|
+
* - Atualize apenas campos necessários
|
|
422
|
+
* - Use mensagens de commit descritivas
|
|
423
|
+
* - Documente mudanças importantes
|
|
424
|
+
* - Teste webhook após atualização
|
|
425
|
+
*/
|
|
426
|
+
async updateWebhook(params, provider, owner) {
|
|
427
|
+
try {
|
|
428
|
+
if (!params.repo || !params.webhook_id) {
|
|
429
|
+
throw new Error('repo e webhook_id são obrigatórios');
|
|
430
|
+
}
|
|
431
|
+
const updateData = {};
|
|
432
|
+
if (params.new_url)
|
|
433
|
+
updateData.url = params.new_url;
|
|
434
|
+
if (params.new_content_type)
|
|
435
|
+
updateData.content_type = params.new_content_type;
|
|
436
|
+
if (params.new_secret)
|
|
437
|
+
updateData.secret = params.new_secret;
|
|
438
|
+
if (params.new_events)
|
|
439
|
+
updateData.events = params.new_events;
|
|
440
|
+
if (params.new_active !== undefined)
|
|
441
|
+
updateData.active = params.new_active;
|
|
442
|
+
if (Object.keys(updateData).length === 0) {
|
|
443
|
+
throw new Error('Nenhum campo para atualizar foi fornecido');
|
|
444
|
+
}
|
|
445
|
+
const webhook = await provider.updateWebhook((await provider.getCurrentUser()).login, params.repo, params.webhook_id, updateData);
|
|
446
|
+
return {
|
|
447
|
+
success: true,
|
|
448
|
+
action: 'update',
|
|
449
|
+
message: `Webhook #${params.webhook_id} atualizado com sucesso`,
|
|
450
|
+
data: webhook
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
throw new Error(`Falha ao atualizar webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
/**
|
|
458
|
+
* Deleta um webhook do repositório
|
|
459
|
+
*
|
|
460
|
+
* FUNCIONALIDADE:
|
|
461
|
+
* - Remove webhook especificado
|
|
462
|
+
* - Confirma exclusão bem-sucedida
|
|
463
|
+
* - Limpa configurações associadas
|
|
464
|
+
*
|
|
465
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
466
|
+
* - owner: Proprietário do repositório
|
|
467
|
+
* - repo: Nome do repositório
|
|
468
|
+
* - webhook_id: ID do webhook
|
|
469
|
+
*
|
|
470
|
+
* VALIDAÇÕES:
|
|
471
|
+
* - Todos os parâmetros obrigatórios
|
|
472
|
+
* - Webhook deve existir
|
|
473
|
+
* - Usuário deve ter permissão de exclusão
|
|
474
|
+
*
|
|
475
|
+
* RECOMENDAÇÕES:
|
|
476
|
+
* - Confirme exclusão antes de executar
|
|
477
|
+
* - Verifique se webhook não está sendo usado
|
|
478
|
+
* - Mantenha backup se necessário
|
|
479
|
+
* - Documente motivo da exclusão
|
|
480
|
+
*/
|
|
481
|
+
async deleteWebhook(params, provider, owner) {
|
|
482
|
+
try {
|
|
483
|
+
if (!params.repo || !params.webhook_id) {
|
|
484
|
+
throw new Error('repo e webhook_id são obrigatórios');
|
|
485
|
+
}
|
|
486
|
+
await provider.deleteWebhook((await provider.getCurrentUser()).login, params.repo, params.webhook_id);
|
|
487
|
+
return {
|
|
488
|
+
success: true,
|
|
489
|
+
action: 'delete',
|
|
490
|
+
message: `Webhook #${params.webhook_id} deletado com sucesso`,
|
|
491
|
+
data: { deleted: true }
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
throw new Error(`Falha ao deletar webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
/**
|
|
499
|
+
* Testa um webhook existente
|
|
500
|
+
*
|
|
501
|
+
* FUNCIONALIDADE:
|
|
502
|
+
* - Envia payload de teste para webhook
|
|
503
|
+
* - Verifica conectividade e resposta
|
|
504
|
+
* - Retorna resultado do teste
|
|
505
|
+
*
|
|
506
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
507
|
+
* - owner: Proprietário do repositório
|
|
508
|
+
* - repo: Nome do repositório
|
|
509
|
+
* - webhook_id: ID do webhook
|
|
510
|
+
*
|
|
511
|
+
* VALIDAÇÕES:
|
|
512
|
+
* - Todos os parâmetros obrigatórios
|
|
513
|
+
* - Webhook deve existir
|
|
514
|
+
* - Webhook deve estar ativo
|
|
515
|
+
*
|
|
516
|
+
* RECOMENDAÇÕES:
|
|
517
|
+
* - Teste webhooks após criação
|
|
518
|
+
* - Monitore respostas de teste
|
|
519
|
+
* - Verifique logs de entrega
|
|
520
|
+
* - Configure retry adequado
|
|
521
|
+
*/
|
|
522
|
+
async testWebhook(params, provider, owner) {
|
|
523
|
+
try {
|
|
524
|
+
if (!params.repo || !params.webhook_id) {
|
|
525
|
+
throw new Error('repo e webhook_id são obrigatórios');
|
|
526
|
+
}
|
|
527
|
+
// Implementar testWebhook
|
|
528
|
+
const result = {
|
|
529
|
+
success: true,
|
|
530
|
+
message: 'Webhook testado com sucesso',
|
|
531
|
+
note: 'Funcionalidade testWebhook será implementada'
|
|
532
|
+
};
|
|
533
|
+
return {
|
|
534
|
+
success: true,
|
|
535
|
+
action: 'test',
|
|
536
|
+
message: `Webhook #${params.webhook_id} testado com sucesso`,
|
|
537
|
+
data: result
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
throw new Error(`Falha ao testar webhook: ${error instanceof Error ? error.message : String(error)}`);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
};
|
|
562
545
|
//# sourceMappingURL=git-webhooks.js.map
|