huntban-cli 0.0.0-stage → 1.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 +212 -2
- 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 +35 -4
- package/templates/SKILL.md +191 -0
package/README.md
CHANGED
|
@@ -1,3 +1,213 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Huntban CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Herramienta de terminal oficial para automatizar tableros, tareas y flujos de trabajo en **Huntban**, diseñada tanto para desarrolladores como para agentes autónomos de IA como **Antigravity**.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Instalación
|
|
8
|
+
|
|
9
|
+
### Opción A: Instalación Global vía npm
|
|
10
|
+
Para utilizar el comando `huntban` en cualquier terminal de tu sistema:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -g huntban-cli
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Opción B: Instalación Local en Desarrollo (`npm link`)
|
|
17
|
+
Si estás trabajando sobre el código fuente del CLI en local:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cd huntban-cli
|
|
21
|
+
npm link
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Opción C: Ejecución sin instalación con `npx`
|
|
25
|
+
Puedes ejecutar comandos directamente sin instalarlo globalmente:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx huntban-cli <comando> [argumentos]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Verifica la instalación:
|
|
32
|
+
```bash
|
|
33
|
+
huntban --version
|
|
34
|
+
huntban --help
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 2. Guía para Publicar el Paquete en npm
|
|
40
|
+
|
|
41
|
+
Si eres mantenedor del proyecto y deseas publicar una nueva versión en el registro de npm:
|
|
42
|
+
|
|
43
|
+
### Paso 2.1: Probar el empaquetado (Dry Run)
|
|
44
|
+
Verifica qué archivos serán incluidos en el paquete antes de subirlo:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm pack --dry-run
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Asegúrate de que solo se incluyan las carpetas `bin/`, `lib/`, `templates/` y la documentación `README.md`.
|
|
51
|
+
|
|
52
|
+
### Paso 2.2: Iniciar sesión en npm
|
|
53
|
+
Si no has iniciado sesión en tu máquina:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm login
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Paso 2.3: Incrementar la versión
|
|
60
|
+
Utiliza el estándar de versionado semántico (SemVer):
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Corrección de errores o parches (1.0.0 -> 1.0.1)
|
|
64
|
+
npm version patch
|
|
65
|
+
|
|
66
|
+
# Nuevas características compatibles (1.0.0 -> 1.1.0)
|
|
67
|
+
npm version minor
|
|
68
|
+
|
|
69
|
+
# Cambios mayores incompatibles (1.0.0 -> 2.0.0)
|
|
70
|
+
npm version major
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Paso 2.4: Publicar
|
|
74
|
+
Publica el paquete con visibilidad pública:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm publish --access public
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 3. Vincular un Repositorio a Huntban (`huntban attach`)
|
|
83
|
+
|
|
84
|
+
Puedes conectar cualquier repositorio de código a su tablero correspondiente en Huntban con un solo comando:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
huntban attach
|
|
88
|
+
# o también:
|
|
89
|
+
huntban init
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### ¿Qué realiza automáticamente?
|
|
93
|
+
1. **Instala el skill en el proyecto**: Crea `.agents/skills/huntban-connector/SKILL.md` para que Antigravity comprenda todos los flujos del tablero en este repositorio.
|
|
94
|
+
2. **Asistente de credenciales**: Te solicita interactivamente los datos de tu tablero y genera `.huntban.json`.
|
|
95
|
+
3. **Protección `.gitignore`**: Agrega `.huntban.json` al `.gitignore` para no exponer secretos en git.
|
|
96
|
+
4. **Prueba de conexión**: Valida la conexión y lista las columnas activas.
|
|
97
|
+
|
|
98
|
+
### Parámetros en una sola línea (para CI/CD o scripts):
|
|
99
|
+
```bash
|
|
100
|
+
huntban attach \
|
|
101
|
+
--url https://next.huntban.com/api/v2 \
|
|
102
|
+
--board <ID_DEL_TABLERO> \
|
|
103
|
+
--key <API_KEY> \
|
|
104
|
+
--secret <API_SECRET> \
|
|
105
|
+
--email tu-correo@empresa.com
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Instalación Global de la Habilidad para Antigravity:
|
|
109
|
+
Para habilitar el skill de Antigravity en **todos** los repositorios de tu máquina de forma permanente:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
huntban attach --global
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 4. Configuración y Credenciales
|
|
118
|
+
|
|
119
|
+
### Dónde obtener las credenciales en Huntban:
|
|
120
|
+
1. Abre tu tablero en la web de Huntban.
|
|
121
|
+
2. Haz clic en el ícono de **Configuración del Tablero (⚙️)** en la cabecera.
|
|
122
|
+
3. Ve a la pestaña **Conector / Webhooks**.
|
|
123
|
+
4. Copia:
|
|
124
|
+
- **URL de la API**: `https://next.huntban.com/api/v2` (o tu servidor local).
|
|
125
|
+
- **ID del Tablero**: Identificador de 24 caracteres.
|
|
126
|
+
- **API Key**: Comienza con `hb_pk_...`.
|
|
127
|
+
- **API Secret**: Comienza con `hb_sk_...`.
|
|
128
|
+
- **Tu Email**: Para atribución de autor en cambios y comentarios.
|
|
129
|
+
|
|
130
|
+
### Orden de Precedencia de Configuración:
|
|
131
|
+
1. **Variables de Entorno**: `HUNTBAN_API_URL`, `HUNTBAN_BOARD_ID`, `HUNTBAN_API_KEY`, `HUNTBAN_API_SECRET`, `HUNTBAN_USER_EMAIL`.
|
|
132
|
+
2. **Archivo local del proyecto**: `.huntban.json` en la raíz actual.
|
|
133
|
+
3. **Archivo global del usuario**: `~/.huntban/config.json`.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 5. Referencia de Comandos y Ejemplos
|
|
138
|
+
|
|
139
|
+
Todos los comandos soportan tanto el **código amigable de la tarea** (ej: `TSTT-28`, `BLBX-55`, `#28`) como el `ObjectId` hexadecimal.
|
|
140
|
+
|
|
141
|
+
### 5.1 Consultar columnas del tablero
|
|
142
|
+
```bash
|
|
143
|
+
huntban cols
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 5.2 Listar tareas
|
|
147
|
+
```bash
|
|
148
|
+
huntban ls
|
|
149
|
+
huntban ls --limit 10
|
|
150
|
+
huntban ls --search "Auth"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 5.3 Ver detalle completo de una tarea
|
|
154
|
+
Muestra objetivo, especificaciones técnicas completas en Markdown, checklist con IDs, comentarios y URL directa:
|
|
155
|
+
```bash
|
|
156
|
+
huntban get TSTT-28
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 5.4 Mover a columna específica
|
|
160
|
+
Búsqueda inteligente por nombre de columna:
|
|
161
|
+
```bash
|
|
162
|
+
huntban to TSTT-28 "Haciendo"
|
|
163
|
+
huntban to TSTT-28 qa -m "Listo para pruebas"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 5.5 Avanzar a la siguiente columna
|
|
167
|
+
Avanza automáticamente según el orden definido en el tablero:
|
|
168
|
+
```bash
|
|
169
|
+
huntban nx TSTT-28 -m "Avanzando de etapa"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 5.6 Marcar Criterios de Aceptación / Checklists
|
|
173
|
+
Marca subtareas completadas por su ID o por su texto:
|
|
174
|
+
```bash
|
|
175
|
+
huntban check TSTT-28 "Crear componente"
|
|
176
|
+
huntban check TSTT-28 6b073757fd4fc45094357faf
|
|
177
|
+
|
|
178
|
+
# Desmarcar criterio:
|
|
179
|
+
huntban check TSTT-28 "Crear componente" --undo
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 5.7 Enviar a Revisión / QA
|
|
183
|
+
Pasa la tarea a la etapa de revisión adjuntando informe para el revisor o Tech Lead:
|
|
184
|
+
```bash
|
|
185
|
+
huntban review TSTT-28 -m "Rama feature/login lista para revisión"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 5.8 Cierre definitivo con Sinceramiento de Fecha
|
|
189
|
+
Cierra la tarea y registra la fecha real de ejecución para no descalibrar el diagrama de Gantt:
|
|
190
|
+
```bash
|
|
191
|
+
huntban cl TSTT-28 --date 2026-11-25 -m "Aprobado en producción"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### 5.9 Agregar comentarios
|
|
195
|
+
Deja comentarios en el hilo de la tarea con atribución de autor:
|
|
196
|
+
```bash
|
|
197
|
+
huntban msg TSTT-28 -m "Progreso al 70%, auth terminada"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### 5.10 Abrir directamente en el navegador
|
|
201
|
+
Lanza la aplicación web con el modal de la tarea abierto en macOS, Linux o Windows:
|
|
202
|
+
```bash
|
|
203
|
+
huntban open TSTT-28
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### 5.11 Crear una nueva tarea
|
|
207
|
+
```bash
|
|
208
|
+
huntban create \
|
|
209
|
+
--name "Nueva Tarea" \
|
|
210
|
+
--desc "Objetivo breve" \
|
|
211
|
+
--content "## Requerimientos técnicos" \
|
|
212
|
+
--checklist "Paso 1, Paso 2, Paso 3"
|
|
213
|
+
```
|
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
|
+
};
|