@falldownthesystem/devtool 0.2.0 → 0.3.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@falldownthesystem/devtool",
3
- "version": "0.2.0",
4
- "description": "CLI for Bitbucket PRs, Jira tickets, and Confluence pages",
3
+ "version": "0.3.0",
4
+ "description": "CLI for Bitbucket PRs, Jira tickets, Confluence pages, and Service Desk tickets",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "dev": "src/index.js"
@@ -0,0 +1,72 @@
1
+ import { get } from '../config/store.js';
2
+
3
+ function baseUrl() {
4
+ return get('serviceDesk.baseUrl');
5
+ }
6
+
7
+ function authHeader() {
8
+ const email = get('serviceDesk.email');
9
+ const token = get('serviceDesk.token');
10
+ return 'Basic ' + Buffer.from(`${email}:${token}`).toString('base64');
11
+ }
12
+
13
+ async function request(path, params = {}) {
14
+ const url = new URL(path.startsWith('http') ? path : `${baseUrl()}${path}`);
15
+ for (const [k, v] of Object.entries(params)) {
16
+ if (v !== undefined && v !== null && v !== '') url.searchParams.set(k, v);
17
+ }
18
+
19
+ const res = await fetch(url, {
20
+ headers: {
21
+ 'Authorization': authHeader(),
22
+ 'Accept': 'application/json',
23
+ },
24
+ });
25
+
26
+ if (!res.ok) {
27
+ const err = new Error(`Service Desk API error: ${res.status} ${res.statusText}`);
28
+ err.status = res.status;
29
+ err.url = url.toString();
30
+ throw err;
31
+ }
32
+
33
+ return res.json();
34
+ }
35
+
36
+ export async function getIssue(issueKey) {
37
+ return request(`/rest/api/3/issue/${encodeURIComponent(issueKey)}`, {
38
+ expand: 'renderedFields',
39
+ });
40
+ }
41
+
42
+ export async function getIssueComments(issueKey) {
43
+ const data = await request(`/rest/api/3/issue/${encodeURIComponent(issueKey)}/comment`, {
44
+ orderBy: 'created',
45
+ maxResults: 100,
46
+ });
47
+ return data.comments || [];
48
+ }
49
+
50
+ export async function searchIssues(jql, maxResults = 50, nextPageToken = '') {
51
+ const fields = 'summary,status,assignee,priority,updated,issuetype,reporter,customfield_10010';
52
+ const data = await request('/rest/api/3/search/jql', {
53
+ jql,
54
+ fields,
55
+ maxResults,
56
+ nextPageToken,
57
+ });
58
+ return {
59
+ issues: data.issues || [],
60
+ nextPageToken: data.nextPageToken || null,
61
+ isLast: data.isLast !== false,
62
+ maxResults,
63
+ };
64
+ }
65
+
66
+ export async function getMyIssues() {
67
+ const project = get('serviceDesk.defaultProject');
68
+ const jql = project
69
+ ? `project = ${project} AND assignee = currentUser() AND statusCategory != Done ORDER BY updated DESC`
70
+ : `assignee = currentUser() AND statusCategory != Done ORDER BY updated DESC`;
71
+ return searchIssues(jql);
72
+ }
@@ -0,0 +1,95 @@
1
+ import { Command } from 'commander';
2
+ import {
3
+ getIssue,
4
+ getIssueComments,
5
+ searchIssues,
6
+ getMyIssues,
7
+ } from '../clients/serviceDesk.js';
8
+ import {
9
+ formatIssueView, formatIssueComments, formatIssueSearch,
10
+ plainIssueView, plainIssueComments, plainIssueSearch,
11
+ curateIssueJson, curateCommentsJson, curateSearchJson,
12
+ } from '../formatters/serviceDesk.js';
13
+ import { spinner } from '../utils/output.js';
14
+ import { handleError } from '../utils/errors.js';
15
+ import { getOutputMode, outputJson } from '../utils/mode.js';
16
+
17
+ const sd = new Command('sd')
18
+ .alias('servicedesk')
19
+ .description('Jira Service Desk Cloud tickets');
20
+
21
+ sd.command('view <key>')
22
+ .alias('read')
23
+ .description('View ticket details')
24
+ .action(async function (key) {
25
+ const mode = getOutputMode(this);
26
+ const s = mode === 'rich' ? spinner(`Fetching ${key}...`).start() : null;
27
+ try {
28
+ const issue = await getIssue(key);
29
+ if (s) s.success({ text: key });
30
+ if (mode === 'json') outputJson(curateIssueJson(issue));
31
+ else if (mode === 'plain') plainIssueView(issue);
32
+ else formatIssueView(issue);
33
+ } catch (err) {
34
+ if (s) s.error({ text: `Failed to fetch ${key}` });
35
+ handleError(err, `sd view ${key}`);
36
+ }
37
+ });
38
+
39
+ sd.command('comments <key>')
40
+ .description('List ticket comments')
41
+ .action(async function (key) {
42
+ const mode = getOutputMode(this);
43
+ const s = mode === 'rich' ? spinner(`Fetching comments for ${key}...`).start() : null;
44
+ try {
45
+ const comments = await getIssueComments(key);
46
+ if (s) s.success({ text: `${comments.length} comment(s)` });
47
+ if (mode === 'json') outputJson(curateCommentsJson(comments));
48
+ else if (mode === 'plain') plainIssueComments(comments);
49
+ else formatIssueComments(comments);
50
+ } catch (err) {
51
+ if (s) s.error({ text: `Failed to fetch comments for ${key}` });
52
+ handleError(err, `sd comments ${key}`);
53
+ }
54
+ });
55
+
56
+ sd.command('search <jql>')
57
+ .alias('find')
58
+ .description('Search Service Desk tickets with JQL')
59
+ .option('-n, --per-page <number>', 'Results per page', '20')
60
+ .option('--next <token>', 'Continuation token from a previous page')
61
+ .action(async function (jql, opts) {
62
+ const mode = getOutputMode(this);
63
+ const perPage = parseInt(opts.perPage, 10);
64
+ const s = mode === 'rich' ? spinner('Searching...').start() : null;
65
+ try {
66
+ const result = await searchIssues(jql, perPage, opts.next || '');
67
+ if (s) s.success({ text: `${result.issues.length} issue(s) returned` });
68
+ if (mode === 'json') outputJson(curateSearchJson(result));
69
+ else if (mode === 'plain') plainIssueSearch(result);
70
+ else formatIssueSearch(result);
71
+ } catch (err) {
72
+ if (s) s.error({ text: 'Search failed' });
73
+ handleError(err, `sd search "${jql}"`);
74
+ }
75
+ });
76
+
77
+ sd.command('mine')
78
+ .alias('my')
79
+ .description('Show my open Service Desk tickets')
80
+ .action(async function () {
81
+ const mode = getOutputMode(this);
82
+ const s = mode === 'rich' ? spinner('Fetching my tickets...').start() : null;
83
+ try {
84
+ const result = await getMyIssues();
85
+ if (s) s.success({ text: `${result.issues.length} ticket(s)` });
86
+ if (mode === 'json') outputJson(curateSearchJson(result));
87
+ else if (mode === 'plain') plainIssueSearch(result);
88
+ else formatIssueSearch(result);
89
+ } catch (err) {
90
+ if (s) s.error({ text: 'Failed to fetch tickets' });
91
+ handleError(err, 'sd my tickets');
92
+ }
93
+ });
94
+
95
+ export default sd;
@@ -29,6 +29,15 @@ const schema = {
29
29
  defaultSpace: { type: 'string' },
30
30
  },
