@andrebuzeli/git-mcp 2.28.1 → 2.29.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/client.d.ts +306 -306
- package/dist/client.js +298 -298
- package/dist/config.d.ts +310 -310
- package/dist/config.js +392 -392
- package/dist/index.d.ts +22 -22
- package/dist/index.js +89 -89
- package/dist/providers/base-provider.d.ts +160 -160
- package/dist/providers/base-provider.js +274 -274
- package/dist/providers/error-handler.d.ts +74 -50
- package/dist/providers/error-handler.d.ts.map +1 -1
- package/dist/providers/error-handler.js +234 -175
- package/dist/providers/error-handler.js.map +1 -1
- package/dist/providers/gitea-provider.d.ts +97 -97
- package/dist/providers/gitea-provider.d.ts.map +1 -1
- package/dist/providers/gitea-provider.js +1015 -1001
- package/dist/providers/gitea-provider.js.map +1 -1
- package/dist/providers/github-provider.d.ts +104 -104
- package/dist/providers/github-provider.d.ts.map +1 -1
- package/dist/providers/github-provider.js +1248 -1234
- package/dist/providers/github-provider.js.map +1 -1
- package/dist/providers/index.d.ts +12 -12
- package/dist/providers/index.js +40 -40
- package/dist/providers/provider-factory.d.ts +74 -74
- package/dist/providers/provider-factory.d.ts.map +1 -1
- package/dist/providers/provider-factory.js +318 -311
- package/dist/providers/provider-factory.js.map +1 -1
- package/dist/providers/types.d.ts +318 -318
- package/dist/providers/types.js +6 -6
- package/dist/server.d.ts +76 -76
- package/dist/server.js +306 -306
- package/dist/server.js.map +1 -1
- package/dist/tools/git-archive.d.ts +169 -165
- package/dist/tools/git-archive.d.ts.map +1 -1
- package/dist/tools/git-archive.js +246 -233
- package/dist/tools/git-archive.js.map +1 -1
- package/dist/tools/git-branches.d.ts +434 -430
- package/dist/tools/git-branches.d.ts.map +1 -1
- package/dist/tools/git-branches.js +640 -627
- package/dist/tools/git-branches.js.map +1 -1
- package/dist/tools/git-commits.d.ts +489 -485
- package/dist/tools/git-commits.d.ts.map +1 -1
- package/dist/tools/git-commits.js +748 -735
- package/dist/tools/git-commits.js.map +1 -1
- package/dist/tools/git-config.d.ts +144 -140
- package/dist/tools/git-config.d.ts.map +1 -1
- package/dist/tools/git-config.js +281 -268
- package/dist/tools/git-config.js.map +1 -1
- package/dist/tools/git-files.d.ts +490 -486
- package/dist/tools/git-files.d.ts.map +1 -1
- package/dist/tools/git-files.js +620 -607
- package/dist/tools/git-files.js.map +1 -1
- package/dist/tools/git-initialize.d.ts +46 -42
- package/dist/tools/git-initialize.d.ts.map +1 -1
- package/dist/tools/git-initialize.js +81 -68
- package/dist/tools/git-initialize.js.map +1 -1
- package/dist/tools/git-issues.d.ts +578 -571
- package/dist/tools/git-issues.d.ts.map +1 -1
- package/dist/tools/git-issues.js +754 -740
- package/dist/tools/git-issues.js.map +1 -1
- package/dist/tools/git-pulls.d.ts +701 -694
- package/dist/tools/git-pulls.d.ts.map +1 -1
- package/dist/tools/git-pulls.js +746 -732
- package/dist/tools/git-pulls.js.map +1 -1
- package/dist/tools/git-releases.d.ts +494 -487
- package/dist/tools/git-releases.d.ts.map +1 -1
- package/dist/tools/git-releases.js +571 -557
- package/dist/tools/git-releases.js.map +1 -1
- package/dist/tools/git-remote.d.ts +142 -138
- package/dist/tools/git-remote.d.ts.map +1 -1
- package/dist/tools/git-remote.js +287 -274
- package/dist/tools/git-remote.js.map +1 -1
- package/dist/tools/git-repositories.d.ts +487 -483
- package/dist/tools/git-repositories.d.ts.map +1 -1
- package/dist/tools/git-repositories.js +653 -640
- package/dist/tools/git-repositories.js.map +1 -1
- package/dist/tools/git-reset.d.ts +134 -130
- package/dist/tools/git-reset.d.ts.map +1 -1
- package/dist/tools/git-reset.js +236 -223
- package/dist/tools/git-reset.js.map +1 -1
- package/dist/tools/git-revert.d.ts +153 -149
- package/dist/tools/git-revert.d.ts.map +1 -1
- package/dist/tools/git-revert.js +211 -198
- package/dist/tools/git-revert.js.map +1 -1
- package/dist/tools/git-stash.d.ts +144 -140
- package/dist/tools/git-stash.d.ts.map +1 -1
- package/dist/tools/git-stash.js +282 -269
- package/dist/tools/git-stash.js.map +1 -1
- package/dist/tools/git-sync.d.ts +182 -178
- package/dist/tools/git-sync.d.ts.map +1 -1
- package/dist/tools/git-sync.js +325 -312
- package/dist/tools/git-sync.js.map +1 -1
- package/dist/tools/git-tags.d.ts +418 -411
- package/dist/tools/git-tags.d.ts.map +1 -1
- package/dist/tools/git-tags.js +499 -485
- package/dist/tools/git-tags.js.map +1 -1
- package/dist/tools/git-upload-project.d.ts +5 -1
- package/dist/tools/git-upload-project.d.ts.map +1 -1
- package/dist/tools/git-upload-project.js +21 -1
- package/dist/tools/git-upload-project.js.map +1 -1
- package/dist/tools/git-webhooks.d.ts +477 -470
- package/dist/tools/git-webhooks.d.ts.map +1 -1
- package/dist/tools/git-webhooks.js +561 -543
- package/dist/tools/git-webhooks.js.map +1 -1
- package/dist/utils/git-error-analyzer.d.ts +64 -0
- package/dist/utils/git-error-analyzer.d.ts.map +1 -0
- package/dist/utils/git-error-analyzer.js +286 -0
- package/dist/utils/git-error-analyzer.js.map +1 -0
- package/dist/utils/terminal-controller.d.ts +80 -80
- package/dist/utils/terminal-controller.js +345 -345
- package/dist/utils/user-detection.d.ts +24 -24
- package/dist/utils/user-detection.js +53 -53
- package/package.json +2 -2
- package/dist/tools/gh-actions.d.ts +0 -253
- package/dist/tools/gh-actions.d.ts.map +0 -1
- package/dist/tools/gh-actions.js +0 -390
- package/dist/tools/gh-actions.js.map +0 -1
- package/dist/tools/gh-analytics.d.ts +0 -264
- package/dist/tools/gh-analytics.d.ts.map +0 -1
- package/dist/tools/gh-analytics.js +0 -402
- package/dist/tools/gh-analytics.js.map +0 -1
- package/dist/tools/gh-code-review.d.ts +0 -305
- package/dist/tools/gh-code-review.d.ts.map +0 -1
- package/dist/tools/gh-code-review.js +0 -513
- package/dist/tools/gh-code-review.js.map +0 -1
- package/dist/tools/gh-codespaces.d.ts +0 -139
- package/dist/tools/gh-codespaces.d.ts.map +0 -1
- package/dist/tools/gh-codespaces.js +0 -283
- package/dist/tools/gh-codespaces.js.map +0 -1
- package/dist/tools/gh-deployments.d.ts +0 -301
- package/dist/tools/gh-deployments.d.ts.map +0 -1
- package/dist/tools/gh-deployments.js +0 -368
- package/dist/tools/gh-deployments.js.map +0 -1
- package/dist/tools/gh-gists.d.ts +0 -175
- package/dist/tools/gh-gists.d.ts.map +0 -1
- package/dist/tools/gh-gists.js +0 -322
- package/dist/tools/gh-gists.js.map +0 -1
- package/dist/tools/gh-projects.d.ts +0 -206
- package/dist/tools/gh-projects.d.ts.map +0 -1
- package/dist/tools/gh-projects.js +0 -359
- package/dist/tools/gh-projects.js.map +0 -1
- package/dist/tools/gh-security.d.ts +0 -275
- package/dist/tools/gh-security.d.ts.map +0 -1
- package/dist/tools/gh-security.js +0 -396
- package/dist/tools/gh-security.js.map +0 -1
- package/dist/tools/gh-sync.d.ts +0 -214
- package/dist/tools/gh-sync.d.ts.map +0 -1
- package/dist/tools/gh-sync.js +0 -379
- package/dist/tools/gh-sync.js.map +0 -1
- package/dist/tools/gh-workflows.d.ts +0 -291
- package/dist/tools/gh-workflows.d.ts.map +0 -1
- package/dist/tools/gh-workflows.js +0 -433
- package/dist/tools/gh-workflows.js.map +0 -1
- package/dist/tools/git-bundle.d.ts +0 -172
- package/dist/tools/git-bundle.d.ts.map +0 -1
- package/dist/tools/git-bundle.js +0 -242
- package/dist/tools/git-bundle.js.map +0 -1
- package/dist/tools/git-cherry-pick.d.ts +0 -159
- package/dist/tools/git-cherry-pick.d.ts.map +0 -1
- package/dist/tools/git-cherry-pick.js +0 -225
- package/dist/tools/git-cherry-pick.js.map +0 -1
- package/dist/tools/git-rebase.d.ts +0 -138
- package/dist/tools/git-rebase.d.ts.map +0 -1
- package/dist/tools/git-rebase.js +0 -214
- package/dist/tools/git-rebase.js.map +0 -1
- package/dist/tools/git-submodule.d.ts +0 -153
- package/dist/tools/git-submodule.d.ts.map +0 -1
- package/dist/tools/git-submodule.js +0 -290
- package/dist/tools/git-submodule.js.map +0 -1
- package/dist/tools/git-worktree.d.ts +0 -160
- package/dist/tools/git-worktree.d.ts.map +0 -1
- package/dist/tools/git-worktree.js +0 -270
- package/dist/tools/git-worktree.js.map +0 -1
- package/dist/tools/repositories.d.ts +0 -406
- package/dist/tools/repositories.d.ts.map +0 -1
- package/dist/tools/repositories.js +0 -570
- package/dist/tools/repositories.js.map +0 -1
- package/dist/tools/users.d.ts +0 -373
- package/dist/tools/users.d.ts.map +0 -1
- package/dist/tools/users.js +0 -500
- package/dist/tools/users.js.map +0 -1
- package/dist/tools/validator.d.ts +0 -171
- package/dist/tools/validator.d.ts.map +0 -1
- package/dist/tools/validator.js +0 -195
- package/dist/tools/validator.js.map +0 -1
- package/dist/tools/version-control.d.ts +0 -137
- package/dist/tools/version-control.d.ts.map +0 -1
- package/dist/tools/version-control.js +0 -165
- package/dist/tools/version-control.js.map +0 -1
|
@@ -1,628 +1,641 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.branchesTool = 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: branches
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Gerenciamento completo de branches Gitea com
|
|
12
|
-
*
|
|
13
|
-
* FUNCIONALIDADES:
|
|
14
|
-
* -
|
|
15
|
-
* - Listagem e busca de branches
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
18
|
-
* - Merge de branches
|
|
19
|
-
* -
|
|
20
|
-
*
|
|
21
|
-
* USO:
|
|
22
|
-
* - Para gerenciar fluxo de trabalho Git
|
|
23
|
-
* - Para criar branches de feature
|
|
24
|
-
* - Para organizar desenvolvimento
|
|
25
|
-
* - Para controle de
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* - Use
|
|
29
|
-
* - Proteja branches importantes
|
|
30
|
-
* - Mantenha branches limpas
|
|
31
|
-
* - Documente
|
|
32
|
-
*/
|
|
33
|
-
/**
|
|
34
|
-
* Schema de
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* - action:
|
|
38
|
-
* -
|
|
39
|
-
* -
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* - Sempre valide entrada antes de usar
|
|
43
|
-
* - Use
|
|
44
|
-
* - Documente
|
|
45
|
-
*/
|
|
46
|
-
const BranchesInputSchema = zod_1.z.object({
|
|
47
|
-
action: zod_1.z.enum(['create', 'list', 'get', 'delete', 'merge', 'compare']),
|
|
48
|
-
//
|
|
49
|
-
repo: zod_1.z.string(),
|
|
50
|
-
projectPath: zod_1.z.string().describe('Local project path for git operations'),
|
|
51
|
-
provider: zod_1.z.enum(['gitea', 'github']).describe('Provider to use (gitea or github)'), // Para create
|
|
52
|
-
branch_name: zod_1.z.string().optional(),
|
|
53
|
-
from_branch: zod_1.z.string().optional(),
|
|
54
|
-
// Para get/delete
|
|
55
|
-
branch: zod_1.z.string().optional(),
|
|
56
|
-
// Para merge
|
|
57
|
-
head: zod_1.z.string().optional(),
|
|
58
|
-
base: zod_1.z.string().optional(),
|
|
59
|
-
merge_method: zod_1.z.enum(['merge', 'rebase', 'squash']).optional(),
|
|
60
|
-
// Para list
|
|
61
|
-
page: zod_1.z.number().min(1).optional(),
|
|
62
|
-
limit: zod_1.z.number().min(1).max(100).optional(),
|
|
63
|
-
// Para compare
|
|
64
|
-
base_branch: zod_1.z.string().optional(),
|
|
65
|
-
head_branch: zod_1.z.string().optional(),
|
|
66
|
-
});
|
|
67
|
-
/**
|
|
68
|
-
* Schema de
|
|
69
|
-
*
|
|
70
|
-
* ESTRUTURA:
|
|
71
|
-
* - success: Status da
|
|
72
|
-
* - action:
|
|
73
|
-
* - message: Mensagem descritiva
|
|
74
|
-
* - data: Dados retornados (opcional)
|
|
75
|
-
* - error: Detalhes do erro (opcional)
|
|
76
|
-
*/
|
|
77
|
-
const BranchesResultSchema = zod_1.z.object({
|
|
78
|
-
success: zod_1.z.boolean(),
|
|
79
|
-
action: zod_1.z.string(),
|
|
80
|
-
message: zod_1.z.string(),
|
|
81
|
-
data: zod_1.z.any().optional(),
|
|
82
|
-
error: zod_1.z.string().optional()
|
|
83
|
-
});
|
|
84
|
-
/**
|
|
85
|
-
* Tool: branches
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* Gerenciamento completo de branches Gitea com
|
|
89
|
-
*
|
|
90
|
-
* ACTIONS
|
|
91
|
-
*
|
|
92
|
-
* 1. create - Criar nova branch
|
|
93
|
-
*
|
|
94
|
-
* - owner (
|
|
95
|
-
* - repo (
|
|
96
|
-
* - branch_name (
|
|
97
|
-
* - from_branch (
|
|
98
|
-
*
|
|
99
|
-
* 2. list - Listar branches
|
|
100
|
-
*
|
|
101
|
-
* - owner (
|
|
102
|
-
* - repo (
|
|
103
|
-
* - page (opcional):
|
|
104
|
-
* - limit (opcional): Itens por
|
|
105
|
-
*
|
|
106
|
-
* 3. get - Obter detalhes da branch
|
|
107
|
-
*
|
|
108
|
-
* - owner (
|
|
109
|
-
* - repo (
|
|
110
|
-
* - branch (
|
|
111
|
-
*
|
|
112
|
-
* 4. delete - Deletar branch
|
|
113
|
-
*
|
|
114
|
-
* - owner (
|
|
115
|
-
* - repo (
|
|
116
|
-
* - branch (
|
|
117
|
-
*
|
|
118
|
-
* 5. merge - Fazer merge de branches
|
|
119
|
-
*
|
|
120
|
-
* - owner (
|
|
121
|
-
* - repo (
|
|
122
|
-
* - head (
|
|
123
|
-
* - base (
|
|
124
|
-
* - merge_method (opcional):
|
|
125
|
-
*
|
|
126
|
-
* 6. compare - Comparar branches
|
|
127
|
-
*
|
|
128
|
-
* - owner (
|
|
129
|
-
* - repo (
|
|
130
|
-
* - base_branch (
|
|
131
|
-
* - head_branch (
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* - Use nomes descritivos para branches
|
|
135
|
-
* - Mantenha branches principais protegidas
|
|
136
|
-
* -
|
|
137
|
-
* - Documente
|
|
138
|
-
* - Use
|
|
139
|
-
* - Limpe branches antigas
|
|
140
|
-
*/
|
|
141
|
-
exports.branchesTool = {
|
|
142
|
-
name: 'git-branches',
|
|
143
|
-
description: 'tool: Gerencia branches Git,
|
|
144
|
-
inputSchema: {
|
|
145
|
-
type: 'object',
|
|
146
|
-
properties: {
|
|
147
|
-
action: {
|
|
148
|
-
type: 'string',
|
|
149
|
-
enum: ['create', 'list', 'get', 'delete', 'merge', 'compare'],
|
|
150
|
-
description: 'Action to perform on branches'
|
|
151
|
-
},
|
|
152
|
-
repo: { type: 'string', description: 'Repository name' },
|
|
153
|
-
projectPath: { type: 'string', description: 'Local project path for git operations' },
|
|
154
|
-
provider: { type: 'string', description: 'Specific provider (github, gitea) or use default' },
|
|
155
|
-
branch_name: { type: 'string', description: 'Name of the new branch' },
|
|
156
|
-
from_branch: { type: 'string', description: 'Source branch for creation' },
|
|
157
|
-
branch: { type: 'string', description: 'Branch name' },
|
|
158
|
-
head: { type: 'string', description: 'Source branch for merge' },
|
|
159
|
-
base: { type: 'string', description: 'Target branch for merge' },
|
|
160
|
-
merge_method: {
|
|
161
|
-
type: 'string',
|
|
162
|
-
enum: ['merge', 'rebase', 'squash'],
|
|
163
|
-
description: 'Merge method'
|
|
164
|
-
},
|
|
165
|
-
page: { type: 'number', description: 'Page number', minimum: 1 },
|
|
166
|
-
limit: { type: 'number', description: 'Items per page', minimum: 1, maximum: 100 },
|
|
167
|
-
base_branch: { type: 'string', description: 'Base branch for comparison' },
|
|
168
|
-
head_branch: { type: 'string', description: 'Head branch for comparison' }
|
|
169
|
-
},
|
|
170
|
-
required: ['action', 'repo', 'provider', 'projectPath']
|
|
171
|
-
},
|
|
172
|
-
/**
|
|
173
|
-
* Handler principal da tool branches
|
|
174
|
-
*
|
|
175
|
-
* FUNCIONALIDADE:
|
|
176
|
-
* - Valida entrada usando Zod schema
|
|
177
|
-
* - Roteia para
|
|
178
|
-
* - Trata erros de forma uniforme
|
|
179
|
-
* - Retorna resultado padronizado
|
|
180
|
-
*
|
|
181
|
-
* FLUXO:
|
|
182
|
-
* 1.
|
|
183
|
-
* 2. Roteamento por
|
|
184
|
-
* 3.
|
|
185
|
-
* 4. Tratamento de erros
|
|
186
|
-
* 5. Retorno de resultado
|
|
187
|
-
*
|
|
188
|
-
* TRATAMENTO DE ERROS:
|
|
189
|
-
* -
|
|
190
|
-
* -
|
|
191
|
-
* - Roteamento:
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* - Sempre valide entrada antes de processar
|
|
195
|
-
* - Trate erros
|
|
196
|
-
* - Log detalhes de erro para debug
|
|
197
|
-
* - Retorne mensagens de erro
|
|
198
|
-
*/
|
|
199
|
-
async handler(input) {
|
|
200
|
-
try {
|
|
201
|
-
const validatedInput = BranchesInputSchema.parse(input);
|
|
202
|
-
// Aplicar auto-
|
|
203
|
-
const processedInput = await (0, user_detection_js_1.applyAutoUserDetection)(validatedInput, validatedInput.provider);
|
|
204
|
-
// Usar o provider especificado pelo
|
|
205
|
-
let provider;
|
|
206
|
-
try {
|
|
207
|
-
if (processedInput.provider) {
|
|
208
|
-
const requestedProvider = index_js_1.globalProviderFactory.getProvider(processedInput.provider);
|
|
209
|
-
if (!requestedProvider) {
|
|
210
|
-
console.warn(`[BRANCHES] Provider '${processedInput.provider}'
|
|
211
|
-
provider = index_js_1.globalProviderFactory.getDefaultProvider();
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
provider = requestedProvider;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
provider = index_js_1.globalProviderFactory.getDefaultProvider();
|
|
219
|
-
}
|
|
220
|
-
if (!provider) {
|
|
221
|
-
throw new Error('Nenhum provider
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
catch (providerError) {
|
|
225
|
-
console.error('[BRANCHES] Erro ao obter provider:', providerError);
|
|
226
|
-
throw new Error(`Erro de
|
|
227
|
-
}
|
|
228
|
-
switch (processedInput.action) {
|
|
229
|
-
case 'create':
|
|
230
|
-
return await this.createBranch(processedInput, provider);
|
|
231
|
-
case 'list':
|
|
232
|
-
return await this.listBranches(processedInput, provider);
|
|
233
|
-
case 'get':
|
|
234
|
-
return await this.getBranch(processedInput, provider);
|
|
235
|
-
case 'delete':
|
|
236
|
-
return await this.deleteBranch(processedInput, provider);
|
|
237
|
-
case 'merge':
|
|
238
|
-
return await this.mergeBranches(processedInput, provider);
|
|
239
|
-
case 'compare':
|
|
240
|
-
return await this.compareBranches(processedInput, provider);
|
|
241
|
-
default:
|
|
242
|
-
throw new Error(`
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
catch (error) {
|
|
246
|
-
return {
|
|
247
|
-
success: false,
|
|
248
|
-
action: input.action,
|
|
249
|
-
message: 'Erro na
|
|
250
|
-
error: error instanceof Error ? error.message : String(error)
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
/**
|
|
255
|
-
* Cria uma nova branch no
|
|
256
|
-
*
|
|
257
|
-
* FUNCIONALIDADE:
|
|
258
|
-
* - Valida
|
|
259
|
-
* - Cria branch a partir de branch existente
|
|
260
|
-
* - Retorna detalhes da nova branch
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* - owner:
|
|
264
|
-
* - repo: Nome do
|
|
265
|
-
* - branch_name: Nome da nova branch
|
|
266
|
-
* - from_branch: Branch de origem
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* - Todos os
|
|
270
|
-
* - Branch de origem deve existir
|
|
271
|
-
* - Nome da nova branch deve ser
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* - Use nomes descritivos para branches
|
|
275
|
-
* - Crie a partir de branches
|
|
276
|
-
* - Documente
|
|
277
|
-
* - Use
|
|
278
|
-
*/
|
|
279
|
-
async createBranch(params, provider) {
|
|
280
|
-
try {
|
|
281
|
-
if (!params.repo || !params.branch_name || !params.from_branch) {
|
|
282
|
-
throw new Error('Repo, branch_name e from_branch
|
|
283
|
-
}
|
|
284
|
-
const currentUser = await provider.getCurrentUser();
|
|
285
|
-
const owner = currentUser.login;
|
|
286
|
-
const branch = await provider.createBranch(owner, params.repo, params.branch_name, params.from_branch);
|
|
287
|
-
return {
|
|
288
|
-
success: true,
|
|
289
|
-
action: 'create',
|
|
290
|
-
message: `Branch '${params.branch_name}' criada com sucesso a partir de '${params.from_branch}'`,
|
|
291
|
-
data: branch
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
catch (error) {
|
|
295
|
-
throw new Error(`Falha ao criar branch: ${error instanceof Error ? error.message : String(error)}`);
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
/**
|
|
299
|
-
* Lista todas as branches do
|
|
300
|
-
*
|
|
301
|
-
* FUNCIONALIDADE:
|
|
302
|
-
* - Lista branches com
|
|
303
|
-
* - Retorna
|
|
304
|
-
* - Suporta filtros de
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
* - owner:
|
|
308
|
-
* - repo: Nome do
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
* - page:
|
|
312
|
-
* - limit: Itens por
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* - e repo
|
|
316
|
-
* - Page deve ser >= 1
|
|
317
|
-
* - Limit deve ser entre 1 e 100
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* - Use
|
|
321
|
-
* - Monitore
|
|
322
|
-
* - Mantenha branches organizadas
|
|
323
|
-
*/
|
|
324
|
-
async listBranches(params, provider) {
|
|
325
|
-
try {
|
|
326
|
-
if (!params.repo) {
|
|
327
|
-
throw new Error('Repo
|
|
328
|
-
}
|
|
329
|
-
const currentUser = await provider.getCurrentUser();
|
|
330
|
-
const owner = currentUser.login;
|
|
331
|
-
const page = params.page || 1;
|
|
332
|
-
const limit = params.limit || 30;
|
|
333
|
-
const branches = await provider.listBranches((await provider.getCurrentUser()).login, params.repo, page, limit);
|
|
334
|
-
return {
|
|
335
|
-
success: true,
|
|
336
|
-
action: 'list',
|
|
337
|
-
message: `${branches.length} branches encontradas`,
|
|
338
|
-
data: {
|
|
339
|
-
branches,
|
|
340
|
-
page,
|
|
341
|
-
limit,
|
|
342
|
-
total: branches.length
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
catch (error) {
|
|
347
|
-
throw new Error(`Falha ao listar branches: ${error instanceof Error ? error.message : String(error)}`);
|
|
348
|
-
}
|
|
349
|
-
},
|
|
350
|
-
/**
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
* FUNCIONALIDADE:
|
|
354
|
-
* - Retorna
|
|
355
|
-
* - Inclui commit mais recente
|
|
356
|
-
* -
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
* - owner:
|
|
360
|
-
* - repo: Nome do
|
|
361
|
-
* - branch: Nome da branch
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
* - Todos os
|
|
365
|
-
* - Branch deve existir no
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
* - Use para obter
|
|
369
|
-
* - Verifique status de
|
|
370
|
-
* - Monitore commits recentes
|
|
371
|
-
*/
|
|
372
|
-
async getBranch(params, provider) {
|
|
373
|
-
try {
|
|
374
|
-
if (!params.repo || !params.branch) {
|
|
375
|
-
throw new Error('Repo e branch
|
|
376
|
-
}
|
|
377
|
-
const currentUser = await provider.getCurrentUser();
|
|
378
|
-
const owner = currentUser.login;
|
|
379
|
-
const branch = await provider.getBranch((await provider.getCurrentUser()).login, params.repo, params.branch);
|
|
380
|
-
return {
|
|
381
|
-
success: true,
|
|
382
|
-
action: 'get',
|
|
383
|
-
message: `Branch '${params.branch}' obtida com sucesso`,
|
|
384
|
-
data: branch
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
catch (error) {
|
|
388
|
-
throw new Error(`Falha ao obter branch: ${error instanceof Error ? error.message : String(error)}`);
|
|
389
|
-
}
|
|
390
|
-
},
|
|
391
|
-
/**
|
|
392
|
-
* Deleta uma branch do
|
|
393
|
-
*
|
|
394
|
-
* FUNCIONALIDADE:
|
|
395
|
-
* - Remove branch especificada
|
|
396
|
-
* - Valida
|
|
397
|
-
* - Confirma
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
* - owner:
|
|
401
|
-
* - repo: Nome do
|
|
402
|
-
* - branch: Nome da branch a ser deletada
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
* - Todos os
|
|
406
|
-
* - Branch deve existir
|
|
407
|
-
* -
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
* - Confirme antes de deletar
|
|
411
|
-
* - Verifique se branch foi mergeada
|
|
412
|
-
* - Mantenha backup se
|
|
413
|
-
* - Documente motivo da
|
|
414
|
-
*/
|
|
415
|
-
async deleteBranch(params, provider) {
|
|
416
|
-
try {
|
|
417
|
-
if (!params.repo || !params.branch) {
|
|
418
|
-
throw new Error('Repo e branch
|
|
419
|
-
}
|
|
420
|
-
const currentUser = await provider.getCurrentUser();
|
|
421
|
-
const owner = currentUser.login;
|
|
422
|
-
await provider.deleteBranch((await provider.getCurrentUser()).login, params.repo, params.branch);
|
|
423
|
-
return {
|
|
424
|
-
success: true,
|
|
425
|
-
action: 'delete',
|
|
426
|
-
message: `Branch '${params.branch}' deletada com sucesso`,
|
|
427
|
-
data: { deleted: true }
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
catch (error) {
|
|
431
|
-
throw new Error(`Falha ao deletar branch: ${error instanceof Error ? error.message : String(error)}`);
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
/**
|
|
435
|
-
* Faz merge de uma branch em outra
|
|
436
|
-
*
|
|
437
|
-
* FUNCIONALIDADE:
|
|
438
|
-
* - Merge de branch de origem em branch de destino
|
|
439
|
-
* - Suporta diferentes
|
|
440
|
-
* - Retorna resultado do merge
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
* - owner:
|
|
444
|
-
* - repo: Nome do
|
|
445
|
-
* - head: Branch de origem (
|
|
446
|
-
* - base: Branch de destino (
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
* - merge_method:
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
* - Todos os
|
|
453
|
-
* - Branches devem existir
|
|
454
|
-
* -
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
* - Resolva conflitos antes do merge
|
|
458
|
-
* - Escolha
|
|
459
|
-
* - Teste
|
|
460
|
-
* - Documente
|
|
461
|
-
*/
|
|
462
|
-
async mergeBranches(params, provider) {
|
|
463
|
-
try {
|
|
464
|
-
if (!params.repo || !params.head || !params.base) {
|
|
465
|
-
throw new Error('Repo, head e base
|
|
466
|
-
}
|
|
467
|
-
const currentUser = await provider.getCurrentUser();
|
|
468
|
-
const owner = currentUser.login;
|
|
469
|
-
const mergeMethod = params.merge_method || 'merge';
|
|
470
|
-
// Verificar se as branches existem
|
|
471
|
-
try {
|
|
472
|
-
await provider.getBranch(owner, params.repo, params.head);
|
|
473
|
-
await provider.getBranch(owner, params.repo, params.base);
|
|
474
|
-
}
|
|
475
|
-
catch (error) {
|
|
476
|
-
throw new Error(`Uma das branches
|
|
477
|
-
}
|
|
478
|
-
// Criar pull request para fazer o merge
|
|
479
|
-
const prTitle = `Merge ${params.head} into ${params.base}`;
|
|
480
|
-
const prBody = `Merge
|
|
481
|
-
const pullRequest = await provider.createPullRequest(owner, params.repo, prTitle, prBody, params.head, params.base);
|
|
482
|
-
// Se o merge_method for merge direto, fazer merge
|
|
483
|
-
if (mergeMethod === 'merge') {
|
|
484
|
-
try {
|
|
485
|
-
await provider.mergePullRequest(owner, params.repo, pullRequest.number, 'merge');
|
|
486
|
-
return {
|
|
487
|
-
success: true,
|
|
488
|
-
action: 'merge',
|
|
489
|
-
message: `Merge de '${params.head}' em '${params.base}' realizado com sucesso`,
|
|
490
|
-
data: {
|
|
491
|
-
head: params.head,
|
|
492
|
-
base: params.base,
|
|
493
|
-
merge_method: mergeMethod,
|
|
494
|
-
pull_request: pullRequest,
|
|
495
|
-
merged: true
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
catch (mergeError) {
|
|
500
|
-
return {
|
|
501
|
-
success: true,
|
|
502
|
-
action: 'merge',
|
|
503
|
-
message: `Pull request criado para merge de '${params.head}' em '${params.base}' (merge
|
|
504
|
-
data: {
|
|
505
|
-
head: params.head,
|
|
506
|
-
base: params.base,
|
|
507
|
-
merge_method: mergeMethod,
|
|
508
|
-
pull_request: pullRequest,
|
|
509
|
-
merged: false,
|
|
510
|
-
merge_error: mergeError instanceof Error ? mergeError.message : String(mergeError)
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
return {
|
|
516
|
-
success: true,
|
|
517
|
-
action: 'merge',
|
|
518
|
-
message: `Pull request criado para merge de '${params.head}' em '${params.base}'`,
|
|
519
|
-
data: {
|
|
520
|
-
head: params.head,
|
|
521
|
-
base: params.base,
|
|
522
|
-
merge_method: mergeMethod,
|
|
523
|
-
pull_request: pullRequest,
|
|
524
|
-
requires_manual_review: true
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
catch (error) {
|
|
529
|
-
throw new Error(`Falha ao fazer merge: ${error instanceof Error ? error.message : String(error)}`);
|
|
530
|
-
}
|
|
531
|
-
},
|
|
532
|
-
/**
|
|
533
|
-
* Compara duas branches
|
|
534
|
-
*
|
|
535
|
-
* FUNCIONALIDADE:
|
|
536
|
-
* - Compara
|
|
537
|
-
* - Retorna commits diferentes
|
|
538
|
-
* - Mostra
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
* - owner:
|
|
542
|
-
* - repo: Nome do
|
|
543
|
-
* - base_branch: Branch base para
|
|
544
|
-
* - head_branch: Branch a ser comparada
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
* - Todos os
|
|
548
|
-
* - Ambas as branches devem existir
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
* - Use para verificar
|
|
552
|
-
* - Compare antes de fazer merge
|
|
553
|
-
* - Analise commits diferentes
|
|
554
|
-
* - Documente
|
|
555
|
-
*/
|
|
556
|
-
async compareBranches(params, provider) {
|
|
557
|
-
try {
|
|
558
|
-
if (!params.repo || !params.base_branch || !params.head_branch) {
|
|
559
|
-
throw new Error('Repo, base_branch e head_branch
|
|
560
|
-
}
|
|
561
|
-
const currentUser = await provider.getCurrentUser();
|
|
562
|
-
const owner = currentUser.login;
|
|
563
|
-
// Verificar se as branches existem
|
|
564
|
-
try {
|
|
565
|
-
const baseBranch = await provider.getBranch(owner, params.repo, params.base_branch);
|
|
566
|
-
const headBranch = await provider.getBranch(owner, params.repo, params.head_branch);
|
|
567
|
-
}
|
|
568
|
-
catch (error) {
|
|
569
|
-
throw new Error(`Uma das branches
|
|
570
|
-
}
|
|
571
|
-
// Obter commits de cada branch
|
|
572
|
-
const baseCommits = await provider.listCommits(owner, params.repo, params.base_branch, 1, 10);
|
|
573
|
-
const headCommits = await provider.listCommits(owner, params.repo, params.head_branch, 1, 10);
|
|
574
|
-
// Comparar commits (simplificado - apenas verificar se
|
|
575
|
-
const baseCommitShas = baseCommits.map(c => c.sha);
|
|
576
|
-
const headCommitShas = headCommits.map(c => c.sha);
|
|
577
|
-
const uniqueBaseCommits = baseCommits.filter(c => !headCommitShas.includes(c.sha));
|
|
578
|
-
const uniqueHeadCommits = headCommits.filter(c => !baseCommitShas.includes(c.sha));
|
|
579
|
-
// Usar compareCommits se
|
|
580
|
-
let detailedComparison = null;
|
|
581
|
-
try {
|
|
582
|
-
if (provider.compareCommits) {
|
|
583
|
-
detailedComparison = await provider.compareCommits(owner, params.repo, params.base_branch, params.head_branch);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
catch (error) {
|
|
587
|
-
console.warn('
|
|
588
|
-
}
|
|
589
|
-
return {
|
|
590
|
-
success: true,
|
|
591
|
-
action: 'compare',
|
|
592
|
-
message: `
|
|
593
|
-
data: {
|
|
594
|
-
base: {
|
|
595
|
-
branch: params.base_branch,
|
|
596
|
-
commits: baseCommits.length,
|
|
597
|
-
unique_commits: uniqueBaseCommits.length,
|
|
598
|
-
last_commit: baseCommits[0]?.sha
|
|
599
|
-
},
|
|
600
|
-
head: {
|
|
601
|
-
branch: params.head_branch,
|
|
602
|
-
commits: headCommits.length,
|
|
603
|
-
unique_commits: uniqueHeadCommits.length,
|
|
604
|
-
last_commit: headCommits[0]?.sha
|
|
605
|
-
},
|
|
606
|
-
comparison: {
|
|
607
|
-
base_ahead: uniqueBaseCommits.length,
|
|
608
|
-
head_ahead: uniqueHeadCommits.length,
|
|
609
|
-
divergent: uniqueBaseCommits.length > 0 && uniqueHeadCommits.length > 0,
|
|
610
|
-
mergeable: true, // Assumir mergeable por
|
|
611
|
-
detailed: detailedComparison
|
|
612
|
-
},
|
|
613
|
-
summary: {
|
|
614
|
-
can_merge: uniqueBaseCommits.length === 0 || uniqueHeadCommits.length === 0,
|
|
615
|
-
requires_merge: uniqueBaseCommits.length > 0 && uniqueHeadCommits.length > 0,
|
|
616
|
-
recommendation: uniqueBaseCommits.length === 0 ? 'head
|
|
617
|
-
uniqueHeadCommits.length === 0 ? 'base
|
|
618
|
-
'branches divergiram'
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
catch (error) {
|
|
624
|
-
throw new Error(`Falha ao comparar branches: ${error instanceof Error ? error.message : String(error)}`);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.branchesTool = 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: branches
|
|
9
|
+
*
|
|
10
|
+
* DESCRIÇÃO:
|
|
11
|
+
* Gerenciamento completo de branches Gitea com múltiplas ações
|
|
12
|
+
*
|
|
13
|
+
* FUNCIONALIDADES:
|
|
14
|
+
* - Criação de novas branches
|
|
15
|
+
* - Listagem e busca de branches
|
|
16
|
+
* - Obtenção de detalhes especÃficos
|
|
17
|
+
* - Exclusão de branches
|
|
18
|
+
* - Merge de branches
|
|
19
|
+
* - Comparação entre branches
|
|
20
|
+
*
|
|
21
|
+
* USO:
|
|
22
|
+
* - Para gerenciar fluxo de trabalho Git
|
|
23
|
+
* - Para criar branches de feature
|
|
24
|
+
* - Para organizar desenvolvimento
|
|
25
|
+
* - Para controle de versão
|
|
26
|
+
*
|
|
27
|
+
* RECOMENDAÇÕES:
|
|
28
|
+
* - Use convenções de nomenclatura consistentes
|
|
29
|
+
* - Proteja branches importantes
|
|
30
|
+
* - Mantenha branches limpas
|
|
31
|
+
* - Documente propósito das branches
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Schema de validação para entrada da tool branches
|
|
35
|
+
*
|
|
36
|
+
* VALIDAÇÕES:
|
|
37
|
+
* - action: Ação obrigatória (create, list, get, delete, merge, compare)
|
|
38
|
+
* - Parâmetros especÃficos por ação
|
|
39
|
+
* - Validação de tipos e formatos
|
|
40
|
+
*
|
|
41
|
+
* RECOMENDAÇÕES:
|
|
42
|
+
* - Sempre valide entrada antes de usar
|
|
43
|
+
* - Use parâmetros opcionais adequadamente
|
|
44
|
+
* - Documente parâmetros obrigatórios
|
|
45
|
+
*/
|
|
46
|
+
const BranchesInputSchema = zod_1.z.object({
|
|
47
|
+
action: zod_1.z.enum(['create', 'list', 'get', 'delete', 'merge', 'compare']),
|
|
48
|
+
// Parâmetros comuns
|
|
49
|
+
repo: zod_1.z.string(),
|
|
50
|
+
projectPath: zod_1.z.string().describe('Local project path for git operations'),
|
|
51
|
+
provider: zod_1.z.enum(['gitea', 'github']).describe('Provider to use (gitea or github)'), // Para create
|
|
52
|
+
branch_name: zod_1.z.string().optional(),
|
|
53
|
+
from_branch: zod_1.z.string().optional(),
|
|
54
|
+
// Para get/delete
|
|
55
|
+
branch: zod_1.z.string().optional(),
|
|
56
|
+
// Para merge
|
|
57
|
+
head: zod_1.z.string().optional(),
|
|
58
|
+
base: zod_1.z.string().optional(),
|
|
59
|
+
merge_method: zod_1.z.enum(['merge', 'rebase', 'squash']).optional(),
|
|
60
|
+
// Para list
|
|
61
|
+
page: zod_1.z.number().min(1).optional(),
|
|
62
|
+
limit: zod_1.z.number().min(1).max(100).optional(),
|
|
63
|
+
// Para compare
|
|
64
|
+
base_branch: zod_1.z.string().optional(),
|
|
65
|
+
head_branch: zod_1.z.string().optional(),
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Schema de saÃda padronizado
|
|
69
|
+
*
|
|
70
|
+
* ESTRUTURA:
|
|
71
|
+
* - success: Status da operação
|
|
72
|
+
* - action: Ação executada
|
|
73
|
+
* - message: Mensagem descritiva
|
|
74
|
+
* - data: Dados retornados (opcional)
|
|
75
|
+
* - error: Detalhes do erro (opcional)
|
|
76
|
+
*/
|
|
77
|
+
const BranchesResultSchema = zod_1.z.object({
|
|
78
|
+
success: zod_1.z.boolean(),
|
|
79
|
+
action: zod_1.z.string(),
|
|
80
|
+
message: zod_1.z.string(),
|
|
81
|
+
data: zod_1.z.any().optional(),
|
|
82
|
+
error: zod_1.z.string().optional()
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* Tool: branches
|
|
86
|
+
*
|
|
87
|
+
* DESCRIÇÃO:
|
|
88
|
+
* Gerenciamento completo de branches Gitea com múltiplas ações
|
|
89
|
+
*
|
|
90
|
+
* ACTIONS DISPONÃVEIS:
|
|
91
|
+
*
|
|
92
|
+
* 1. create - Criar nova branch
|
|
93
|
+
* Parâmetros:
|
|
94
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
95
|
+
* - repo (obrigatório): Nome do repositório
|
|
96
|
+
* - branch_name (obrigatório): Nome da nova branch
|
|
97
|
+
* - from_branch (obrigatório): Branch de origem
|
|
98
|
+
*
|
|
99
|
+
* 2. list - Listar branches
|
|
100
|
+
* Parâmetros:
|
|
101
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
102
|
+
* - repo (obrigatório): Nome do repositório
|
|
103
|
+
* - page (opcional): Página da listagem (padrão: 1)
|
|
104
|
+
* - limit (opcional): Itens por página (padrão: 30)
|
|
105
|
+
*
|
|
106
|
+
* 3. get - Obter detalhes da branch
|
|
107
|
+
* Parâmetros:
|
|
108
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
109
|
+
* - repo (obrigatório): Nome do repositório
|
|
110
|
+
* - branch (obrigatório): Nome da branch
|
|
111
|
+
*
|
|
112
|
+
* 4. delete - Deletar branch
|
|
113
|
+
* Parâmetros:
|
|
114
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
115
|
+
* - repo (obrigatório): Nome do repositório
|
|
116
|
+
* - branch (obrigatório): Nome da branch
|
|
117
|
+
*
|
|
118
|
+
* 5. merge - Fazer merge de branches
|
|
119
|
+
* Parâmetros:
|
|
120
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
121
|
+
* - repo (obrigatório): Nome do repositório
|
|
122
|
+
* - head (obrigatório): Branch de origem
|
|
123
|
+
* - base (obrigatório): Branch de destino
|
|
124
|
+
* - merge_method (opcional): Método de merge (padrão: merge)
|
|
125
|
+
*
|
|
126
|
+
* 6. compare - Comparar branches
|
|
127
|
+
* Parâmetros:
|
|
128
|
+
* - owner (obrigatório): Proprietário do repositório
|
|
129
|
+
* - repo (obrigatório): Nome do repositório
|
|
130
|
+
* - base_branch (obrigatório): Branch base
|
|
131
|
+
* - head_branch (obrigatório): Branch de comparação
|
|
132
|
+
*
|
|
133
|
+
* RECOMENDAÇÕES DE USO:
|
|
134
|
+
* - Use nomes descritivos para branches
|
|
135
|
+
* - Mantenha branches principais protegidas
|
|
136
|
+
* - Faça merge regularmente
|
|
137
|
+
* - Documente propósito das branches
|
|
138
|
+
* - Use convenções de nomenclatura
|
|
139
|
+
* - Limpe branches antigas
|
|
140
|
+
*/
|
|
141
|
+
exports.branchesTool = {
|
|
142
|
+
name: 'git-branches',
|
|
143
|
+
description: 'tool: Gerencia branches Git, criação, listagem, merge e comparação\n──────────────\naction create: cria nova branch\naction create requires: repo, branch_name, from_branch, provider, projectPath\n───────────────\naction list: lista branches do repositório\naction list requires: repo, page, limit, provider, projectPath\n───────────────\naction get: obtém detalhes de branch\naction get requires: repo, branch, provider, projectPath\n───────────────\naction delete: remove branch\naction delete requires: repo, branch, provider, projectPath\n───────────────\naction merge: integra branches\naction merge requires: repo, head, base, merge_method, provider, projectPath\n───────────────\naction compare: compara branches\naction compare requires: repo, base_branch, head_branch, provider, projectPath',
|
|
144
|
+
inputSchema: {
|
|
145
|
+
type: 'object',
|
|
146
|
+
properties: {
|
|
147
|
+
action: {
|
|
148
|
+
type: 'string',
|
|
149
|
+
enum: ['create', 'list', 'get', 'delete', 'merge', 'compare'],
|
|
150
|
+
description: 'Action to perform on branches'
|
|
151
|
+
},
|
|
152
|
+
repo: { type: 'string', description: 'Repository name' },
|
|
153
|
+
projectPath: { type: 'string', description: 'Local project path for git operations' },
|
|
154
|
+
provider: { type: 'string', description: 'Specific provider (github, gitea) or use default' },
|
|
155
|
+
branch_name: { type: 'string', description: 'Name of the new branch' },
|
|
156
|
+
from_branch: { type: 'string', description: 'Source branch for creation' },
|
|
157
|
+
branch: { type: 'string', description: 'Branch name' },
|
|
158
|
+
head: { type: 'string', description: 'Source branch for merge' },
|
|
159
|
+
base: { type: 'string', description: 'Target branch for merge' },
|
|
160
|
+
merge_method: {
|
|
161
|
+
type: 'string',
|
|
162
|
+
enum: ['merge', 'rebase', 'squash'],
|
|
163
|
+
description: 'Merge method'
|
|
164
|
+
},
|
|
165
|
+
page: { type: 'number', description: 'Page number', minimum: 1 },
|
|
166
|
+
limit: { type: 'number', description: 'Items per page', minimum: 1, maximum: 100 },
|
|
167
|
+
base_branch: { type: 'string', description: 'Base branch for comparison' },
|
|
168
|
+
head_branch: { type: 'string', description: 'Head branch for comparison' }
|
|
169
|
+
},
|
|
170
|
+
required: ['action', 'repo', 'provider', 'projectPath']
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Handler principal da tool branches
|
|
174
|
+
*
|
|
175
|
+
* FUNCIONALIDADE:
|
|
176
|
+
* - Valida entrada usando Zod schema
|
|
177
|
+
* - Roteia para método especÃfico baseado na ação
|
|
178
|
+
* - Trata erros de forma uniforme
|
|
179
|
+
* - Retorna resultado padronizado
|
|
180
|
+
*
|
|
181
|
+
* FLUXO:
|
|
182
|
+
* 1. Validação de entrada
|
|
183
|
+
* 2. Roteamento por ação
|
|
184
|
+
* 3. Execução do método especÃfico
|
|
185
|
+
* 4. Tratamento de erros
|
|
186
|
+
* 5. Retorno de resultado
|
|
187
|
+
*
|
|
188
|
+
* TRATAMENTO DE ERROS:
|
|
189
|
+
* - Validação: erro de schema
|
|
190
|
+
* - Execução: erro da operação
|
|
191
|
+
* - Roteamento: ação não suportada
|
|
192
|
+
*
|
|
193
|
+
* RECOMENDAÇÕES:
|
|
194
|
+
* - Sempre valide entrada antes de processar
|
|
195
|
+
* - Trate erros especÃficos adequadamente
|
|
196
|
+
* - Log detalhes de erro para debug
|
|
197
|
+
* - Retorne mensagens de erro úteis
|
|
198
|
+
*/
|
|
199
|
+
async handler(input) {
|
|
200
|
+
try {
|
|
201
|
+
const validatedInput = BranchesInputSchema.parse(input);
|
|
202
|
+
// Aplicar auto-detecção apenas para owner dentro do provider especificado
|
|
203
|
+
const processedInput = await (0, user_detection_js_1.applyAutoUserDetection)(validatedInput, validatedInput.provider);
|
|
204
|
+
// Usar o provider especificado pelo usuário ou o padrão se não especificado
|
|
205
|
+
let provider;
|
|
206
|
+
try {
|
|
207
|
+
if (processedInput.provider) {
|
|
208
|
+
const requestedProvider = index_js_1.globalProviderFactory.getProvider(processedInput.provider);
|
|
209
|
+
if (!requestedProvider) {
|
|
210
|
+
console.warn(`[BRANCHES] Provider '${processedInput.provider}' não encontrado, usando padrão`);
|
|
211
|
+
provider = index_js_1.globalProviderFactory.getDefaultProvider();
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
provider = requestedProvider;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
provider = index_js_1.globalProviderFactory.getDefaultProvider();
|
|
219
|
+
}
|
|
220
|
+
if (!provider) {
|
|
221
|
+
throw new Error('Nenhum provider disponÃvel');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
catch (providerError) {
|
|
225
|
+
console.error('[BRANCHES] Erro ao obter provider:', providerError);
|
|
226
|
+
throw new Error(`Erro de configuração do provider: ${providerError instanceof Error ? providerError.message : 'Provider não disponÃvel'}`);
|
|
227
|
+
}
|
|
228
|
+
switch (processedInput.action) {
|
|
229
|
+
case 'create':
|
|
230
|
+
return await this.createBranch(processedInput, provider);
|
|
231
|
+
case 'list':
|
|
232
|
+
return await this.listBranches(processedInput, provider);
|
|
233
|
+
case 'get':
|
|
234
|
+
return await this.getBranch(processedInput, provider);
|
|
235
|
+
case 'delete':
|
|
236
|
+
return await this.deleteBranch(processedInput, provider);
|
|
237
|
+
case 'merge':
|
|
238
|
+
return await this.mergeBranches(processedInput, provider);
|
|
239
|
+
case 'compare':
|
|
240
|
+
return await this.compareBranches(processedInput, provider);
|
|
241
|
+
default:
|
|
242
|
+
throw new Error(`Ação não suportada: ${processedInput.action}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
return {
|
|
247
|
+
success: false,
|
|
248
|
+
action: input.action,
|
|
249
|
+
message: 'Erro na operação de branches',
|
|
250
|
+
error: error instanceof Error ? error.message : String(error)
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
/**
|
|
255
|
+
* Cria uma nova branch no repositório
|
|
256
|
+
*
|
|
257
|
+
* FUNCIONALIDADE:
|
|
258
|
+
* - Valida parâmetros obrigatórios
|
|
259
|
+
* - Cria branch a partir de branch existente
|
|
260
|
+
* - Retorna detalhes da nova branch
|
|
261
|
+
*
|
|
262
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
263
|
+
* - owner: Proprietário do repositório
|
|
264
|
+
* - repo: Nome do repositório
|
|
265
|
+
* - branch_name: Nome da nova branch
|
|
266
|
+
* - from_branch: Branch de origem
|
|
267
|
+
*
|
|
268
|
+
* VALIDAÇÕES:
|
|
269
|
+
* - Todos os parâmetros obrigatórios
|
|
270
|
+
* - Branch de origem deve existir
|
|
271
|
+
* - Nome da nova branch deve ser único
|
|
272
|
+
*
|
|
273
|
+
* RECOMENDAÇÕES:
|
|
274
|
+
* - Use nomes descritivos para branches
|
|
275
|
+
* - Crie a partir de branches estáveis
|
|
276
|
+
* - Documente propósito da branch
|
|
277
|
+
* - Use convenções de nomenclatura
|
|
278
|
+
*/
|
|
279
|
+
async createBranch(params, provider) {
|
|
280
|
+
try {
|
|
281
|
+
if (!params.repo || !params.branch_name || !params.from_branch) {
|
|
282
|
+
throw new Error('Repo, branch_name e from_branch são obrigatórios');
|
|
283
|
+
}
|
|
284
|
+
const currentUser = await provider.getCurrentUser();
|
|
285
|
+
const owner = currentUser.login;
|
|
286
|
+
const branch = await provider.createBranch(owner, params.repo, params.branch_name, params.from_branch);
|
|
287
|
+
return {
|
|
288
|
+
success: true,
|
|
289
|
+
action: 'create',
|
|
290
|
+
message: `Branch '${params.branch_name}' criada com sucesso a partir de '${params.from_branch}'`,
|
|
291
|
+
data: branch
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
throw new Error(`Falha ao criar branch: ${error instanceof Error ? error.message : String(error)}`);
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
/**
|
|
299
|
+
* Lista todas as branches do repositório
|
|
300
|
+
*
|
|
301
|
+
* FUNCIONALIDADE:
|
|
302
|
+
* - Lista branches com paginação
|
|
303
|
+
* - Retorna informações básicas de cada branch
|
|
304
|
+
* - Suporta filtros de paginação
|
|
305
|
+
*
|
|
306
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
307
|
+
* - owner: Proprietário do repositório
|
|
308
|
+
* - repo: Nome do repositório
|
|
309
|
+
*
|
|
310
|
+
* PARÂMETROS OPCIONAIS:
|
|
311
|
+
* - page: Página da listagem (padrão: 1)
|
|
312
|
+
* - limit: Itens por página (padrão: 30, máximo: 100)
|
|
313
|
+
*
|
|
314
|
+
* VALIDAÇÕES:
|
|
315
|
+
* - e repo obrigatórios
|
|
316
|
+
* - Page deve ser >= 1
|
|
317
|
+
* - Limit deve ser entre 1 e 100
|
|
318
|
+
*
|
|
319
|
+
* RECOMENDAÇÕES:
|
|
320
|
+
* - Use paginação para repositórios grandes
|
|
321
|
+
* - Monitore número total de branches
|
|
322
|
+
* - Mantenha branches organizadas
|
|
323
|
+
*/
|
|
324
|
+
async listBranches(params, provider) {
|
|
325
|
+
try {
|
|
326
|
+
if (!params.repo) {
|
|
327
|
+
throw new Error('Repo é obrigatório');
|
|
328
|
+
}
|
|
329
|
+
const currentUser = await provider.getCurrentUser();
|
|
330
|
+
const owner = currentUser.login;
|
|
331
|
+
const page = params.page || 1;
|
|
332
|
+
const limit = params.limit || 30;
|
|
333
|
+
const branches = await provider.listBranches((await provider.getCurrentUser()).login, params.repo, page, limit);
|
|
334
|
+
return {
|
|
335
|
+
success: true,
|
|
336
|
+
action: 'list',
|
|
337
|
+
message: `${branches.length} branches encontradas`,
|
|
338
|
+
data: {
|
|
339
|
+
branches,
|
|
340
|
+
page,
|
|
341
|
+
limit,
|
|
342
|
+
total: branches.length
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
throw new Error(`Falha ao listar branches: ${error instanceof Error ? error.message : String(error)}`);
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
/**
|
|
351
|
+
* Obtém detalhes de uma branch especÃfica
|
|
352
|
+
*
|
|
353
|
+
* FUNCIONALIDADE:
|
|
354
|
+
* - Retorna informações completas da branch
|
|
355
|
+
* - Inclui commit mais recente
|
|
356
|
+
* - Informações de proteção e permissões
|
|
357
|
+
*
|
|
358
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
359
|
+
* - owner: Proprietário do repositório
|
|
360
|
+
* - repo: Nome do repositório
|
|
361
|
+
* - branch: Nome da branch
|
|
362
|
+
*
|
|
363
|
+
* VALIDAÇÕES:
|
|
364
|
+
* - Todos os parâmetros obrigatórios
|
|
365
|
+
* - Branch deve existir no repositório
|
|
366
|
+
*
|
|
367
|
+
* RECOMENDAÇÕES:
|
|
368
|
+
* - Use para obter informações detalhadas
|
|
369
|
+
* - Verifique status de proteção
|
|
370
|
+
* - Monitore commits recentes
|
|
371
|
+
*/
|
|
372
|
+
async getBranch(params, provider) {
|
|
373
|
+
try {
|
|
374
|
+
if (!params.repo || !params.branch) {
|
|
375
|
+
throw new Error('Repo e branch são obrigatórios');
|
|
376
|
+
}
|
|
377
|
+
const currentUser = await provider.getCurrentUser();
|
|
378
|
+
const owner = currentUser.login;
|
|
379
|
+
const branch = await provider.getBranch((await provider.getCurrentUser()).login, params.repo, params.branch);
|
|
380
|
+
return {
|
|
381
|
+
success: true,
|
|
382
|
+
action: 'get',
|
|
383
|
+
message: `Branch '${params.branch}' obtida com sucesso`,
|
|
384
|
+
data: branch
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
throw new Error(`Falha ao obter branch: ${error instanceof Error ? error.message : String(error)}`);
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
/**
|
|
392
|
+
* Deleta uma branch do repositório
|
|
393
|
+
*
|
|
394
|
+
* FUNCIONALIDADE:
|
|
395
|
+
* - Remove branch especificada
|
|
396
|
+
* - Valida permissões de exclusão
|
|
397
|
+
* - Confirma exclusão bem-sucedida
|
|
398
|
+
*
|
|
399
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
400
|
+
* - owner: Proprietário do repositório
|
|
401
|
+
* - repo: Nome do repositório
|
|
402
|
+
* - branch: Nome da branch a ser deletada
|
|
403
|
+
*
|
|
404
|
+
* VALIDAÇÕES:
|
|
405
|
+
* - Todos os parâmetros obrigatórios
|
|
406
|
+
* - Branch deve existir
|
|
407
|
+
* - Usuário deve ter permissão de exclusão
|
|
408
|
+
*
|
|
409
|
+
* RECOMENDAÇÕES:
|
|
410
|
+
* - Confirme antes de deletar
|
|
411
|
+
* - Verifique se branch foi mergeada
|
|
412
|
+
* - Mantenha backup se necessário
|
|
413
|
+
* - Documente motivo da exclusão
|
|
414
|
+
*/
|
|
415
|
+
async deleteBranch(params, provider) {
|
|
416
|
+
try {
|
|
417
|
+
if (!params.repo || !params.branch) {
|
|
418
|
+
throw new Error('Repo e branch são obrigatórios');
|
|
419
|
+
}
|
|
420
|
+
const currentUser = await provider.getCurrentUser();
|
|
421
|
+
const owner = currentUser.login;
|
|
422
|
+
await provider.deleteBranch((await provider.getCurrentUser()).login, params.repo, params.branch);
|
|
423
|
+
return {
|
|
424
|
+
success: true,
|
|
425
|
+
action: 'delete',
|
|
426
|
+
message: `Branch '${params.branch}' deletada com sucesso`,
|
|
427
|
+
data: { deleted: true }
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
catch (error) {
|
|
431
|
+
throw new Error(`Falha ao deletar branch: ${error instanceof Error ? error.message : String(error)}`);
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
/**
|
|
435
|
+
* Faz merge de uma branch em outra
|
|
436
|
+
*
|
|
437
|
+
* FUNCIONALIDADE:
|
|
438
|
+
* - Merge de branch de origem em branch de destino
|
|
439
|
+
* - Suporta diferentes métodos de merge
|
|
440
|
+
* - Retorna resultado do merge
|
|
441
|
+
*
|
|
442
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
443
|
+
* - owner: Proprietário do repositório
|
|
444
|
+
* - repo: Nome do repositório
|
|
445
|
+
* - head: Branch de origem (será mergeada)
|
|
446
|
+
* - base: Branch de destino (receberá o merge)
|
|
447
|
+
*
|
|
448
|
+
* PARÂMETROS OPCIONAIS:
|
|
449
|
+
* - merge_method: Método de merge (merge, rebase, squash)
|
|
450
|
+
*
|
|
451
|
+
* VALIDAÇÕES:
|
|
452
|
+
* - Todos os parâmetros obrigatórios
|
|
453
|
+
* - Branches devem existir
|
|
454
|
+
* - Não deve haver conflitos
|
|
455
|
+
*
|
|
456
|
+
* RECOMENDAÇÕES:
|
|
457
|
+
* - Resolva conflitos antes do merge
|
|
458
|
+
* - Escolha método de merge adequado
|
|
459
|
+
* - Teste após o merge
|
|
460
|
+
* - Documente mudanças
|
|
461
|
+
*/
|
|
462
|
+
async mergeBranches(params, provider) {
|
|
463
|
+
try {
|
|
464
|
+
if (!params.repo || !params.head || !params.base) {
|
|
465
|
+
throw new Error('Repo, head e base são obrigatórios');
|
|
466
|
+
}
|
|
467
|
+
const currentUser = await provider.getCurrentUser();
|
|
468
|
+
const owner = currentUser.login;
|
|
469
|
+
const mergeMethod = params.merge_method || 'merge';
|
|
470
|
+
// Verificar se as branches existem
|
|
471
|
+
try {
|
|
472
|
+
await provider.getBranch(owner, params.repo, params.head);
|
|
473
|
+
await provider.getBranch(owner, params.repo, params.base);
|
|
474
|
+
}
|
|
475
|
+
catch (error) {
|
|
476
|
+
throw new Error(`Uma das branches não existe: ${params.head} ou ${params.base}`);
|
|
477
|
+
}
|
|
478
|
+
// Criar pull request para fazer o merge
|
|
479
|
+
const prTitle = `Merge ${params.head} into ${params.base}`;
|
|
480
|
+
const prBody = `Merge automático da branch '${params.head}' na branch '${params.base}'\n\nMétodo: ${mergeMethod}`;
|
|
481
|
+
const pullRequest = await provider.createPullRequest(owner, params.repo, prTitle, prBody, params.head, params.base);
|
|
482
|
+
// Se o merge_method for merge direto, fazer merge automático
|
|
483
|
+
if (mergeMethod === 'merge') {
|
|
484
|
+
try {
|
|
485
|
+
await provider.mergePullRequest(owner, params.repo, pullRequest.number, 'merge');
|
|
486
|
+
return {
|
|
487
|
+
success: true,
|
|
488
|
+
action: 'merge',
|
|
489
|
+
message: `Merge de '${params.head}' em '${params.base}' realizado com sucesso`,
|
|
490
|
+
data: {
|
|
491
|
+
head: params.head,
|
|
492
|
+
base: params.base,
|
|
493
|
+
merge_method: mergeMethod,
|
|
494
|
+
pull_request: pullRequest,
|
|
495
|
+
merged: true
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
catch (mergeError) {
|
|
500
|
+
return {
|
|
501
|
+
success: true,
|
|
502
|
+
action: 'merge',
|
|
503
|
+
message: `Pull request criado para merge de '${params.head}' em '${params.base}' (merge automático falhou)`,
|
|
504
|
+
data: {
|
|
505
|
+
head: params.head,
|
|
506
|
+
base: params.base,
|
|
507
|
+
merge_method: mergeMethod,
|
|
508
|
+
pull_request: pullRequest,
|
|
509
|
+
merged: false,
|
|
510
|
+
merge_error: mergeError instanceof Error ? mergeError.message : String(mergeError)
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
success: true,
|
|
517
|
+
action: 'merge',
|
|
518
|
+
message: `Pull request criado para merge de '${params.head}' em '${params.base}'`,
|
|
519
|
+
data: {
|
|
520
|
+
head: params.head,
|
|
521
|
+
base: params.base,
|
|
522
|
+
merge_method: mergeMethod,
|
|
523
|
+
pull_request: pullRequest,
|
|
524
|
+
requires_manual_review: true
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
catch (error) {
|
|
529
|
+
throw new Error(`Falha ao fazer merge: ${error instanceof Error ? error.message : String(error)}`);
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
/**
|
|
533
|
+
* Compara duas branches
|
|
534
|
+
*
|
|
535
|
+
* FUNCIONALIDADE:
|
|
536
|
+
* - Compara diferenças entre branches
|
|
537
|
+
* - Retorna commits diferentes
|
|
538
|
+
* - Mostra divergências
|
|
539
|
+
*
|
|
540
|
+
* PARÂMETROS OBRIGATÓRIOS:
|
|
541
|
+
* - owner: Proprietário do repositório
|
|
542
|
+
* - repo: Nome do repositório
|
|
543
|
+
* - base_branch: Branch base para comparação
|
|
544
|
+
* - head_branch: Branch a ser comparada
|
|
545
|
+
*
|
|
546
|
+
* VALIDAÇÕES:
|
|
547
|
+
* - Todos os parâmetros obrigatórios
|
|
548
|
+
* - Ambas as branches devem existir
|
|
549
|
+
*
|
|
550
|
+
* RECOMENDAÇÕES:
|
|
551
|
+
* - Use para verificar divergências
|
|
552
|
+
* - Compare antes de fazer merge
|
|
553
|
+
* - Analise commits diferentes
|
|
554
|
+
* - Documente diferenças importantes
|
|
555
|
+
*/
|
|
556
|
+
async compareBranches(params, provider) {
|
|
557
|
+
try {
|
|
558
|
+
if (!params.repo || !params.base_branch || !params.head_branch) {
|
|
559
|
+
throw new Error('Repo, base_branch e head_branch são obrigatórios');
|
|
560
|
+
}
|
|
561
|
+
const currentUser = await provider.getCurrentUser();
|
|
562
|
+
const owner = currentUser.login;
|
|
563
|
+
// Verificar se as branches existem
|
|
564
|
+
try {
|
|
565
|
+
const baseBranch = await provider.getBranch(owner, params.repo, params.base_branch);
|
|
566
|
+
const headBranch = await provider.getBranch(owner, params.repo, params.head_branch);
|
|
567
|
+
}
|
|
568
|
+
catch (error) {
|
|
569
|
+
throw new Error(`Uma das branches não existe: ${params.base_branch} ou ${params.head_branch}`);
|
|
570
|
+
}
|
|
571
|
+
// Obter commits de cada branch
|
|
572
|
+
const baseCommits = await provider.listCommits(owner, params.repo, params.base_branch, 1, 10);
|
|
573
|
+
const headCommits = await provider.listCommits(owner, params.repo, params.head_branch, 1, 10);
|
|
574
|
+
// Comparar commits (simplificado - apenas verificar se há commits diferentes)
|
|
575
|
+
const baseCommitShas = baseCommits.map(c => c.sha);
|
|
576
|
+
const headCommitShas = headCommits.map(c => c.sha);
|
|
577
|
+
const uniqueBaseCommits = baseCommits.filter(c => !headCommitShas.includes(c.sha));
|
|
578
|
+
const uniqueHeadCommits = headCommits.filter(c => !baseCommitShas.includes(c.sha));
|
|
579
|
+
// Usar compareCommits se disponÃvel no provider
|
|
580
|
+
let detailedComparison = null;
|
|
581
|
+
try {
|
|
582
|
+
if (provider.compareCommits) {
|
|
583
|
+
detailedComparison = await provider.compareCommits(owner, params.repo, params.base_branch, params.head_branch);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
catch (error) {
|
|
587
|
+
console.warn('Comparação detalhada não disponÃvel:', error);
|
|
588
|
+
}
|
|
589
|
+
return {
|
|
590
|
+
success: true,
|
|
591
|
+
action: 'compare',
|
|
592
|
+
message: `Comparação entre '${params.base_branch}' e '${params.head_branch}' realizada com sucesso`,
|
|
593
|
+
data: {
|
|
594
|
+
base: {
|
|
595
|
+
branch: params.base_branch,
|
|
596
|
+
commits: baseCommits.length,
|
|
597
|
+
unique_commits: uniqueBaseCommits.length,
|
|
598
|
+
last_commit: baseCommits[0]?.sha
|
|
599
|
+
},
|
|
600
|
+
head: {
|
|
601
|
+
branch: params.head_branch,
|
|
602
|
+
commits: headCommits.length,
|
|
603
|
+
unique_commits: uniqueHeadCommits.length,
|
|
604
|
+
last_commit: headCommits[0]?.sha
|
|
605
|
+
},
|
|
606
|
+
comparison: {
|
|
607
|
+
base_ahead: uniqueBaseCommits.length,
|
|
608
|
+
head_ahead: uniqueHeadCommits.length,
|
|
609
|
+
divergent: uniqueBaseCommits.length > 0 && uniqueHeadCommits.length > 0,
|
|
610
|
+
mergeable: true, // Assumir mergeable por padrão
|
|
611
|
+
detailed: detailedComparison
|
|
612
|
+
},
|
|
613
|
+
summary: {
|
|
614
|
+
can_merge: uniqueBaseCommits.length === 0 || uniqueHeadCommits.length === 0,
|
|
615
|
+
requires_merge: uniqueBaseCommits.length > 0 && uniqueHeadCommits.length > 0,
|
|
616
|
+
recommendation: uniqueBaseCommits.length === 0 ? 'head está à frente' :
|
|
617
|
+
uniqueHeadCommits.length === 0 ? 'base está à frente' :
|
|
618
|
+
'branches divergiram'
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
catch (error) {
|
|
624
|
+
throw new Error(`Falha ao comparar branches: ${error instanceof Error ? error.message : String(error)}`);
|
|
625
|
+
}
|
|
626
|
+
},
|
|
627
|
+
/**
|
|
628
|
+
* Verifica se erro é relacionado a Git
|
|
629
|
+
*/
|
|
630
|
+
isGitRelatedError(errorMessage) {
|
|
631
|
+
const gitKeywords = [
|
|
632
|
+
'git', 'commit', 'push', 'pull', 'merge', 'conflict', 'branch',
|
|
633
|
+
'remote', 'repository', 'authentication', 'permission', 'unauthorized',
|
|
634
|
+
'divergent', 'non-fast-forward', 'fetch first', 'working tree',
|
|
635
|
+
'uncommitted', 'stash', 'rebase', 'reset', 'checkout'
|
|
636
|
+
];
|
|
637
|
+
const errorLower = errorMessage.toLowerCase();
|
|
638
|
+
return gitKeywords.some(keyword => errorLower.includes(keyword));
|
|
639
|
+
}
|
|
640
|
+
};
|
|
628
641
|
//# sourceMappingURL=git-branches.js.map
|