huntban-cli 0.0.0-stage → 1.0.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/bin/huntban.js +199 -0
- package/lib/api.js +183 -0
- package/lib/commands/check.js +64 -0
- package/lib/commands/close.js +45 -0
- package/lib/commands/comment.js +27 -0
- package/lib/commands/config.js +66 -0
- package/lib/commands/create.js +71 -0
- package/lib/commands/get.js +77 -0
- package/lib/commands/init.js +123 -0
- package/lib/commands/list.js +50 -0
- package/lib/commands/move.js +36 -0
- package/lib/commands/next.js +116 -0
- package/lib/commands/open.js +43 -0
- package/lib/commands/pipelines.js +34 -0
- package/lib/commands/review.js +49 -0
- package/lib/commands/to.js +126 -0
- package/lib/commands/update.js +31 -0
- package/lib/config.js +105 -0
- package/lib/interactive.js +57 -0
- package/package.json +20 -4
- package/templates/SKILL.md +191 -0
- package/README.md +0 -3
package/bin/huntban.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Huntban CLI Executable
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const packageJson = require('../package.json');
|
|
8
|
+
const { loadConfig } = require('../lib/config');
|
|
9
|
+
|
|
10
|
+
const listCommand = require('../lib/commands/list');
|
|
11
|
+
const getCommand = require('../lib/commands/get');
|
|
12
|
+
const closeCommand = require('../lib/commands/close');
|
|
13
|
+
const commentCommand = require('../lib/commands/comment');
|
|
14
|
+
const updateCommand = require('../lib/commands/update');
|
|
15
|
+
const createCommand = require('../lib/commands/create');
|
|
16
|
+
const configCommand = require('../lib/commands/config');
|
|
17
|
+
const pipelinesCommand = require('../lib/commands/pipelines');
|
|
18
|
+
const moveCommand = require('../lib/commands/move');
|
|
19
|
+
const reviewCommand = require('../lib/commands/review');
|
|
20
|
+
const nextCommand = require('../lib/commands/next');
|
|
21
|
+
const toCommand = require('../lib/commands/to');
|
|
22
|
+
const openCommand = require('../lib/commands/open');
|
|
23
|
+
const checkCommand = require('../lib/commands/check');
|
|
24
|
+
const initCommand = require('../lib/commands/init');
|
|
25
|
+
|
|
26
|
+
function parseArgs(args) {
|
|
27
|
+
const parsed = {
|
|
28
|
+
command: args[0],
|
|
29
|
+
positional: [],
|
|
30
|
+
flags: {}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
for (let i = 1; i < args.length; i++) {
|
|
34
|
+
const arg = args[i];
|
|
35
|
+
if (arg.startsWith('--')) {
|
|
36
|
+
const key = arg.slice(2);
|
|
37
|
+
const nextArg = args[i + 1];
|
|
38
|
+
if (nextArg && !nextArg.startsWith('-')) {
|
|
39
|
+
parsed.flags[key] = nextArg;
|
|
40
|
+
i++;
|
|
41
|
+
} else {
|
|
42
|
+
parsed.flags[key] = true;
|
|
43
|
+
}
|
|
44
|
+
} else if (arg.startsWith('-') && arg.length === 2) {
|
|
45
|
+
const key = arg.slice(1);
|
|
46
|
+
const nextArg = args[i + 1];
|
|
47
|
+
if (nextArg && !nextArg.startsWith('-')) {
|
|
48
|
+
parsed.flags[key] = nextArg;
|
|
49
|
+
i++;
|
|
50
|
+
} else {
|
|
51
|
+
parsed.flags[key] = true;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
parsed.positional.push(arg);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return parsed;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function showHelp() {
|
|
62
|
+
console.log(`
|
|
63
|
+
Huntban CLI - Automatización de Tableros y Tareas para Terminal y Agentes
|
|
64
|
+
========================================================================
|
|
65
|
+
|
|
66
|
+
Uso:
|
|
67
|
+
huntban <comando> [argumentos] [opciones]
|
|
68
|
+
|
|
69
|
+
Comandos principales (admiten alias cortos):
|
|
70
|
+
next, nx <id|cod> Avanzar automáticamente a la siguiente columna según el orden
|
|
71
|
+
to, mv <id|cod> [col] Mover a una columna (ej: huntban to BLBX-55 qa / o interactivo)
|
|
72
|
+
close, cl <id|cod> Cierre definitivo (closed-success) con fecha real y comentario
|
|
73
|
+
review, qa <id|cod> Enviar a revisión con reporte de entrega para el revisor
|
|
74
|
+
list, ls Listar tareas del tablero (admite filtros)
|
|
75
|
+
get, show <id|cod> Consultar detalle de una tarea (ej: huntban get BLBX-55)
|
|
76
|
+
cols, pipelines Listar columnas/etapas ordenadas del tablero y sus fases
|
|
77
|
+
open [id|cod] Abrir el tablero o tarea directamente en el navegador
|
|
78
|
+
comment, msg <id|cod> Dejar un comentario en una tarea con atribución de autor
|
|
79
|
+
check, tick <id> <item> Marcar un criterio/checklist como completado (--undo para desmarcar)
|
|
80
|
+
update <id|cod> Actualizar fase, columna, fechas u objetivo
|
|
81
|
+
create, add Crear una nueva tarea en el tablero
|
|
82
|
+
init, attach Vincular este repositorio e instalar el skill en .agents/skills/
|
|
83
|
+
config [show|set] Ver o guardar configuración global (~/.huntban/config.json)
|
|
84
|
+
|
|
85
|
+
Opciones y Flags globales:
|
|
86
|
+
--board <id> ID del tablero (Proxycard board)
|
|
87
|
+
--email <email> Email del usuario para atribución de autor (opcional)
|
|
88
|
+
--url <url> URL de la API (por defecto: http://localhost:3000)
|
|
89
|
+
--key <key> API Key del conector (BoardWebhook)
|
|
90
|
+
--secret <secret> API Secret del conector (BoardWebhook)
|
|
91
|
+
-m, --comment <texto> Texto para comentarios o reportes de cierre
|
|
92
|
+
--date <YYYY-MM-DD> Fecha real de ejecución (para cierre o inicio)
|
|
93
|
+
--json Salida en formato JSON sin formato interactivo
|
|
94
|
+
-v, --version Mostrar la versión instalada
|
|
95
|
+
-h, --help Mostrar esta ayuda
|
|
96
|
+
`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function main() {
|
|
100
|
+
const rawArgs = process.argv.slice(2);
|
|
101
|
+
if (rawArgs.length === 0 || rawArgs[0] === '--help' || rawArgs[0] === '-h') {
|
|
102
|
+
showHelp();
|
|
103
|
+
process.exit(0);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (rawArgs[0] === '--version' || rawArgs[0] === '-v' || rawArgs[0] === 'version') {
|
|
107
|
+
console.log(`huntban-cli v${packageJson.version}`);
|
|
108
|
+
process.exit(0);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const parsed = parseArgs(rawArgs);
|
|
112
|
+
const config = loadConfig();
|
|
113
|
+
|
|
114
|
+
// Flags prioritarios sobre configuración persistente
|
|
115
|
+
if (parsed.flags.url) config.apiUrl = parsed.flags.url;
|
|
116
|
+
if (parsed.flags.key) config.apiKey = parsed.flags.key;
|
|
117
|
+
if (parsed.flags.secret) config.apiSecret = parsed.flags.secret;
|
|
118
|
+
if (parsed.flags.board) config.boardId = parsed.flags.board;
|
|
119
|
+
if (parsed.flags.email) config.userEmail = parsed.flags.email;
|
|
120
|
+
|
|
121
|
+
// Los comandos config e init/attach no requieren apiKey previa para setearla
|
|
122
|
+
if (parsed.command === 'config') {
|
|
123
|
+
await configCommand(parsed);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (parsed.command === 'init' || parsed.command === 'attach') {
|
|
128
|
+
await initCommand(parsed, config);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!config.apiKey) {
|
|
133
|
+
console.error('❌ Falta API Key. Configúrala con:');
|
|
134
|
+
console.error(' huntban config set --key <API_KEY> --secret <API_SECRET> --board <BOARD_ID>');
|
|
135
|
+
console.error(' O pasa el flag "--key <API_KEY>"\n');
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
switch (parsed.command) {
|
|
140
|
+
case 'list':
|
|
141
|
+
case 'ls':
|
|
142
|
+
await listCommand(parsed, config);
|
|
143
|
+
break;
|
|
144
|
+
case 'get':
|
|
145
|
+
case 'show':
|
|
146
|
+
await getCommand(parsed, config);
|
|
147
|
+
break;
|
|
148
|
+
case 'next':
|
|
149
|
+
case 'nx':
|
|
150
|
+
case 'advance':
|
|
151
|
+
await nextCommand(parsed, config);
|
|
152
|
+
break;
|
|
153
|
+
case 'to':
|
|
154
|
+
case 'move':
|
|
155
|
+
case 'mv':
|
|
156
|
+
await toCommand(parsed, config);
|
|
157
|
+
break;
|
|
158
|
+
case 'close':
|
|
159
|
+
case 'cl':
|
|
160
|
+
await closeCommand(parsed, config);
|
|
161
|
+
break;
|
|
162
|
+
case 'comment':
|
|
163
|
+
case 'msg':
|
|
164
|
+
await commentCommand(parsed, config);
|
|
165
|
+
break;
|
|
166
|
+
case 'update':
|
|
167
|
+
await updateCommand(parsed, config);
|
|
168
|
+
break;
|
|
169
|
+
case 'create':
|
|
170
|
+
case 'add':
|
|
171
|
+
await createCommand(parsed, config);
|
|
172
|
+
break;
|
|
173
|
+
case 'pipelines':
|
|
174
|
+
case 'cols':
|
|
175
|
+
case 'columns':
|
|
176
|
+
await pipelinesCommand(parsed, config);
|
|
177
|
+
break;
|
|
178
|
+
case 'review':
|
|
179
|
+
case 'qa':
|
|
180
|
+
await reviewCommand(parsed, config);
|
|
181
|
+
break;
|
|
182
|
+
case 'open':
|
|
183
|
+
await openCommand(parsed, config);
|
|
184
|
+
break;
|
|
185
|
+
case 'check':
|
|
186
|
+
case 'tick':
|
|
187
|
+
case 'done':
|
|
188
|
+
await checkCommand(parsed, config);
|
|
189
|
+
break;
|
|
190
|
+
default:
|
|
191
|
+
console.error(`❌ Comando desconocido: "${parsed.command}". Usa "huntban --help" para ver los comandos disponibles.`);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
main().catch((err) => {
|
|
197
|
+
console.error('❌ Error no controlado en huntban-cli:', err);
|
|
198
|
+
process.exit(1);
|
|
199
|
+
});
|
package/lib/api.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cliente HTTP nativo para la API de Connector de Huntban
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
function buildUrl(baseUrl, endpoint) {
|
|
6
|
+
let base = (baseUrl || 'http://localhost:3000').replace(/\/$/, '');
|
|
7
|
+
let path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
|
8
|
+
|
|
9
|
+
// Si baseUrl ya incluye /api/v2 o /api/v1
|
|
10
|
+
if (base.endsWith('/api/v2')) {
|
|
11
|
+
if (path.startsWith('/api/v1/')) {
|
|
12
|
+
path = path.slice('/api/v1'.length);
|
|
13
|
+
} else if (path.startsWith('/api/v2/')) {
|
|
14
|
+
path = path.slice('/api/v2'.length);
|
|
15
|
+
}
|
|
16
|
+
} else if (base.endsWith('/api/v1')) {
|
|
17
|
+
if (path.startsWith('/api/v1/')) {
|
|
18
|
+
path = path.slice('/api/v1'.length);
|
|
19
|
+
} else if (path.startsWith('/api/v2/')) {
|
|
20
|
+
path = path.slice('/api/v2'.length);
|
|
21
|
+
}
|
|
22
|
+
} else if (!base.includes('/api/')) {
|
|
23
|
+
// Si no tiene prefijo /api, por defecto asumimos /api/v1 si no viene indicado
|
|
24
|
+
if (!path.startsWith('/api/')) {
|
|
25
|
+
path = `/api/v1${path}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return `${base}${path}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function apiRequest(endpoint, method = 'GET', body = null, config = {}) {
|
|
33
|
+
const url = buildUrl(config.apiUrl, endpoint);
|
|
34
|
+
|
|
35
|
+
const headers = {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
'x-api-key': config.apiKey || ''
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (config.apiSecret) {
|
|
41
|
+
headers['x-api-secret'] = config.apiSecret;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (config.userEmail) {
|
|
45
|
+
headers['x-user-email'] = config.userEmail;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const options = {
|
|
49
|
+
method,
|
|
50
|
+
headers
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (body && (method === 'POST' || method === 'PUT')) {
|
|
54
|
+
options.body = JSON.stringify(body);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const res = await fetch(url, options);
|
|
59
|
+
const data = await res.json().catch(() => null);
|
|
60
|
+
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
const errMsg = data?.error || data?.message || `HTTP ${res.status} ${res.statusText}`;
|
|
63
|
+
throw new Error(errMsg);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return data;
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error(`❌ Error en petición [${method} ${url}]:`, err.message);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Obtiene las columnas/pipelines del tablero de forma agnóstica a v1 o v2
|
|
75
|
+
*/
|
|
76
|
+
async function getPipelines(boardId, config) {
|
|
77
|
+
// 1. Probar /connector/schema (v2 y contratos completos del tablero)
|
|
78
|
+
try {
|
|
79
|
+
const schema = await apiRequest(`/boards/${boardId}/connector/schema`, 'GET', null, config);
|
|
80
|
+
const pipes = schema?.data?.pipelines || schema?.pipelines || [];
|
|
81
|
+
if (Array.isArray(pipes) && pipes.length > 0) {
|
|
82
|
+
return pipes;
|
|
83
|
+
}
|
|
84
|
+
} catch (e) {
|
|
85
|
+
// Continuar al fallback
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 2. Probar view=pipelines (v1 / backend optimizado)
|
|
89
|
+
try {
|
|
90
|
+
const res = await apiRequest(`/boards/${boardId}/connector?view=pipelines`, 'GET', null, config);
|
|
91
|
+
if (Array.isArray(res?.data) && res.data.length > 0) {
|
|
92
|
+
return res.data;
|
|
93
|
+
}
|
|
94
|
+
} catch (e) {
|
|
95
|
+
// ignorar
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Obtiene una tarea por código o ID
|
|
103
|
+
*/
|
|
104
|
+
async function getTask(boardId, target, config) {
|
|
105
|
+
const taskParams = new URLSearchParams();
|
|
106
|
+
if (/^[0-9a-fA-F]{24}$/.test(target)) {
|
|
107
|
+
taskParams.set('taskId', target);
|
|
108
|
+
} else {
|
|
109
|
+
taskParams.set('code', target);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const taskRes = await apiRequest(`/boards/${boardId}/connector?${taskParams.toString()}`, 'GET', null, config);
|
|
113
|
+
const data = taskRes?.data !== undefined ? taskRes.data : taskRes;
|
|
114
|
+
if (!data) return null;
|
|
115
|
+
|
|
116
|
+
// Si la API devolvió directamente el objeto de la tarea
|
|
117
|
+
if (!Array.isArray(data)) {
|
|
118
|
+
return data;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (data.length === 0) return null;
|
|
122
|
+
|
|
123
|
+
const cleanTarget = String(target).trim().toLowerCase();
|
|
124
|
+
const matched = data.find(t => {
|
|
125
|
+
const id = String(t.id || t._id || '').toLowerCase();
|
|
126
|
+
const code = String(t.code || t.card?.code || '').toLowerCase();
|
|
127
|
+
const serial = t.serial !== undefined && t.serial !== null ? String(t.serial).toLowerCase() : null;
|
|
128
|
+
return id === cleanTarget || code === cleanTarget || serial === cleanTarget;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return matched || (data.length === 1 ? data[0] : null);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Resuelve una tarea a partir de su código o ID, garantizando el ObjectId para la API
|
|
136
|
+
*/
|
|
137
|
+
async function resolveTask(boardId, target, config) {
|
|
138
|
+
if (!target) return null;
|
|
139
|
+
|
|
140
|
+
// Si ya es un ObjectId de 24 caracteres hexadecimales
|
|
141
|
+
if (/^[0-9a-fA-F]{24}$/.test(target)) {
|
|
142
|
+
return {
|
|
143
|
+
id: target,
|
|
144
|
+
code: target
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Si es un código (ej: TSTT-28, BLBX-55, #28, etc.)
|
|
149
|
+
const task = await getTask(boardId, target, config);
|
|
150
|
+
if (!task) {
|
|
151
|
+
console.error(`❌ No se encontró ninguna tarea con el código o ID: "${target}" en el tablero.`);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
id: task.id || task._id,
|
|
157
|
+
code: task.code || target,
|
|
158
|
+
task
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Muestra información del usuario que ejecutó la acción o advierte si no se encontró
|
|
164
|
+
*/
|
|
165
|
+
function checkActor(actor, expectedEmail) {
|
|
166
|
+
if (!expectedEmail) return;
|
|
167
|
+
|
|
168
|
+
if (actor && actor.email) {
|
|
169
|
+
console.log(`👤 Autor: ${actor.name || actor.email} (${actor.email})`);
|
|
170
|
+
} else {
|
|
171
|
+
console.warn(`⚠️ Advertencia: El email '${expectedEmail}' no coincide con ningún usuario registrado en Huntban.`);
|
|
172
|
+
console.warn(` La acción se ejecutó correctamente sin atribución de usuario.`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
module.exports = {
|
|
177
|
+
buildUrl,
|
|
178
|
+
apiRequest,
|
|
179
|
+
getPipelines,
|
|
180
|
+
getTask,
|
|
181
|
+
resolveTask,
|
|
182
|
+
checkActor
|
|
183
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const { apiRequest, getTask, checkActor } = require('../api');
|
|
2
|
+
|
|
3
|
+
module.exports = async function checkCommand(parsed, config) {
|
|
4
|
+
const target = parsed.positional[0] || parsed.flags.task;
|
|
5
|
+
const subtarget = parsed.positional[1] || parsed.flags.subtask || parsed.flags.item;
|
|
6
|
+
const boardId = parsed.flags.board || config.boardId;
|
|
7
|
+
const isDone = !parsed.flags.undo && !parsed.flags.undone;
|
|
8
|
+
|
|
9
|
+
if (!target || !subtarget) {
|
|
10
|
+
console.error('❌ Falta información.');
|
|
11
|
+
console.error(' Uso: huntban check <TASK_ID_O_CODIGO> <SUBTASK_ID_O_TEXTO> [--undo]');
|
|
12
|
+
console.error(' Ejemplos:');
|
|
13
|
+
console.error(' huntban check TSTT-1 "Crear componente"');
|
|
14
|
+
console.error(' huntban check TSTT-1 6a2d90fbd939e792adb7c04c');
|
|
15
|
+
console.error(' huntban check TSTT-1 "Crear componente" --undo');
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 1. Obtener la tarea para localizar el item del checklist
|
|
20
|
+
const task = await getTask(boardId, target, config);
|
|
21
|
+
if (!task) {
|
|
22
|
+
console.error(`❌ Tarea no encontrada: "${target}"`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let matchedItem = null;
|
|
27
|
+
const cleanSub = String(subtarget).trim().toLowerCase();
|
|
28
|
+
|
|
29
|
+
const updatedCheckboxes = (task.checkboxes || []).map(group => {
|
|
30
|
+
return {
|
|
31
|
+
name: group.name || 'Tareas',
|
|
32
|
+
isVisual: !!group.isVisual,
|
|
33
|
+
tasks: (group.tasks || []).map(item => {
|
|
34
|
+
const matchById = item.id && String(item.id).toLowerCase() === cleanSub;
|
|
35
|
+
const matchByText = item.text && item.text.toLowerCase().includes(cleanSub);
|
|
36
|
+
if (matchById || matchByText) {
|
|
37
|
+
matchedItem = item;
|
|
38
|
+
return { ...item, done: isDone };
|
|
39
|
+
}
|
|
40
|
+
return item;
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const payload = {
|
|
46
|
+
taskId: task.id || task._id,
|
|
47
|
+
checkboxes: updatedCheckboxes,
|
|
48
|
+
checklistActions: [
|
|
49
|
+
{
|
|
50
|
+
type: 'update',
|
|
51
|
+
subtaskId: matchedItem?.id || subtarget,
|
|
52
|
+
text: matchedItem?.text || subtarget,
|
|
53
|
+
done: isDone
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const endpoint = `/boards/${boardId}/connector`;
|
|
59
|
+
const response = await apiRequest(endpoint, 'PUT', payload, config);
|
|
60
|
+
|
|
61
|
+
console.log(`\n${isDone ? '✅ Criterio completado' : '⬜ Criterio desmarcado'} en [${task.code || target}]: "${matchedItem?.text || subtarget}"`);
|
|
62
|
+
checkActor(response?.actor, config.userEmail);
|
|
63
|
+
console.log('');
|
|
64
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { apiRequest, resolveTask, checkActor } = require('../api');
|
|
2
|
+
|
|
3
|
+
module.exports = async function closeCommand(parsed, config) {
|
|
4
|
+
const target = parsed.positional[0] || parsed.flags.task;
|
|
5
|
+
const boardId = parsed.flags.board || config.boardId;
|
|
6
|
+
|
|
7
|
+
if (!target) {
|
|
8
|
+
console.error('❌ Falta la tarea a cerrar. Uso: huntban close <TASK_ID_O_CODIGO> [--date YYYY-MM-DD] [-m "comentario"]');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const resolved = await resolveTask(boardId, target, config);
|
|
13
|
+
|
|
14
|
+
const todayIso = new Date().toISOString().split('T')[0];
|
|
15
|
+
const closeDate = parsed.flags.date || todayIso;
|
|
16
|
+
const comment = parsed.flags.m || parsed.flags.comment || null;
|
|
17
|
+
const phase = parsed.flags.phase || 'closed-success';
|
|
18
|
+
|
|
19
|
+
const payload = {
|
|
20
|
+
taskId: resolved.id,
|
|
21
|
+
phase,
|
|
22
|
+
closedAt: closeDate
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if (parsed.flags.pipeline) {
|
|
26
|
+
payload.pipeline = parsed.flags.pipeline;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (comment) {
|
|
30
|
+
payload.comment = comment;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const endpoint = `/boards/${boardId}/connector`;
|
|
34
|
+
const response = await apiRequest(endpoint, 'PUT', payload, config);
|
|
35
|
+
|
|
36
|
+
console.log(`\n✅ Tarea [${resolved.code}] cerrada exitosamente!`);
|
|
37
|
+
console.log(`📅 Fecha Real de Cierre: ${closeDate}`);
|
|
38
|
+
console.log(`🏷️ Fase: ${phase}`);
|
|
39
|
+
if (comment) {
|
|
40
|
+
console.log(`💬 Comentario registrado: "${comment}"`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
checkActor(response?.actor, config.userEmail);
|
|
44
|
+
console.log('');
|
|
45
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { apiRequest, resolveTask, checkActor } = require('../api');
|
|
2
|
+
|
|
3
|
+
module.exports = async function commentCommand(parsed, config) {
|
|
4
|
+
const target = parsed.positional[0] || parsed.flags.task;
|
|
5
|
+
const boardId = parsed.flags.board || config.boardId;
|
|
6
|
+
const text = parsed.flags.m || parsed.flags.text || parsed.flags.comment || parsed.positional[1];
|
|
7
|
+
|
|
8
|
+
if (!target || !text) {
|
|
9
|
+
console.error('❌ Falta información. Uso: huntban comment <TASK_ID_O_CODIGO> -m "Texto del comentario..."');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const resolved = await resolveTask(boardId, target, config);
|
|
14
|
+
|
|
15
|
+
const payload = {
|
|
16
|
+
taskId: resolved.id,
|
|
17
|
+
comment: text
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const endpoint = `/boards/${boardId}/connector`;
|
|
21
|
+
const response = await apiRequest(endpoint, 'PUT', payload, config);
|
|
22
|
+
|
|
23
|
+
console.log(`\n✅ Comentario registrado en tarea [${resolved.code}]:`);
|
|
24
|
+
console.log(`💬 "${text}"`);
|
|
25
|
+
checkActor(response?.actor, config.userEmail);
|
|
26
|
+
console.log('');
|
|
27
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const { setGlobalConfig, setLocalConfig, getGlobalConfig, loadConfig, GLOBAL_CONFIG_FILE, LOCAL_CONFIG_FILE } = require('../config');
|
|
2
|
+
|
|
3
|
+
module.exports = async function configCommand(parsed) {
|
|
4
|
+
const subAction = parsed.positional[0] || 'show';
|
|
5
|
+
|
|
6
|
+
if (subAction === 'set') {
|
|
7
|
+
const updates = {};
|
|
8
|
+
if (parsed.flags.url) updates.apiUrl = parsed.flags.url;
|
|
9
|
+
if (parsed.flags.key) updates.apiKey = parsed.flags.key;
|
|
10
|
+
if (parsed.flags.secret) updates.apiSecret = parsed.flags.secret;
|
|
11
|
+
if (parsed.flags.board) updates.boardId = parsed.flags.board;
|
|
12
|
+
if (parsed.flags.email) updates.userEmail = parsed.flags.email;
|
|
13
|
+
|
|
14
|
+
if (Object.keys(updates).length === 0) {
|
|
15
|
+
console.log('⚠️ No se pasaron parámetros para actualizar.');
|
|
16
|
+
console.log(' Uso: huntban config set [--url <url>] [--board <id>] [--key <key>] [--secret <secret>] [--email <email>] [--local|--global]');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const isLocal = parsed.flags.local || (!parsed.flags.global && require('fs').existsSync(LOCAL_CONFIG_FILE));
|
|
21
|
+
if (isLocal) {
|
|
22
|
+
const next = setLocalConfig(updates);
|
|
23
|
+
console.log(`\n✅ Configuración local actualizada en ${LOCAL_CONFIG_FILE}:\n`);
|
|
24
|
+
console.log(JSON.stringify(maskConfig(next), null, 2));
|
|
25
|
+
} else {
|
|
26
|
+
try {
|
|
27
|
+
const next = setGlobalConfig(updates);
|
|
28
|
+
console.log(`\n✅ Configuración global actualizada en ${GLOBAL_CONFIG_FILE}:\n`);
|
|
29
|
+
console.log(JSON.stringify(maskConfig(next), null, 2));
|
|
30
|
+
} catch (err) {
|
|
31
|
+
// En entornos sandbox o restringidos, guardar localmente como fallback amigable
|
|
32
|
+
const next = setLocalConfig(updates);
|
|
33
|
+
console.log(`\n✅ Configuración guardada en archivo local ${LOCAL_CONFIG_FILE}:\n`);
|
|
34
|
+
console.log(JSON.stringify(maskConfig(next), null, 2));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
console.log('');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Subaction 'show' (default)
|
|
42
|
+
const currentMerged = loadConfig();
|
|
43
|
+
console.log('\n⚙️ Configuración activa de Huntban:\n');
|
|
44
|
+
console.log(JSON.stringify(maskConfig({
|
|
45
|
+
apiUrl: currentMerged.apiUrl,
|
|
46
|
+
boardId: currentMerged.boardId,
|
|
47
|
+
apiKey: currentMerged.apiKey,
|
|
48
|
+
apiSecret: currentMerged.apiSecret,
|
|
49
|
+
userEmail: currentMerged.userEmail
|
|
50
|
+
}), null, 2));
|
|
51
|
+
|
|
52
|
+
if (currentMerged._localFile) {
|
|
53
|
+
console.log(`\n📁 Archivo de proyecto activo: ${currentMerged._localFile}`);
|
|
54
|
+
}
|
|
55
|
+
console.log(`🌐 Archivo global de usuario: ${currentMerged._globalFile}`);
|
|
56
|
+
console.log('\nPara modificar valores:');
|
|
57
|
+
console.log(' huntban config set --board <id> --key <key> --secret <secret> [--local]\n');
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function maskConfig(cfg) {
|
|
61
|
+
const copy = { ...cfg };
|
|
62
|
+
if (copy.apiSecret) {
|
|
63
|
+
copy.apiSecret = copy.apiSecret.substring(0, 4) + '***' + copy.apiSecret.slice(-4);
|
|
64
|
+
}
|
|
65
|
+
return copy;
|
|
66
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const { apiRequest, getPipelines, checkActor } = require('../api');
|
|
2
|
+
|
|
3
|
+
module.exports = async function createCommand(parsed, config) {
|
|
4
|
+
const boardId = parsed.flags.board || config.boardId;
|
|
5
|
+
const name = parsed.flags.name || parsed.positional[0];
|
|
6
|
+
|
|
7
|
+
if (!boardId || !name) {
|
|
8
|
+
console.error('❌ Falta información obligatoria.');
|
|
9
|
+
console.error(' Uso: huntban create --name "Título" [--pipeline <nombre_o_id>] [--desc "..."] [--content "..."] [--checklist "A, B, C"]');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// 1. Resolver pipeline
|
|
14
|
+
let pipelineId = parsed.flags.pipeline;
|
|
15
|
+
const pipelines = await getPipelines(boardId, config);
|
|
16
|
+
|
|
17
|
+
if (!pipelineId && pipelines.length > 0) {
|
|
18
|
+
pipelineId = pipelines[0].id || pipelines[0]._id;
|
|
19
|
+
} else if (pipelineId && pipelines.length > 0) {
|
|
20
|
+
const cleanKey = String(pipelineId).trim().toLowerCase();
|
|
21
|
+
const matched = pipelines.find(p =>
|
|
22
|
+
String(p.id || p._id).toLowerCase() === cleanKey ||
|
|
23
|
+
p.name.toLowerCase().includes(cleanKey) ||
|
|
24
|
+
p.phase.toLowerCase().includes(cleanKey)
|
|
25
|
+
);
|
|
26
|
+
if (matched) {
|
|
27
|
+
pipelineId = matched.id || matched._id;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const payload = {
|
|
32
|
+
name,
|
|
33
|
+
pipelineId,
|
|
34
|
+
description: parsed.flags.desc || parsed.flags.description || '',
|
|
35
|
+
priority: parsed.flags.priority ? parseInt(parsed.flags.priority) : 3
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (parsed.flags.content) {
|
|
39
|
+
payload.content = parsed.flags.content;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (parsed.flags.checklist) {
|
|
43
|
+
const items = parsed.flags.checklist.split(',').map(t => ({ text: t.trim(), done: false }));
|
|
44
|
+
payload.checkboxes = [{ name: 'Tareas', tasks: items }];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (parsed.flags.responsible) {
|
|
48
|
+
payload.responsibleId = parsed.flags.responsible;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const endpoint = `/boards/${boardId}/connector`;
|
|
52
|
+
const response = await apiRequest(endpoint, 'POST', payload, config);
|
|
53
|
+
|
|
54
|
+
const created = response?.data || response;
|
|
55
|
+
const code = created?.code || created?.serial ? `#${created?.serial}` : 'N/A';
|
|
56
|
+
const id = created?.id || created?._id;
|
|
57
|
+
|
|
58
|
+
const appBaseUrl = (config.apiUrl || 'https://next.huntban.com')
|
|
59
|
+
.replace(/\/api\/(v1|v2)\/?$/, '')
|
|
60
|
+
.replace(/\/$/, '');
|
|
61
|
+
const webUrl = `${appBaseUrl}/${boardId}/board?taskId=${code !== 'N/A' ? code : id}`;
|
|
62
|
+
|
|
63
|
+
console.log(`\n✅ Tarea creada con éxito!`);
|
|
64
|
+
console.log(`Código: ${code}`);
|
|
65
|
+
console.log(`ID: ${id}`);
|
|
66
|
+
console.log(`Nombre: ${created?.name}`);
|
|
67
|
+
console.log(`🔗 Web: ${webUrl}`);
|
|
68
|
+
|
|
69
|
+
checkActor(response?.actor, config.userEmail);
|
|
70
|
+
console.log('');
|
|
71
|
+
};
|