@andre.buzeli/git-mcp 16.0.1 → 16.0.2
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/package.json +1 -1
- package/src/providers/providerManager.js +73 -11
package/package.json
CHANGED
|
@@ -146,14 +146,51 @@ export class ProviderManager {
|
|
|
146
146
|
if (createIfMissing) {
|
|
147
147
|
let cr;
|
|
148
148
|
if (organization) {
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
149
|
+
// Tentar criar repo na organização
|
|
150
|
+
try {
|
|
151
|
+
cr = await this.github.rest.repos.createInOrg({
|
|
152
|
+
org: organization,
|
|
153
|
+
name: repoName,
|
|
154
|
+
description,
|
|
155
|
+
private: isPrivate,
|
|
156
|
+
auto_init: false,
|
|
157
|
+
});
|
|
158
|
+
} catch (orgRepoErr) {
|
|
159
|
+
const errMsg = String(orgRepoErr?.message || orgRepoErr).toLowerCase();
|
|
160
|
+
// Se org não existe, criar a org primeiro e depois o repo
|
|
161
|
+
if (errMsg.includes("not found") || errMsg.includes("404")) {
|
|
162
|
+
console.error(`[ProviderManager] GitHub org '${organization}' not found, creating...`);
|
|
163
|
+
try {
|
|
164
|
+
await this.github.rest.orgs.createForAuthenticatedUser
|
|
165
|
+
? await this.github.request("POST /user/orgs", { login: organization, profile_name: organization })
|
|
166
|
+
: null;
|
|
167
|
+
} catch (orgCreateErr) {
|
|
168
|
+
// GitHub free users can't create orgs via API, try alternative
|
|
169
|
+
console.error(`[ProviderManager] GitHub org creation failed: ${orgCreateErr?.message}. Trying as user repo with org topic...`);
|
|
170
|
+
}
|
|
171
|
+
// Retry repo creation in org
|
|
172
|
+
try {
|
|
173
|
+
cr = await this.github.rest.repos.createInOrg({
|
|
174
|
+
org: organization,
|
|
175
|
+
name: repoName,
|
|
176
|
+
description,
|
|
177
|
+
private: isPrivate,
|
|
178
|
+
auto_init: false,
|
|
179
|
+
});
|
|
180
|
+
} catch {
|
|
181
|
+
// Fallback: create as personal repo if org creation not possible
|
|
182
|
+
console.error(`[ProviderManager] Fallback: creating '${repoName}' as personal repo (GitHub org '${organization}' unavailable)`);
|
|
183
|
+
cr = await this.github.rest.repos.createForAuthenticatedUser({
|
|
184
|
+
name: repoName,
|
|
185
|
+
description: `[org:${organization}] ${description}`,
|
|
186
|
+
private: isPrivate,
|
|
187
|
+
auto_init: false,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
throw orgRepoErr;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
157
194
|
} else {
|
|
158
195
|
// Criar repo no usuário pessoal
|
|
159
196
|
cr = await this.github.rest.repos.createForAuthenticatedUser({
|
|
@@ -187,9 +224,34 @@ export class ProviderManager {
|
|
|
187
224
|
} catch (e) {
|
|
188
225
|
if (createIfMissing) {
|
|
189
226
|
try {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
227
|
+
let createUrl;
|
|
228
|
+
if (organization) {
|
|
229
|
+
// Verificar se org existe, criar se não existir
|
|
230
|
+
try {
|
|
231
|
+
await axios.get(`${this.giteaUrl}/api/v1/orgs/${organization}`,
|
|
232
|
+
{ headers: { Authorization: `token ${this.giteaToken}` }, timeout: 8000 });
|
|
233
|
+
} catch (orgCheckErr) {
|
|
234
|
+
// Org não existe, criar
|
|
235
|
+
console.error(`[ProviderManager] Gitea org '${organization}' not found, creating...`);
|
|
236
|
+
try {
|
|
237
|
+
await axios.post(`${this.giteaUrl}/api/v1/orgs`, {
|
|
238
|
+
username: organization,
|
|
239
|
+
full_name: organization,
|
|
240
|
+
description: `Organization ${organization}`,
|
|
241
|
+
visibility: isPublic ? "public" : "limited",
|
|
242
|
+
}, { headers: { Authorization: `token ${this.giteaToken}` }, timeout: 8000 });
|
|
243
|
+
console.error(`[ProviderManager] Gitea org '${organization}' created successfully`);
|
|
244
|
+
} catch (orgCreateErr) {
|
|
245
|
+
const msg = String(orgCreateErr?.message || orgCreateErr).toLowerCase();
|
|
246
|
+
if (!msg.includes("already exists") && !msg.includes("409")) {
|
|
247
|
+
console.error(`[ProviderManager] Gitea org creation failed: ${orgCreateErr?.message}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
createUrl = `${this.giteaUrl}/api/v1/orgs/${organization}/repos`;
|
|
252
|
+
} else {
|
|
253
|
+
createUrl = `${this.giteaUrl}/api/v1/user/repos`;
|
|
254
|
+
}
|
|
193
255
|
const cr = await axios.post(createUrl,
|
|
194
256
|
{ name: repoName, description, private: isPrivate, auto_init: false },
|
|
195
257
|
{ headers: { Authorization: `token ${this.giteaToken}` }, timeout: 8000 });
|