@andrebuzeli/git-mcp 2.48.0 → 3.0.1
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/README.md +356 -329
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +82 -83
- package/dist/server.js.map +1 -1
- package/dist/tools/git-branches.d.ts +125 -359
- package/dist/tools/git-branches.d.ts.map +1 -1
- package/dist/tools/git-branches.js +179 -530
- package/dist/tools/git-branches.js.map +1 -1
- package/dist/tools/git-commits.d.ts +2 -2
- package/dist/tools/git-config.d.ts +2 -2
- package/dist/tools/git-files.d.ts +246 -406
- package/dist/tools/git-files.d.ts.map +1 -1
- package/dist/tools/git-files.js +556 -499
- package/dist/tools/git-files.js.map +1 -1
- package/dist/tools/git-issues.d.ts +10 -10
- package/dist/tools/git-packages.d.ts +2 -2
- package/dist/tools/git-projects.d.ts +142 -57
- package/dist/tools/git-projects.d.ts.map +1 -1
- package/dist/tools/git-projects.js +281 -283
- package/dist/tools/git-projects.js.map +1 -1
- package/dist/tools/git-pulls.d.ts +16 -16
- package/dist/tools/git-releases.d.ts +131 -401
- package/dist/tools/git-releases.d.ts.map +1 -1
- package/dist/tools/git-releases.js +374 -469
- package/dist/tools/git-releases.js.map +1 -1
- package/dist/tools/git-remote.d.ts +4 -4
- package/dist/tools/git-repositories.d.ts +8 -8
- package/dist/tools/git-reset.d.ts +106 -65
- package/dist/tools/git-reset.d.ts.map +1 -1
- package/dist/tools/git-reset.js +265 -149
- package/dist/tools/git-reset.js.map +1 -1
- package/dist/tools/git-stash.d.ts +110 -68
- package/dist/tools/git-stash.d.ts.map +1 -1
- package/dist/tools/git-stash.js +311 -186
- package/dist/tools/git-stash.js.map +1 -1
- package/dist/tools/git-sync.d.ts +149 -80
- package/dist/tools/git-sync.d.ts.map +1 -1
- package/dist/tools/git-sync.js +346 -246
- package/dist/tools/git-sync.js.map +1 -1
- package/dist/tools/git-tags.d.ts +2 -2
- package/dist/tools/git-undo.d.ts +268 -0
- package/dist/tools/git-undo.d.ts.map +1 -0
- package/dist/tools/git-undo.js +516 -0
- package/dist/tools/git-undo.js.map +1 -0
- package/dist/tools/git-update-project.d.ts +4 -159
- package/dist/tools/git-update-project.d.ts.map +1 -1
- package/dist/tools/git-update-project.js +7 -349
- package/dist/tools/git-update-project.js.map +1 -1
- package/dist/tools/git-versioning.d.ts +286 -0
- package/dist/tools/git-versioning.d.ts.map +1 -0
- package/dist/tools/git-versioning.js +483 -0
- package/dist/tools/git-versioning.js.map +1 -0
- package/dist/tools/git-workflow.d.ts +200 -259
- package/dist/tools/git-workflow.d.ts.map +1 -1
- package/dist/tools/git-workflow.js +424 -498
- package/dist/tools/git-workflow.js.map +1 -1
- package/package.json +5 -14
- package/dist/tools/git-publish.d.ts +0 -327
- package/dist/tools/git-publish.d.ts.map +0 -1
- package/dist/tools/git-publish.js +0 -632
- package/dist/tools/git-publish.js.map +0 -1
|
@@ -1,625 +1,274 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.gitBranchesTool = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const
|
|
6
|
-
const user_detection_js_1 = require("../utils/user-detection.js");
|
|
5
|
+
const git_operations_js_1 = require("../utils/git-operations.js");
|
|
7
6
|
/**
|
|
8
|
-
* Tool: branches
|
|
7
|
+
* Tool: git-branches
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* GERENCIAMENTO DE BRANCHES - Mantém como está
|
|
10
|
+
* Funcionalidades completas de branches Git
|
|
12
11
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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)
|
|
12
|
+
* DESIGNED FOR: Programador individual autônomo
|
|
13
|
+
* PHILOSOPHY: Branches mantidos simples e funcionais
|
|
76
14
|
*/
|
|
77
|
-
const
|
|
15
|
+
const GitBranchesInputSchema = zod_1.z.discriminatedUnion('action', [
|
|
16
|
+
zod_1.z.object({
|
|
17
|
+
action: zod_1.z.literal('create'),
|
|
18
|
+
projectPath: zod_1.z.string(),
|
|
19
|
+
name: zod_1.z.string(),
|
|
20
|
+
from: zod_1.z.string().optional().default('main')
|
|
21
|
+
}),
|
|
22
|
+
zod_1.z.object({
|
|
23
|
+
action: zod_1.z.literal('list'),
|
|
24
|
+
projectPath: zod_1.z.string(),
|
|
25
|
+
all: zod_1.z.boolean().optional().default(false)
|
|
26
|
+
}),
|
|
27
|
+
zod_1.z.object({
|
|
28
|
+
action: zod_1.z.literal('switch'),
|
|
29
|
+
projectPath: zod_1.z.string(),
|
|
30
|
+
name: zod_1.z.string()
|
|
31
|
+
}),
|
|
32
|
+
zod_1.z.object({
|
|
33
|
+
action: zod_1.z.literal('delete'),
|
|
34
|
+
projectPath: zod_1.z.string(),
|
|
35
|
+
name: zod_1.z.string(),
|
|
36
|
+
force: zod_1.z.boolean().optional().default(false)
|
|
37
|
+
}),
|
|
38
|
+
zod_1.z.object({
|
|
39
|
+
action: zod_1.z.literal('merge'),
|
|
40
|
+
projectPath: zod_1.z.string(),
|
|
41
|
+
branch: zod_1.z.string(),
|
|
42
|
+
noEdit: zod_1.z.boolean().optional().default(false)
|
|
43
|
+
}),
|
|
44
|
+
zod_1.z.object({
|
|
45
|
+
action: zod_1.z.literal('compare'),
|
|
46
|
+
projectPath: zod_1.z.string(),
|
|
47
|
+
base: zod_1.z.string(),
|
|
48
|
+
head: zod_1.z.string()
|
|
49
|
+
})
|
|
50
|
+
]);
|
|
51
|
+
const GitBranchesResultSchema = zod_1.z.object({
|
|
78
52
|
success: zod_1.z.boolean(),
|
|
79
53
|
action: zod_1.z.string(),
|
|
80
54
|
message: zod_1.z.string(),
|
|
81
55
|
data: zod_1.z.any().optional(),
|
|
82
|
-
error: zod_1.z.string().optional()
|
|
56
|
+
error: zod_1.z.string().optional(),
|
|
57
|
+
recoverable: zod_1.z.boolean().optional(),
|
|
58
|
+
suggestion: zod_1.z.string().optional()
|
|
83
59
|
});
|
|
84
60
|
/**
|
|
85
|
-
*
|
|
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
|
|
61
|
+
* Enhanced Error Handler for Branches
|
|
140
62
|
*/
|
|
141
|
-
|
|
63
|
+
class BranchesErrorHandler {
|
|
64
|
+
static handleError(error, context) {
|
|
65
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
66
|
+
const errorPatterns = [
|
|
67
|
+
{
|
|
68
|
+
pattern: /branch.*already exists/i,
|
|
69
|
+
suggestion: "Choose a different branch name",
|
|
70
|
+
recoverable: true
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
pattern: /branch.*not found/i,
|
|
74
|
+
suggestion: "Check branch name or create it first",
|
|
75
|
+
recoverable: true
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
pattern: /cannot delete/i,
|
|
79
|
+
suggestion: "Switch to another branch before deleting",
|
|
80
|
+
recoverable: true
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
pattern: /merge conflict/i,
|
|
84
|
+
suggestion: "Resolve conflicts manually then commit",
|
|
85
|
+
recoverable: false
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
const matchedPattern = errorPatterns.find(p => p.pattern.test(errorMessage));
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
action: context,
|
|
92
|
+
message: `Error in ${context}: ${errorMessage}`,
|
|
93
|
+
error: errorMessage,
|
|
94
|
+
recoverable: matchedPattern?.recoverable || false,
|
|
95
|
+
suggestion: matchedPattern?.suggestion
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.gitBranchesTool = {
|
|
142
100
|
name: 'git-branches',
|
|
143
|
-
description:
|
|
101
|
+
description: `🌿 GERENCIAMENTO DE BRANCHES - Mantém como está
|
|
102
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
103
|
+
🌿 BRANCHES:
|
|
104
|
+
• create: Criar nova branch
|
|
105
|
+
• list: Listar branches (locais/remotas)
|
|
106
|
+
• switch: Trocar de branch
|
|
107
|
+
• delete: Remover branch
|
|
108
|
+
• merge: Fazer merge de branches
|
|
109
|
+
• compare: Comparar branches
|
|
110
|
+
|
|
111
|
+
✨ DIFERENCIAIS:
|
|
112
|
+
• Error handling com sugestões
|
|
113
|
+
• Operações seguras com validação
|
|
114
|
+
• Suporte completo a branches`,
|
|
144
115
|
inputSchema: {
|
|
145
116
|
type: 'object',
|
|
146
117
|
properties: {
|
|
147
118
|
action: {
|
|
148
119
|
type: 'string',
|
|
149
|
-
enum: ['create', 'list', '
|
|
150
|
-
description: '
|
|
120
|
+
enum: ['create', 'list', 'switch', 'delete', 'merge', 'compare'],
|
|
121
|
+
description: 'Branch action to perform'
|
|
151
122
|
},
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
branch: { type: 'string', description: 'Branch
|
|
158
|
-
|
|
159
|
-
base: { type: 'string', description: '
|
|
160
|
-
|
|
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' }
|
|
123
|
+
projectPath: { type: 'string', description: 'Local project path' },
|
|
124
|
+
name: { type: 'string', description: 'Branch name' },
|
|
125
|
+
from: { type: 'string', description: 'Source branch', default: 'main' },
|
|
126
|
+
all: { type: 'boolean', description: 'Show all branches', default: false },
|
|
127
|
+
force: { type: 'boolean', description: 'Force delete', default: false },
|
|
128
|
+
branch: { type: 'string', description: 'Branch to merge' },
|
|
129
|
+
noEdit: { type: 'boolean', description: 'No edit merge', default: false },
|
|
130
|
+
base: { type: 'string', description: 'Base branch for comparison' },
|
|
131
|
+
head: { type: 'string', description: 'Head branch for comparison' }
|
|
169
132
|
},
|
|
170
|
-
required: ['action', '
|
|
133
|
+
required: ['action', 'projectPath']
|
|
171
134
|
},
|
|
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
135
|
async handler(input) {
|
|
200
136
|
try {
|
|
201
|
-
const validatedInput =
|
|
202
|
-
|
|
203
|
-
const processedInput = await (0, user_detection_js_1.applyAutoUserDetection)(validatedInput, validatedInput.provider);
|
|
204
|
-
// Usar o provider especificado pelo usuário; se ausente, usar o padrão. Sem fallback quando informado.
|
|
205
|
-
let provider;
|
|
206
|
-
try {
|
|
207
|
-
if (processedInput.provider) {
|
|
208
|
-
const requestedProvider = index_js_1.globalProviderFactory.getProvider(processedInput.provider);
|
|
209
|
-
if (!requestedProvider) {
|
|
210
|
-
throw new Error(`Provider '${processedInput.provider}' não encontrado`);
|
|
211
|
-
}
|
|
212
|
-
provider = requestedProvider;
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
throw new Error("Parâmetro 'provider' é obrigatório e não pode ser omitido");
|
|
216
|
-
}
|
|
217
|
-
if (!provider) {
|
|
218
|
-
throw new Error('Nenhum provider disponível');
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
catch (providerError) {
|
|
222
|
-
console.error('[BRANCHES] Erro ao obter provider:', providerError);
|
|
223
|
-
throw new Error(`Erro de configuração do provider: ${providerError instanceof Error ? providerError.message : 'Provider não disponível'}`);
|
|
224
|
-
}
|
|
225
|
-
switch (processedInput.action) {
|
|
137
|
+
const validatedInput = GitBranchesInputSchema.parse(input);
|
|
138
|
+
switch (validatedInput.action) {
|
|
226
139
|
case 'create':
|
|
227
|
-
return await this.
|
|
140
|
+
return await this.handleCreate(validatedInput);
|
|
228
141
|
case 'list':
|
|
229
|
-
return await this.
|
|
230
|
-
case '
|
|
231
|
-
return await this.
|
|
142
|
+
return await this.handleList(validatedInput);
|
|
143
|
+
case 'switch':
|
|
144
|
+
return await this.handleSwitch(validatedInput);
|
|
232
145
|
case 'delete':
|
|
233
|
-
return await this.
|
|
146
|
+
return await this.handleDelete(validatedInput);
|
|
234
147
|
case 'merge':
|
|
235
|
-
return await this.
|
|
148
|
+
return await this.handleMerge(validatedInput);
|
|
236
149
|
case 'compare':
|
|
237
|
-
return await this.
|
|
150
|
+
return await this.handleCompare(validatedInput);
|
|
238
151
|
default:
|
|
239
|
-
throw new Error(`
|
|
152
|
+
throw new Error(`Action '${validatedInput.action}' not supported`);
|
|
240
153
|
}
|
|
241
154
|
}
|
|
242
155
|
catch (error) {
|
|
243
|
-
return {
|
|
244
|
-
success: false,
|
|
245
|
-
action: input.action,
|
|
246
|
-
message: 'Erro na operação de branches',
|
|
247
|
-
error: error instanceof Error ? error.message : String(error)
|
|
248
|
-
};
|
|
156
|
+
return BranchesErrorHandler.handleError(error, `branches.${input.action}`);
|
|
249
157
|
}
|
|
250
158
|
},
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
* FUNCIONALIDADE:
|
|
255
|
-
* - Valida parâmetros obrigatórios
|
|
256
|
-
* - Cria branch a partir de branch existente
|
|
257
|
-
* - Retorna detalhes da nova branch
|
|
258
|
-
*
|
|
259
|
-
* PARÂMETROS OBRIGATÓRIOS:
|
|
260
|
-
* - projectPath: Caminho do projeto local (OBRIGATÓRIO para TODAS as operações)
|
|
261
|
-
* - provider: Provedor a usar (gitea ou github)
|
|
262
|
-
* - repo: Nome do repositório
|
|
263
|
-
* - branch_name: Nome da nova branch
|
|
264
|
-
* - from_branch: Branch de origem
|
|
265
|
-
*
|
|
266
|
-
* VALIDAÇÕES:
|
|
267
|
-
* - Todos os parâmetros obrigatórios
|
|
268
|
-
* - Branch de origem deve existir
|
|
269
|
-
* - Nome da nova branch deve ser único
|
|
270
|
-
*
|
|
271
|
-
* RECOMENDAÇÕES:
|
|
272
|
-
* - Use nomes descritivos para branches
|
|
273
|
-
* - Crie a partir de branches estáveis
|
|
274
|
-
* - Documente propósito da branch
|
|
275
|
-
* - Use convenções de nomenclatura
|
|
276
|
-
*/
|
|
277
|
-
async createBranch(params, provider) {
|
|
159
|
+
async handleCreate(params) {
|
|
160
|
+
const { projectPath, name, from } = params;
|
|
161
|
+
const gitOps = new git_operations_js_1.GitOperations(projectPath);
|
|
278
162
|
try {
|
|
279
|
-
|
|
280
|
-
|
|
163
|
+
const branchResult = await gitOps.createBranch(name, from);
|
|
164
|
+
if (!branchResult.success) {
|
|
165
|
+
throw new Error(`Failed to create branch: ${branchResult.error}`);
|
|
281
166
|
}
|
|
282
|
-
const currentUser = await provider.getCurrentUser();
|
|
283
|
-
const owner = currentUser.login;
|
|
284
|
-
const branch = await provider.createBranch(owner, params.repo, params.branch_name, params.from_branch);
|
|
285
167
|
return {
|
|
286
168
|
success: true,
|
|
287
169
|
action: 'create',
|
|
288
|
-
message:
|
|
289
|
-
data:
|
|
170
|
+
message: 'Branch created successfully',
|
|
171
|
+
data: { name, from }
|
|
290
172
|
};
|
|
291
173
|
}
|
|
292
174
|
catch (error) {
|
|
293
|
-
|
|
175
|
+
return BranchesErrorHandler.handleError(error, 'create');
|
|
294
176
|
}
|
|
295
177
|
},
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
* FUNCIONALIDADE:
|
|
300
|
-
* - Lista branches com paginação
|
|
301
|
-
* - Retorna informações básicas de cada branch
|
|
302
|
-
* - Suporta filtros de paginação
|
|
303
|
-
*
|
|
304
|
-
* PARÂMETROS OBRIGATÓRIOS:
|
|
305
|
-
* - owner: Proprietário do repositório
|
|
306
|
-
* - repo: Nome do repositório
|
|
307
|
-
*
|
|
308
|
-
* PARÂMETROS OPCIONAIS:
|
|
309
|
-
* - page: Página da listagem (padrão: 1)
|
|
310
|
-
* - limit: Itens por página (padrão: 30, máximo: 100)
|
|
311
|
-
*
|
|
312
|
-
* VALIDAÇÕES:
|
|
313
|
-
* - e repo obrigatórios
|
|
314
|
-
* - Page deve ser >= 1
|
|
315
|
-
* - Limit deve ser entre 1 e 100
|
|
316
|
-
*
|
|
317
|
-
* RECOMENDAÇÕES:
|
|
318
|
-
* - Use paginação para repositórios grandes
|
|
319
|
-
* - Monitore número total de branches
|
|
320
|
-
* - Mantenha branches organizadas
|
|
321
|
-
*/
|
|
322
|
-
async listBranches(params, provider) {
|
|
178
|
+
async handleList(params) {
|
|
179
|
+
const { projectPath, all } = params;
|
|
180
|
+
const gitOps = new git_operations_js_1.GitOperations(projectPath);
|
|
323
181
|
try {
|
|
324
|
-
|
|
325
|
-
|
|
182
|
+
const branchesResult = await gitOps.listBranches({ all });
|
|
183
|
+
if (!branchesResult.success) {
|
|
184
|
+
throw new Error(`Failed to list branches: ${branchesResult.error}`);
|
|
326
185
|
}
|
|
327
|
-
const
|
|
328
|
-
const owner = currentUser.login;
|
|
329
|
-
const page = params.page || 1;
|
|
330
|
-
const limit = params.limit || 30;
|
|
331
|
-
const branches = await provider.listBranches((await provider.getCurrentUser()).login, params.repo, page, limit);
|
|
186
|
+
const branches = branchesResult.output.trim().split('\n').filter(b => b.trim());
|
|
332
187
|
return {
|
|
333
188
|
success: true,
|
|
334
189
|
action: 'list',
|
|
335
|
-
message:
|
|
336
|
-
data: {
|
|
337
|
-
branches,
|
|
338
|
-
page,
|
|
339
|
-
limit,
|
|
340
|
-
total: branches.length
|
|
341
|
-
}
|
|
190
|
+
message: `Found ${branches.length} branches`,
|
|
191
|
+
data: { branches, count: branches.length, all }
|
|
342
192
|
};
|
|
343
193
|
}
|
|
344
194
|
catch (error) {
|
|
345
|
-
|
|
195
|
+
return BranchesErrorHandler.handleError(error, 'list');
|
|
346
196
|
}
|
|
347
197
|
},
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
* FUNCIONALIDADE:
|
|
352
|
-
* - Retorna informações completas da branch
|
|
353
|
-
* - Inclui commit mais recente
|
|
354
|
-
* - Informações de proteção e permissões
|
|
355
|
-
*
|
|
356
|
-
* PARÂMETROS OBRIGATÓRIOS:
|
|
357
|
-
* - owner: Proprietário do repositório
|
|
358
|
-
* - repo: Nome do repositório
|
|
359
|
-
* - branch: Nome da branch
|
|
360
|
-
*
|
|
361
|
-
* VALIDAÇÕES:
|
|
362
|
-
* - Todos os parâmetros obrigatórios
|
|
363
|
-
* - Branch deve existir no repositório
|
|
364
|
-
*
|
|
365
|
-
* RECOMENDAÇÕES:
|
|
366
|
-
* - Use para obter informações detalhadas
|
|
367
|
-
* - Verifique status de proteção
|
|
368
|
-
* - Monitore commits recentes
|
|
369
|
-
*/
|
|
370
|
-
async getBranch(params, provider) {
|
|
198
|
+
async handleSwitch(params) {
|
|
199
|
+
const { projectPath, name } = params;
|
|
200
|
+
const gitOps = new git_operations_js_1.GitOperations(projectPath);
|
|
371
201
|
try {
|
|
372
|
-
|
|
373
|
-
|
|
202
|
+
const switchResult = await gitOps.checkout(name);
|
|
203
|
+
if (!switchResult.success) {
|
|
204
|
+
throw new Error(`Failed to switch branch: ${switchResult.error}`);
|
|
374
205
|
}
|
|
375
|
-
const currentUser = await provider.getCurrentUser();
|
|
376
|
-
const owner = currentUser.login;
|
|
377
|
-
const branch = await provider.getBranch((await provider.getCurrentUser()).login, params.repo, params.branch);
|
|
378
206
|
return {
|
|
379
207
|
success: true,
|
|
380
|
-
action: '
|
|
381
|
-
message:
|
|
382
|
-
data: branch
|
|
208
|
+
action: 'switch',
|
|
209
|
+
message: 'Switched branch successfully',
|
|
210
|
+
data: { branch: name }
|
|
383
211
|
};
|
|
384
212
|
}
|
|
385
213
|
catch (error) {
|
|
386
|
-
|
|
214
|
+
return BranchesErrorHandler.handleError(error, 'switch');
|
|
387
215
|
}
|
|
388
216
|
},
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
* FUNCIONALIDADE:
|
|
393
|
-
* - Remove branch especificada
|
|
394
|
-
* - Valida permissões de exclusão
|
|
395
|
-
* - Confirma exclusão bem-sucedida
|
|
396
|
-
*
|
|
397
|
-
* PARÂMETROS OBRIGATÓRIOS:
|
|
398
|
-
* - owner: Proprietário do repositório
|
|
399
|
-
* - repo: Nome do repositório
|
|
400
|
-
* - branch: Nome da branch a ser deletada
|
|
401
|
-
*
|
|
402
|
-
* VALIDAÇÕES:
|
|
403
|
-
* - Todos os parâmetros obrigatórios
|
|
404
|
-
* - Branch deve existir
|
|
405
|
-
* - Usuário deve ter permissão de exclusão
|
|
406
|
-
*
|
|
407
|
-
* RECOMENDAÇÕES:
|
|
408
|
-
* - Confirme antes de deletar
|
|
409
|
-
* - Verifique se branch foi mergeada
|
|
410
|
-
* - Mantenha backup se necessário
|
|
411
|
-
* - Documente motivo da exclusão
|
|
412
|
-
*/
|
|
413
|
-
async deleteBranch(params, provider) {
|
|
217
|
+
async handleDelete(params) {
|
|
218
|
+
const { projectPath, name, force } = params;
|
|
219
|
+
const gitOps = new git_operations_js_1.GitOperations(projectPath);
|
|
414
220
|
try {
|
|
415
|
-
|
|
416
|
-
|
|
221
|
+
const deleteResult = await gitOps.deleteBranch(name, { force });
|
|
222
|
+
if (!deleteResult.success) {
|
|
223
|
+
throw new Error(`Failed to delete branch: ${deleteResult.error}`);
|
|
417
224
|
}
|
|
418
|
-
const currentUser = await provider.getCurrentUser();
|
|
419
|
-
const owner = currentUser.login;
|
|
420
|
-
await provider.deleteBranch((await provider.getCurrentUser()).login, params.repo, params.branch);
|
|
421
225
|
return {
|
|
422
226
|
success: true,
|
|
423
227
|
action: 'delete',
|
|
424
|
-
message:
|
|
425
|
-
data: {
|
|
228
|
+
message: 'Branch deleted successfully',
|
|
229
|
+
data: { branch: name, force }
|
|
426
230
|
};
|
|
427
231
|
}
|
|
428
232
|
catch (error) {
|
|
429
|
-
|
|
233
|
+
return BranchesErrorHandler.handleError(error, 'delete');
|
|
430
234
|
}
|
|
431
235
|
},
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
* FUNCIONALIDADE:
|
|
436
|
-
* - Merge de branch de origem em branch de destino
|
|
437
|
-
* - Suporta diferentes métodos de merge
|
|
438
|
-
* - Retorna resultado do merge
|
|
439
|
-
*
|
|
440
|
-
* PARÂMETROS OBRIGATÓRIOS:
|
|
441
|
-
* - owner: Proprietário do repositório
|
|
442
|
-
* - repo: Nome do repositório
|
|
443
|
-
* - head: Branch de origem (será mergeada)
|
|
444
|
-
* - base: Branch de destino (receberá o merge)
|
|
445
|
-
*
|
|
446
|
-
* PARÂMETROS OPCIONAIS:
|
|
447
|
-
* - merge_method: Método de merge (merge, rebase, squash)
|
|
448
|
-
*
|
|
449
|
-
* VALIDAÇÕES:
|
|
450
|
-
* - Todos os parâmetros obrigatórios
|
|
451
|
-
* - Branches devem existir
|
|
452
|
-
* - Não deve haver conflitos
|
|
453
|
-
*
|
|
454
|
-
* RECOMENDAÇÕES:
|
|
455
|
-
* - Resolva conflitos antes do merge
|
|
456
|
-
* - Escolha método de merge adequado
|
|
457
|
-
* - Teste após o merge
|
|
458
|
-
* - Documente mudanças
|
|
459
|
-
*/
|
|
460
|
-
async mergeBranches(params, provider) {
|
|
236
|
+
async handleMerge(params) {
|
|
237
|
+
const { projectPath, branch, noEdit } = params;
|
|
238
|
+
const gitOps = new git_operations_js_1.GitOperations(projectPath);
|
|
461
239
|
try {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
// Verificar se as branches existem
|
|
469
|
-
try {
|
|
470
|
-
await provider.getBranch(owner, params.repo, params.head);
|
|
471
|
-
await provider.getBranch(owner, params.repo, params.base);
|
|
472
|
-
}
|
|
473
|
-
catch (error) {
|
|
474
|
-
throw new Error(`Uma das branches não existe: ${params.head} ou ${params.base}`);
|
|
475
|
-
}
|
|
476
|
-
// Criar pull request para fazer o merge
|
|
477
|
-
const prTitle = `Merge ${params.head} into ${params.base}`;
|
|
478
|
-
const prBody = `Merge automático da branch '${params.head}' na branch '${params.base}'\n\nMétodo: ${mergeMethod}`;
|
|
479
|
-
const pullRequest = await provider.createPullRequest(owner, params.repo, prTitle, prBody, params.head, params.base);
|
|
480
|
-
// Se o merge_method for merge direto, fazer merge automático
|
|
481
|
-
if (mergeMethod === 'merge') {
|
|
482
|
-
try {
|
|
483
|
-
await provider.mergePullRequest(owner, params.repo, pullRequest.number, 'merge');
|
|
484
|
-
return {
|
|
485
|
-
success: true,
|
|
486
|
-
action: 'merge',
|
|
487
|
-
message: `Merge de '${params.head}' em '${params.base}' realizado com sucesso`,
|
|
488
|
-
data: {
|
|
489
|
-
head: params.head,
|
|
490
|
-
base: params.base,
|
|
491
|
-
merge_method: mergeMethod,
|
|
492
|
-
pull_request: pullRequest,
|
|
493
|
-
merged: true
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
catch (mergeError) {
|
|
498
|
-
return {
|
|
499
|
-
success: true,
|
|
500
|
-
action: 'merge',
|
|
501
|
-
message: `Pull request criado para merge de '${params.head}' em '${params.base}' (merge automático falhou)`,
|
|
502
|
-
data: {
|
|
503
|
-
head: params.head,
|
|
504
|
-
base: params.base,
|
|
505
|
-
merge_method: mergeMethod,
|
|
506
|
-
pull_request: pullRequest,
|
|
507
|
-
merged: false,
|
|
508
|
-
merge_error: mergeError instanceof Error ? mergeError.message : String(mergeError)
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
}
|
|
240
|
+
const mergeOptions = {};
|
|
241
|
+
if (noEdit)
|
|
242
|
+
mergeOptions.noEdit = true;
|
|
243
|
+
const mergeResult = await gitOps.merge(branch, mergeOptions);
|
|
244
|
+
if (!mergeResult.success) {
|
|
245
|
+
throw new Error(`Failed to merge branch: ${mergeResult.error}`);
|
|
512
246
|
}
|
|
513
247
|
return {
|
|
514
248
|
success: true,
|
|
515
249
|
action: 'merge',
|
|
516
|
-
message:
|
|
517
|
-
data: {
|
|
518
|
-
head: params.head,
|
|
519
|
-
base: params.base,
|
|
520
|
-
merge_method: mergeMethod,
|
|
521
|
-
pull_request: pullRequest,
|
|
522
|
-
requires_manual_review: true
|
|
523
|
-
}
|
|
250
|
+
message: 'Branch merged successfully',
|
|
251
|
+
data: { branch, noEdit }
|
|
524
252
|
};
|
|
525
253
|
}
|
|
526
254
|
catch (error) {
|
|
527
|
-
|
|
255
|
+
return BranchesErrorHandler.handleError(error, 'merge');
|
|
528
256
|
}
|
|
529
257
|
},
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
* FUNCIONALIDADE:
|
|
534
|
-
* - Compara diferenças entre branches
|
|
535
|
-
* - Retorna commits diferentes
|
|
536
|
-
* - Mostra divergências
|
|
537
|
-
*
|
|
538
|
-
* PARÂMETROS OBRIGATÓRIOS:
|
|
539
|
-
* - owner: Proprietário do repositório
|
|
540
|
-
* - repo: Nome do repositório
|
|
541
|
-
* - base_branch: Branch base para comparação
|
|
542
|
-
* - head_branch: Branch a ser comparada
|
|
543
|
-
*
|
|
544
|
-
* VALIDAÇÕES:
|
|
545
|
-
* - Todos os parâmetros obrigatórios
|
|
546
|
-
* - Ambas as branches devem existir
|
|
547
|
-
*
|
|
548
|
-
* RECOMENDAÇÕES:
|
|
549
|
-
* - Use para verificar divergências
|
|
550
|
-
* - Compare antes de fazer merge
|
|
551
|
-
* - Analise commits diferentes
|
|
552
|
-
* - Documente diferenças importantes
|
|
553
|
-
*/
|
|
554
|
-
async compareBranches(params, provider) {
|
|
258
|
+
async handleCompare(params) {
|
|
259
|
+
const { projectPath, base, head } = params;
|
|
260
|
+
const gitOps = new git_operations_js_1.GitOperations(projectPath);
|
|
555
261
|
try {
|
|
556
|
-
|
|
557
|
-
throw new Error('Repo, base_branch e head_branch são obrigatórios');
|
|
558
|
-
}
|
|
559
|
-
const currentUser = await provider.getCurrentUser();
|
|
560
|
-
const owner = currentUser.login;
|
|
561
|
-
// Verificar se as branches existem
|
|
562
|
-
try {
|
|
563
|
-
const baseBranch = await provider.getBranch(owner, params.repo, params.base_branch);
|
|
564
|
-
const headBranch = await provider.getBranch(owner, params.repo, params.head_branch);
|
|
565
|
-
}
|
|
566
|
-
catch (error) {
|
|
567
|
-
throw new Error(`Uma das branches não existe: ${params.base_branch} ou ${params.head_branch}`);
|
|
568
|
-
}
|
|
569
|
-
// Obter commits de cada branch
|
|
570
|
-
const baseCommits = await provider.listCommits(owner, params.repo, params.base_branch, 1, 10);
|
|
571
|
-
const headCommits = await provider.listCommits(owner, params.repo, params.head_branch, 1, 10);
|
|
572
|
-
// Comparar commits (simplificado - apenas verificar se há commits diferentes)
|
|
573
|
-
const baseCommitShas = baseCommits.map(c => c.sha);
|
|
574
|
-
const headCommitShas = headCommits.map(c => c.sha);
|
|
575
|
-
const uniqueBaseCommits = baseCommits.filter(c => !headCommitShas.includes(c.sha));
|
|
576
|
-
const uniqueHeadCommits = headCommits.filter(c => !baseCommitShas.includes(c.sha));
|
|
577
|
-
// Usar compareCommits se disponível no provider
|
|
578
|
-
let detailedComparison = null;
|
|
579
|
-
try {
|
|
580
|
-
if (provider.compareCommits) {
|
|
581
|
-
detailedComparison = await provider.compareCommits(owner, params.repo, params.base_branch, params.head_branch);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
catch (error) {
|
|
585
|
-
console.warn('Comparação detalhada não disponível:', error);
|
|
586
|
-
}
|
|
262
|
+
const diffResult = await gitOps.diff({ commit1: base, commit2: head });
|
|
587
263
|
return {
|
|
588
264
|
success: true,
|
|
589
265
|
action: 'compare',
|
|
590
|
-
message:
|
|
591
|
-
data: {
|
|
592
|
-
base: {
|
|
593
|
-
branch: params.base_branch,
|
|
594
|
-
commits: baseCommits.length,
|
|
595
|
-
unique_commits: uniqueBaseCommits.length,
|
|
596
|
-
last_commit: baseCommits[0]?.sha
|
|
597
|
-
},
|
|
598
|
-
head: {
|
|
599
|
-
branch: params.head_branch,
|
|
600
|
-
commits: headCommits.length,
|
|
601
|
-
unique_commits: uniqueHeadCommits.length,
|
|
602
|
-
last_commit: headCommits[0]?.sha
|
|
603
|
-
},
|
|
604
|
-
comparison: {
|
|
605
|
-
base_ahead: uniqueBaseCommits.length,
|
|
606
|
-
head_ahead: uniqueHeadCommits.length,
|
|
607
|
-
divergent: uniqueBaseCommits.length > 0 && uniqueHeadCommits.length > 0,
|
|
608
|
-
mergeable: true, // Assumir mergeable por padrão
|
|
609
|
-
detailed: detailedComparison
|
|
610
|
-
},
|
|
611
|
-
summary: {
|
|
612
|
-
can_merge: uniqueBaseCommits.length === 0 || uniqueHeadCommits.length === 0,
|
|
613
|
-
requires_merge: uniqueBaseCommits.length > 0 && uniqueHeadCommits.length > 0,
|
|
614
|
-
recommendation: uniqueBaseCommits.length === 0 ? 'head está à frente' :
|
|
615
|
-
uniqueHeadCommits.length === 0 ? 'base está à frente' :
|
|
616
|
-
'branches divergiram'
|
|
617
|
-
}
|
|
618
|
-
}
|
|
266
|
+
message: 'Branch comparison completed',
|
|
267
|
+
data: { diff: diffResult.output, base, head }
|
|
619
268
|
};
|
|
620
269
|
}
|
|
621
270
|
catch (error) {
|
|
622
|
-
|
|
271
|
+
return BranchesErrorHandler.handleError(error, 'compare');
|
|
623
272
|
}
|
|
624
273
|
}
|
|
625
274
|
};
|