31
31
  },
32
+ serviceDesk: {
33
+ type: 'object',
34
+ properties: {
35
+ baseUrl: { type: 'string' },
36
+ email: { type: 'string' },
37
+ token: { type: 'string' },
38
+ defaultProject: { type: 'string' },
39
+ },
40
+ },
32
41
  };
33
42
 
34
43
  const config = new Conf({
@@ -38,6 +47,7 @@ const config = new Conf({
38
47
  bitbucket: { workspace: '', defaultRepo: '', email: '', token: '' },
39
48
  jira: { baseUrl: '', token: '', defaultProject: '' },
40
49
  confluence: { baseUrl: '', email: '', token: '', defaultSpace: '' },
50
+ serviceDesk: { baseUrl: '', email: '', token: '', defaultProject: '' },
41
51
  },
42
52
  });
43
53
 
@@ -146,9 +156,52 @@ export async function runSetup() {
146
156
  },
147
157
  });
148
158
 
159
+ const reuseConfluenceCreds = confluence.email && confluence.token
160
+ ? await p.confirm({
161
+ message: 'Reuse Confluence email/token for Jira Service Desk Cloud?',
162
+ initialValue: true,
163
+ })
164
+ : false;
165
+
166
+ if (p.isCancel(reuseConfluenceCreds)) {
167
+ p.cancel('Setup cancelled.');
168
+ process.exit(0);
169
+ }
170
+
171
+ const serviceDesk = await p.group({
172
+ baseUrl: () => p.text({
173
+ message: 'Jira Service Desk Cloud base URL (use canonical *.atlassian.net, not a vanity domain)',
174
+ placeholder: 'https://company.atlassian.net',
175
+ initialValue: config.get('serviceDesk.baseUrl') || '',
176
+ }),
177
+ email: () => reuseConfluenceCreds
178
+ ? Promise.resolve(confluence.email)
179
+ : p.text({
180
+ message: 'Service Desk account email',
181
+ placeholder: 'you@company.com',
182
+ initialValue: config.get('serviceDesk.email') || '',
183
+ }),
184
+ token: () => reuseConfluenceCreds
185
+ ? Promise.resolve(confluence.token)
186
+ : p.password({
187
+ message: 'Service Desk API token',
188
+ }),
189
+ defaultProject: () => p.text({
190
+ message: 'Service Desk default project key',
191
+ placeholder: 'TUKI',
192
+ initialValue: config.get('serviceDesk.defaultProject') || '',
193
+ }),
194
+ }, {
195
+ onCancel: () => {
196
+ p.cancel('Setup cancelled.');
197
+ process.exit(0);
198
+ },
199
+ });
200
+
149
201
  config.set('bitbucket', bb);
