baton-issue-tracker 1.4.0 → 1.6.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/package.json +2 -1
- package/source/cli.js +37 -15
- package/source/commands/approve.js +13 -5
- package/source/commands/create.js +218 -29
- package/source/commands/init.js +22 -10
- package/source/commands/list.js +30 -16
- package/source/commands/log.js +85 -0
- package/source/commands/loop.js +7 -3
- package/source/commands/next.js +20 -13
- package/source/commands/priority.js +102 -0
- package/source/commands/search.js +24 -14
- package/source/commands/status.js +47 -17
- package/source/commands/update.js +231 -41
- package/source/commands/view.js +23 -13
- package/source/util.js +61 -0
package/source/commands/view.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// list.js
|
|
2
2
|
// AI was consulted for some portions of this file.
|
|
3
3
|
// view command which allows user to view all data fields for an issue
|
|
4
|
-
// Usage: baton view <id
|
|
4
|
+
// Usage: baton view <id> [--json]
|
|
5
5
|
|
|
6
6
|
import { getIssue } from '../services/issuesService.js';
|
|
7
|
+
import { hasFlag, renderOutput, serializeIssue } from '../util.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Displays all issue fields for a given id #
|
|
@@ -11,12 +12,15 @@ import { getIssue } from '../services/issuesService.js';
|
|
|
11
12
|
* @returns {Promise<number>} The exit code: 0 is success, 1 is error.
|
|
12
13
|
*/
|
|
13
14
|
export async function run(args) {
|
|
15
|
+
const isJson = hasFlag(args, '--json');
|
|
16
|
+
const idArgs = args.filter((arg) => arg !== '--json');
|
|
17
|
+
|
|
14
18
|
// checks if id # argument is empty
|
|
15
|
-
if (
|
|
19
|
+
if (idArgs.length == 0) {
|
|
16
20
|
throw new Error(`Invalid input: Missing Issue ID.\nUsage: baton view <id>`);
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
const id =
|
|
23
|
+
const id = idArgs.join(' ');
|
|
20
24
|
|
|
21
25
|
// checks if ID # argument isn't a number
|
|
22
26
|
if (isNaN(id)) {
|
|
@@ -25,18 +29,24 @@ export async function run(args) {
|
|
|
25
29
|
|
|
26
30
|
try {
|
|
27
31
|
const issue = await getIssue(id);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const envelope = {
|
|
33
|
+
status: 'success',
|
|
34
|
+
issue: issue ? serializeIssue(issue) : null,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
renderOutput(isJson, envelope, () => {
|
|
38
|
+
if (!issue) {
|
|
39
|
+
console.log(`No issue with ID #"${issue}" was found.`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.log('');
|
|
44
|
+
Object.entries(issue).forEach(([key, value]) => {
|
|
45
|
+
console.log(`${key}: ${value}`);
|
|
46
|
+
});
|
|
47
|
+
console.log('');
|
|
37
48
|
});
|
|
38
49
|
|
|
39
|
-
console.log("");
|
|
40
50
|
return 0;
|
|
41
51
|
} catch (error) {
|
|
42
52
|
console.error("Error: Failed to retrieve data.");
|
package/source/util.js
CHANGED
|
@@ -189,6 +189,67 @@ export function reportTrackerNotReady() {
|
|
|
189
189
|
console.error('Run `baton init` first.');
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Converts DB-style enum values to lowercase snake_case for JSON output.
|
|
194
|
+
* e.g. "In-Progress" → "in_progress"
|
|
195
|
+
* @param {string | null | undefined} value
|
|
196
|
+
* @returns {string | null}
|
|
197
|
+
*/
|
|
198
|
+
function toJsonEnum(value) {
|
|
199
|
+
return value?.toLowerCase().replace(/-/g, '_') ?? null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Normalizes a DB row or Issue instance into a stable JSON-friendly shape.
|
|
204
|
+
* All commands should serialize through this before building their envelope.
|
|
205
|
+
* @param {object} issue
|
|
206
|
+
* @returns {object}
|
|
207
|
+
*/
|
|
208
|
+
export function serializeIssue(issue) {
|
|
209
|
+
return {
|
|
210
|
+
id: issue.id,
|
|
211
|
+
title: issue.title,
|
|
212
|
+
status: toJsonEnum(issue.status),
|
|
213
|
+
priority: toJsonEnum(issue.priority),
|
|
214
|
+
description: issue.description ?? null,
|
|
215
|
+
token_limit: issue.tokenLimit ?? issue.token_limit ?? null,
|
|
216
|
+
attempt_num: issue.attemptNum ?? issue.attempt_num ?? 0,
|
|
217
|
+
created_at: issue.createdAt ?? issue.created_at ?? null,
|
|
218
|
+
last_updated: issue.lastUpdated ?? issue.last_updated ?? null,
|
|
219
|
+
assignees: issue.assignees ?? null,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Centralized output renderer.
|
|
225
|
+
* If isJson is true, outputs the envelope as JSON.
|
|
226
|
+
* Otherwise, runs the human-readable callback.
|
|
227
|
+
* @param {boolean} isJson - Whether the user passed the --json flag
|
|
228
|
+
* @param {object} envelope - Structured response payload (e.g. { status, issues })
|
|
229
|
+
* @param {Function} humanOutput - Callback for human terminal styling
|
|
230
|
+
*/
|
|
231
|
+
export function renderOutput(isJson, envelope, humanOutput) {
|
|
232
|
+
if (isJson) {
|
|
233
|
+
console.log(JSON.stringify(envelope, null, 2));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
humanOutput(envelope);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Prints an error in JSON or plain text depending on output mode.
|
|
241
|
+
* @param {boolean} isJson
|
|
242
|
+
* @param {string} message
|
|
243
|
+
* @param {string} [code='ERROR']
|
|
244
|
+
*/
|
|
245
|
+
export function renderError(isJson, message, code = 'ERROR') {
|
|
246
|
+
if (isJson) {
|
|
247
|
+
console.error(JSON.stringify({ status: 'error', code, message }));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
console.error(`Error: ${message}`);
|
|
251
|
+
}
|
|
252
|
+
|
|
192
253
|
/**
|
|
193
254
|
* Configuration for table column widths.
|
|
194
255
|
*/
|