baton-issue-tracker 1.7.0 → 1.8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baton-issue-tracker",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "A CLI issue tracker for AI agents",
5
5
  "type": "module",
6
6
  "bin": {
package/source/cli.js CHANGED
@@ -24,6 +24,7 @@ import { run as runSearch } from './commands/search.js';
24
24
  import { run as runList } from './commands/list.js';
25
25
  import { run as runCreate } from './commands/create.js'
26
26
  import { run as runUpdate } from './commands/update.js';
27
+ import { run as runDelete } from './commands/delete.js';
27
28
  import { run as runPriority } from './commands/priority.js';
28
29
  import { run as runLog } from './commands/log.js';
29
30
  import { run as runRegister } from './commands/register.js';
@@ -48,6 +49,7 @@ Commands:
48
49
  approve Move an issue from in-review to closed
49
50
  priority Set an issue's priority level
50
51
  update Updates an issue's specified fields
52
+ delete Deletes an issue
51
53
  log Show activity history for an issue
52
54
 
53
55
  Options:
@@ -83,6 +85,7 @@ Options:
83
85
  update --status <s> open | in-progress | closed
84
86
  update --priority <level> low | medium | high
85
87
  update --json Output as JSON (for AI agents)
88
+ delete <id> [--yes]
86
89
  log <id> [--json]
87
90
 
88
91
  Examples:
@@ -138,6 +141,7 @@ async function main() {
138
141
  priority: () => runPriority(args),
139
142
  create: () => runCreate(args),
140
143
  update: () => runUpdate(args),
144
+ delete: () => runDelete(args),
141
145
  log: () => runLog(args),
142
146
  };
143
147
 
@@ -0,0 +1,99 @@
1
+ // delete.js
2
+ // supports deleting an issue.
3
+ //
4
+ // AI was used to modify this file to support JSON outputs.
5
+ //
6
+ // Usage:
7
+ // baton delete <id> [--yes] [--json]
8
+ //
9
+ // Options:
10
+ // --yes Skip confirmation prompt
11
+ // --json Output in JSON format
12
+ // -h, --help Show this help
13
+ //
14
+ // Examples:
15
+ // baton delete 4
16
+ // baton delete 4 --yes
17
+
18
+ import { deleteIssue, getIssue } from '../services/issuesService.js';
19
+ import { hasFlag, wantsHelp, renderOutput, renderError } from '../util.js';
20
+ import { confirm } from '@inquirer/prompts';
21
+
22
+ const USAGE = "Usage: baton delete <id> [options]\n\nOptions:\n --yes Skip confirmation prompt\n --json Output in JSON format\n -h, --help Show this help";
23
+
24
+ /**
25
+ * Deletes an issue for a specified ID.
26
+ *
27
+ * @param {string[]} args - The command line arguments
28
+ * @returns {Promise<number>} The exit code: 0 is success, 1 is error.
29
+ */
30
+ export async function run(args) {
31
+ const isJson = hasFlag(args, '--json');
32
+
33
+ // (0) Help check
34
+ if (wantsHelp(args)) {
35
+ console.log(USAGE);
36
+ return 0;
37
+ }
38
+
39
+ // (1) Parse arguments
40
+ const idArgs = args.filter(arg => !arg.startsWith('-'));
41
+ if (idArgs.length === 0) {
42
+ renderError(isJson, `No ID provided.\n${USAGE}`, 'MISSING_ID');
43
+ return 1;
44
+ }
45
+
46
+ const id = Number(idArgs[0]);
47
+ if (!Number.isInteger(id)) {
48
+ renderError(isJson, `Invalid ID "${idArgs[0]}". ID must be an integer.`, 'INVALID_ID');
49
+ return 1;
50
+ }
51
+
52
+ const isYes = hasFlag(args, "--yes");
53
+
54
+ try {
55
+ // (2) Check if issue exists before confirming
56
+ try {
57
+ await getIssue(id);
58
+ } catch (error) {
59
+ if (error.message.includes("not found")) {
60
+ renderError(isJson, error.message, 'NOT_FOUND');
61
+ } else {
62
+ renderError(isJson, error.message);
63
+ }
64
+ return 1;
65
+ }
66
+
67
+ // (3) Confirmation prompt
68
+ let confirmed = isYes;
69
+ if (!confirmed && !isJson) { // Only prompt if not JSON and not --yes
70
+ try {
71
+ confirmed = await confirm({ message: `Are you sure you want to delete issue #${id}?`, default: false });
72
+ } catch {
73
+ return 1;
74
+ }
75
+ } else if (!confirmed && isJson) {
76
+ // In JSON mode, do not prompt. If --yes is missing, we fail or assume no.
77
+ renderError(isJson, "Confirmation required. Use --yes to confirm deletion in JSON mode.", 'CONFIRMATION_REQUIRED');
78
+ return 1;
79
+ }
80
+
81
+ if (!confirmed) {
82
+ console.log("Deletion cancelled.");
83
+ return 0;
84
+ }
85
+
86
+ // (4) Execution
87
+ await deleteIssue(id);
88
+
89
+ const envelope = { status: 'success', id: id, message: `Issue #${id} deleted successfully.` };
90
+ renderOutput(isJson, envelope, () => {
91
+ console.log(`Issue #${id} deleted successfully.`);
92
+ });
93
+
94
+ return 0;
95
+ } catch (error) {
96
+ renderError(isJson, error.message);
97
+ return 1;
98
+ }
99
+ }