150
202
  config.set('jira', jira);
151
203
  config.set('confluence', confluence);
204
+ config.set('serviceDesk', serviceDesk);
152
205
 
153
206
  p.outro(pc.green('Configuration saved!'));
154
207
  }
@@ -0,0 +1,222 @@
1
+ import { table, heading, field, divider, pc } from '../utils/output.js';
2
+
3
+ function statusColor(name) {
4
+ if (!name) return pc.dim('Unknown');
5
+ const lower = name.toLowerCase();
6
+ if (lower === 'done' || lower === 'closed' || lower === 'resolved') return pc.green(name);
7
+ if (lower === 'in progress' || lower === 'in review' || lower === 'waiting for support') return pc.blue(name);
8
+ if (lower === 'to do' || lower === 'open' || lower === 'backlog' || lower === 'waiting for customer') return pc.yellow(name);
9
+ return name;
10
+ }
11
+
12
+ function priorityColor(name) {
13
+ if (!name) return pc.dim('None');
14
+ const lower = name.toLowerCase();
15
+ if (lower === 'highest' || lower === 'blocker') return pc.red(pc.bold(name));
16
+ if (lower === 'high' || lower === 'critical') return pc.red(name);
17
+ if (lower === 'low' || lower === 'minor' || lower === 'lowest' || lower === 'trivial') return pc.dim(name);
18
+ return name;
19
+ }
20
+
21
+ function relativeTime(dateStr) {
22
+ if (!dateStr) return '';
23
+ const diff = Date.now() - new Date(dateStr).getTime();
24
+ const mins = Math.floor(diff / 60000);
25
+ if (mins < 60) return `${mins}m ago`;
26
+ const hours = Math.floor(mins / 60);
27
+ if (hours < 24) return `${hours}h ago`;
28
+ const days = Math.floor(hours / 24);
29
+ if (days < 30) return `${days}d ago`;
30
+ return new Date(dateStr).toLocaleDateString();
31
+ }
32
+
33
+ function adfToText(node) {
34
+ if (!node) return '';
35
+ if (typeof node === 'string') return node;
36
+ if (Array.isArray(node)) return node.map(adfToText).join('');
37
+ if (node.type === 'text') return node.text || '';
38
+ if (node.type === 'hardBreak') return '\n';
39
+ const inner = adfToText(node.content);
40
+ const blockTypes = new Set(['paragraph', 'heading', 'bulletList', 'orderedList', 'listItem', 'codeBlock', 'blockquote']);
41
+ if (blockTypes.has(node.type)) return inner + '\n';
42
+ return inner;
43
+ }
44
+
45
+ function descriptionText(field) {
46
+ if (!field) return '';
47
+ if (typeof field === 'string') return field;
48
+ return adfToText(field).trim();
49
+ }
50
+
51
+ function requestType(fields) {
52
+ for (const key of Object.keys(fields)) {
53
+ if (!key.startsWith('customfield_')) continue;
54
+ const val = fields[key];
55
+ if (val && typeof val === 'object' && val.requestType?.name) {
56
+ return val.requestType.name;
57
+ }
58
+ }
59
+ return null;
60
+ }
61
+
62
+ // --- JSON curators ---
63
+
64
+ export function curateIssueJson(issue) {
65
+ const f = issue.fields;
66
+ return {
67
+ key: issue.key,
68
+ summary: f.summary,
69
+ status: f.status?.name || null,
70
+ priority: f.priority?.name || null,
71
+ type: f.issuetype?.name || null,
72
+ requestType: requestType(f),
73
+ assignee: f.assignee?.displayName || null,
74
+ reporter: f.reporter?.displayName || null,
75
+ labels: f.labels || [],
76
+ components: (f.components || []).map((c) => c.name),
77
+ created: f.created,
78
+ updated: f.updated,
79
+ description: descriptionText(f.description),
80
+ };
81
+ }
82
+
83
+ export function curateCommentsJson(comments) {
84
+ return comments.map((c) => ({
85
+ author: c.author?.displayName || null,
86
+ date: c.created,
87
+ body: descriptionText(c.body),
88
+ }));
89
+ }
90
+
91
+ export function curateSearchJson(result) {
92
+ return {
93
+ nextPageToken: result.nextPageToken,
94
+ isLast: result.isLast,
95
+ issues: result.issues.map((issue) => ({
96
+ key: issue.key,
97
+ summary: issue.fields.summary,
98
+ status: issue.fields.status?.name || null,
99
+ assignee: issue.fields.assignee?.displayName || null,
100
+ priority: issue.fields.priority?.name || null,
101
+ updated: issue.fields.updated,
102
+ })),
103
+ };
104
+ }
105
+
106
+ // --- Plain formatters ---
107
+
108
+ export function plainIssueView(issue) {
109
+ const f = issue.fields;
110
+ console.log(`${issue.key} ${f.summary}`);
111
+ console.log(`Status: ${f.status?.name || 'Unknown'}`);
112
+ console.log(`Priority: ${f.priority?.name || 'None'}`);
113
+ console.log(`Type: ${f.issuetype?.name || 'Unknown'}`);
114
+ const rt = requestType(f);
115
+ if (rt) console.log(`Request Type: ${rt}`);
116
+ console.log(`Assignee: ${f.assignee?.displayName || 'Unassigned'}`);
117
+ console.log(`Reporter: ${f.reporter?.displayName || 'Unknown'}`);
118
+ if (f.labels?.length > 0) console.log(`Labels: ${f.labels.join(', ')}`);
119
+ if (f.components?.length > 0) console.log(`Components: ${f.components.map((c) => c.name).join(', ')}`);
120
+ console.log(`Created: ${f.created}`);
121
+ console.log(`Updated: ${f.updated}`);
122
+ const desc = descriptionText(f.description);
123
+ if (desc) console.log(`Description:\n${desc}`);
124
+ }
125
+
126
+ export function plainIssueComments(comments) {
127
+ if (comments.length === 0) { console.log('No comments.'); return; }
128
+ for (const c of comments) {
129
+ console.log(`${c.author?.displayName || 'Unknown'} (${relativeTime(c.created)}): ${descriptionText(c.body)}`);
130
+ }
131
+ }
132
+
133
+ export function plainIssueSearch(result) {
134
+ if (result.issues.length === 0) { console.log('No issues found.'); return; }
135
+ for (const issue of result.issues) {
136
+ const f = issue.fields;
137
+ console.log(`${issue.key} [${f.status?.name}] "${f.summary}" - ${f.assignee?.displayName || 'Unassigned'} (${f.priority?.name}, ${relativeTime(f.updated)})`);
138
+ }
139
+ if (!result.isLast && result.nextPageToken) {
140
+ console.log(`More results available (nextPageToken: ${result.nextPageToken})`);
141
+ }
142
+ }
143
+
144
+ // --- Rich formatters ---
145
+
146
+ export function formatIssueView(issue) {
147
+ const f = issue.fields;
148
+
149
+ heading(`${issue.key} ${f.summary}`);
150
+ divider();
151
+ field('Status', statusColor(f.status?.name));
152
+ field('Priority', priorityColor(f.priority?.name));
153
+ field('Type', f.issuetype?.name);
154
+ const rt = requestType(f);
155
+ if (rt) field('Request Type', rt);
156
+ field('Assignee', f.assignee?.displayName || pc.dim('Unassigned'));
157
+ field('Reporter', f.reporter?.displayName);
158
+ field('Labels', f.labels?.length > 0 ? f.labels.join(', ') : null);
159
+ field('Components', f.components?.map((c) => c.name).join(', ') || null);
160
+ field('Created', new Date(f.created).toLocaleString());
161
+ field('Updated', new Date(f.updated).toLocaleString());
162
+
163
+ const desc = descriptionText(f.description);
164
+ if (desc) {
165
+ heading('Description');
166
+ const lines = desc.split('\n');
167
+ const truncated = lines.slice(0, 30);
168
+ for (const line of truncated) {
169
+ console.log(` ${line}`);
170
+ }
171
+ if (lines.length > 30) {
172
+ console.log(pc.dim(` ... (${lines.length - 30} more lines)`));
173
+ }
174
+ }
175
+
176
+ console.log('');
177
+ }
178
+
179
+ export function formatIssueComments(comments) {
180
+ if (comments.length === 0) {
181
+ console.log(pc.dim(' No comments.'));
182
+ return;
183
+ }
184
+
185
+ for (const c of comments) {
186
+ console.log(`\n ${pc.bold(c.author?.displayName || 'Unknown')} ${pc.dim(relativeTime(c.created))}`);
187
+ const body = descriptionText(c.body);
188
+ if (body) {
189
+ for (const line of body.split('\n')) {
190
+ console.log(` ${line}`);
191
+ }
192
+ }
193
+ }
194
+ console.log('');
195
+ }
196
+
197
+ export function formatIssueSearch(result) {
198
+ const { issues } = result;
199
+
200
+ if (issues.length === 0) {
201
+ console.log(pc.dim(' No issues found.'));
202
+ return;
203
+ }
204
+
205
+ const rows = issues.map((issue) => [
206
+ pc.bold(issue.key),
207
+ (issue.fields.summary || '').length > 55
208
+ ? issue.fields.summary.slice(0, 52) + '...'
209
+ : issue.fields.summary || '',
210
+ statusColor(issue.fields.status?.name),
211
+ issue.fields.assignee?.displayName || pc.dim('Unassigned'),
212
+ priorityColor(issue.fields.priority?.name),
213
+ relativeTime(issue.fields.updated),
214
+ ]);
215
+
216
+ console.log(table(['Key', 'Summary', 'Status', 'Assignee', 'Priority', 'Updated'], rows));
217
+
218
+ if (!result.isLast && result.nextPageToken) {
219
+ console.log(pc.dim(` More results available — pass --next ${result.nextPageToken} to continue`));
220
+ }
221
+ console.log('');
222
+ }
package/src/index.js CHANGED
@@ -6,13 +6,14 @@ import configCmd from './commands/config.js';
6
6
  import prCmd from './commands/pr.js';
7
7
  import jiraCmd from './commands/jira.js';
8
8
  import confluenceCmd from './commands/confluence.js';
9
+ import sdCmd from './commands/sd.js';
9
10
 
10
11
  const program = new Command();
11
12
 
12
13
  program
13
14
  .name('dev')
14
- .description('CLI for Bitbucket PRs, Jira tickets, and Confluence pages')
15
- .version('0.2.0')
15
+ .description('CLI for Bitbucket PRs, Jira tickets, Confluence pages, and Service Desk tickets')
16
+ .version('0.3.0')
16
17
  .option('--json', 'Output raw JSON')
17
18
  .option('--plain', 'Output compact plain text (no tables, no colors)');
18
19
 
@@ -20,6 +21,7 @@ program.addCommand(configCmd);
20
21
  program.addCommand(prCmd);
21
22
  program.addCommand(jiraCmd);
22
23
  program.addCommand(confluenceCmd);
24
+ program.addCommand(sdCmd);
23
25
 
24
26
  program.hook('preAction', async (thisCommand, actionCommand) => {
25
27
  const cmdChain = [];