duoops 0.2.6 → 0.2.7
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/commands/init.js +50 -4
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -46,6 +46,21 @@ const detectGitRemotePath = () => {
|
|
|
46
46
|
}
|
|
47
47
|
catch { /* ignore */ }
|
|
48
48
|
};
|
|
49
|
+
const resolveProjectId = async (auth, pathOrId) => {
|
|
50
|
+
const base = normalizeGitLabUrl(auth.baseUrl);
|
|
51
|
+
const encoded = encodeURIComponent(normalizeProjectPath(pathOrId));
|
|
52
|
+
try {
|
|
53
|
+
const res = await axios.get(`${base}/api/v4/projects/${encoded}`, {
|
|
54
|
+
headers: gitlabAuthHeaders(auth.token),
|
|
55
|
+
timeout: 5000,
|
|
56
|
+
validateStatus: () => true,
|
|
57
|
+
});
|
|
58
|
+
if (res.status === 200 && res.data?.id) {
|
|
59
|
+
return { id: res.data.id, name: res.data.name_with_namespace, path: res.data.path_with_namespace };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch { /* ignore */ }
|
|
63
|
+
};
|
|
49
64
|
const normalizeProjectPath = (project) => project.replace(/^\/+/, '');
|
|
50
65
|
const normalizeGitLabUrl = (url) => url.replace(/\/+$/, '');
|
|
51
66
|
const setGitlabVariable = async (auth, projectPath, variable) => {
|
|
@@ -447,13 +462,44 @@ export default class Init extends Command {
|
|
|
447
462
|
this.warn('GitLab credentials missing, skipping project configuration.');
|
|
448
463
|
return;
|
|
449
464
|
}
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
465
|
+
const detectedPath = detectGitRemotePath();
|
|
466
|
+
let projectPath;
|
|
467
|
+
let resolvedProject;
|
|
468
|
+
if (detectedPath) {
|
|
469
|
+
resolvedProject = await resolveProjectId(auth, detectedPath);
|
|
470
|
+
}
|
|
471
|
+
if (resolvedProject) {
|
|
472
|
+
const useDetected = await confirm({
|
|
473
|
+
default: true,
|
|
474
|
+
message: `Detected project: ${resolvedProject.name} (ID: ${resolvedProject.id}). Use it?`,
|
|
475
|
+
});
|
|
476
|
+
if (useDetected) {
|
|
477
|
+
projectPath = resolvedProject.path;
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
projectPath = await input({
|
|
481
|
+
default: currentDefault,
|
|
482
|
+
message: 'GitLab project path or URL',
|
|
483
|
+
});
|
|
484
|
+
resolvedProject = await resolveProjectId(auth, projectPath);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
projectPath = await input({
|
|
489
|
+
default: currentDefault ?? detectedPath,
|
|
490
|
+
message: 'GitLab project path or URL',
|
|
491
|
+
});
|
|
492
|
+
resolvedProject = await resolveProjectId(auth, projectPath);
|
|
493
|
+
}
|
|
454
494
|
if (!projectPath) {
|
|
455
495
|
this.warn('Project path is required to configure CI variables.');
|
|
456
496
|
}
|
|
497
|
+
if (resolvedProject) {
|
|
498
|
+
this.log(gray(` Project: ${resolvedProject.name} (ID: ${resolvedProject.id})`));
|
|
499
|
+
}
|
|
500
|
+
else if (projectPath) {
|
|
501
|
+
this.warn(`Could not resolve project "${projectPath}". Continuing with path as-is.`);
|
|
502
|
+
}
|
|
457
503
|
const setAsDefault = await confirm({
|
|
458
504
|
default: !currentDefault,
|
|
459
505
|
message: 'Use this project as the default for DuoOps commands?',
|
package/oclif.manifest.json
CHANGED