@falldownthesystem/devtool 0.4.0 → 0.4.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/LICENSE +15 -0
- package/README.md +1 -2
- package/package.json +22 -4
- package/src/clients/confluence.js +12 -8
- package/src/clients/serviceDesk.js +181 -119
- package/src/commands/config.js +10 -27
- package/src/commands/sd.js +135 -135
- package/src/config/store.js +20 -16
- package/src/formatters/serviceDesk.js +267 -267
- package/src/index.js +1 -1
- package/CLAUDE.md +0 -54
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 FallDownTheSystem
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -5,8 +5,7 @@ A terminal-first CLI for working with Bitbucket PRs, Jira tickets, and Confluenc
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install
|
|
9
|
-
npm link
|
|
8
|
+
npm install -g @falldownthesystem/devtool
|
|
10
9
|
```
|
|
11
10
|
|
|
12
11
|
This gives you the `dev` command globally. On first run, it'll walk you through connecting your Bitbucket, Jira, and Confluence accounts.
|
package/package.json
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@falldownthesystem/devtool",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
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"
|
|
8
8
|
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src/"
|
|
11
|
+
],
|
|
9
12
|
"scripts": {
|
|
10
|
-
"start": "node src/index.js"
|
|
13
|
+
"start": "node src/index.js",
|
|
14
|
+
"test": "node --test test/config.test.js test/confluence.test.js test/service-desk.test.js"
|
|
11
15
|
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
|
|
16
|
+
"keywords": [
|
|
17
|
+
"cli",
|
|
18
|
+
"bitbucket",
|
|
19
|
+
"jira",
|
|
20
|
+
"confluence",
|
|
21
|
+
"pull-request",
|
|
22
|
+
"devtools"
|
|
23
|
+
],
|
|
24
|
+
"author": "FallDownTheSystem",
|
|
14
25
|
"license": "ISC",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/FallDownTheSystem/devtool.git"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
15
33
|
"dependencies": {
|
|
16
34
|
"@clack/prompts": "^1.0.0",
|
|
17
35
|
"cli-table3": "^0.6.5",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { get } from '../config/store.js';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
return
|
|
3
|
+
function apiUrl(path) {
|
|
4
|
+
return new URL(`/wiki${path}`, get('confluence.baseUrl'));
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
function authHeader() {
|
|
@@ -10,8 +10,10 @@ function authHeader() {
|
|
|
10
10
|
return 'Basic ' + Buffer.from(`${email}:${token}`).toString('base64');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
async function request(
|
|
14
|
-
|
|
13
|
+
async function request(url, params = {}) {
|
|
14
|
+
if (url.origin !== new URL(get('confluence.baseUrl')).origin) {
|
|
15
|
+
throw new Error('Confluence pagination points to a different site. Check confluence.baseUrl.');
|
|
16
|
+
}
|
|
15
17
|
for (const [k, v] of Object.entries(params)) {
|
|
16
18
|
if (v !== undefined && v !== null) url.searchParams.set(k, v);
|
|
17
19
|
}
|
|
@@ -35,11 +37,13 @@ async function request(path, params = {}) {
|
|
|
35
37
|
|
|
36
38
|
async function paginateV2(path, params = {}) {
|
|
37
39
|
const results = [];
|
|
38
|
-
let
|
|
40
|
+
let url = apiUrl(path);
|
|
41
|
+
let data = await request(url, params);
|
|
39
42
|
results.push(...(data.results || []));
|
|
40
43
|
|
|
41
44
|
while (data._links?.next) {
|
|
42
|
-
|
|
45
|
+
url = new URL(data._links.next, url);
|
|
46
|
+
data = await request(url);
|
|
43
47
|
results.push(...(data.results || []));
|
|
44
48
|
}
|
|
45
49
|
|
|
@@ -51,7 +55,7 @@ export async function listSpaces() {
|
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
export async function getPage(id) {
|
|
54
|
-
return request(`/api/v2/pages/${id}
|
|
58
|
+
return request(apiUrl(`/api/v2/pages/${id}`), { 'body-format': 'storage' });
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
export async function listSpacePages(spaceId) {
|
|
@@ -59,5 +63,5 @@ export async function listSpacePages(spaceId) {
|
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
export async function searchPages(cql) {
|
|
62
|
-
return request('/rest/api/search', { cql });
|
|
66
|
+
return request(apiUrl('/rest/api/search'), { cql });
|
|
63
67
|
}
|
|
@@ -1,119 +1,181 @@
|
|
|
1
|
-
import { get } from '../config/store.js';
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
return
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const data = await request(`/rest/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
1
|
+
import { get } from '../config/store.js';
|
|
2
|
+
|
|
3
|
+
function configurationError(reason) {
|
|
4
|
+
return new Error(`Service Desk configuration error: ${reason}. Check serviceDesk.baseUrl; use the canonical https://<site>.atlassian.net URL.`);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function baseUrl() {
|
|
8
|
+
let url;
|
|
9
|
+
try {
|
|
10
|
+
url = new URL(get('serviceDesk.baseUrl'));
|
|
11
|
+
} catch {
|
|
12
|
+
throw configurationError('invalid base URL');
|
|
13
|
+
}
|
|
14
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash || /[^/]/.test(url.pathname)) {
|
|
15
|
+
throw configurationError('the base URL must be an HTTPS site URL without a path, query, or credentials');
|
|
16
|
+
}
|
|
17
|
+
return new URL(url.origin);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function authHeader() {
|
|
21
|
+
const email = get('serviceDesk.email');
|
|
22
|
+
const token = get('serviceDesk.token');
|
|
23
|
+
return 'Basic ' + Buffer.from(`${email}:${token}`).toString('base64');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function fetchJson(url, headers = {}) {
|
|
27
|
+
const res = await fetch(url, {
|
|
28
|
+
redirect: 'manual',
|
|
29
|
+
headers: { 'Accept': 'application/json', ...headers },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (res.redirected || (res.status >= 300 && res.status < 400)) {
|
|
33
|
+
throw configurationError('the API returned a redirect; authentication may not reach the intended site');
|
|
34
|
+
}
|
|
35
|
+
if (res.url && new URL(res.url).origin !== url.origin) {
|
|
36
|
+
throw configurationError('the API response came from an unexpected host');
|
|
37
|
+
}
|
|
38
|
+
if (!res.ok) {
|
|
39
|
+
const err = new Error(`Service Desk API error: ${res.status} ${res.statusText}`);
|
|
40
|
+
err.status = res.status;
|
|
41
|
+
err.url = url.toString();
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const contentType = res.headers.get('content-type')?.split(';')[0].trim().toLowerCase();
|
|
46
|
+
if (!/^application\/(?:[\w.+-]+\+)?json$/.test(contentType || '')) {
|
|
47
|
+
throw configurationError('expected a JSON API response, but received a different content type');
|
|
48
|
+
}
|
|
49
|
+
let data;
|
|
50
|
+
try {
|
|
51
|
+
data = await res.json();
|
|
52
|
+
} catch {
|
|
53
|
+
throw configurationError('the API response contains invalid JSON');
|
|
54
|
+
}
|
|
55
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
56
|
+
throw configurationError('unexpected API response structure');
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function request(path, params = {}, { extraHeaders = {}, validate = () => true } = {}) {
|
|
62
|
+
const site = baseUrl();
|
|
63
|
+
if (!site.hostname.endsWith('.atlassian.net')) {
|
|
64
|
+
const info = await fetchJson(new URL('/rest/api/2/serverInfo', site));
|
|
65
|
+
let canonical;
|
|
66
|
+
try {
|
|
67
|
+
canonical = new URL(info.baseUrl);
|
|
68
|
+
} catch {
|
|
69
|
+
throw configurationError('serverInfo did not return a valid canonical base URL');
|
|
70
|
+
}
|
|
71
|
+
if (canonical.origin !== site.origin || canonical.pathname.replace(/\/+$/, '') !== '') {
|
|
72
|
+
throw configurationError(`serverInfo identifies a different canonical base URL: ${canonical.origin}${canonical.pathname.replace(/\/+$/, '')}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const url = new URL(path, site);
|
|
77
|
+
for (const [k, v] of Object.entries(params)) {
|
|
78
|
+
if (v !== undefined && v !== null && v !== '') url.searchParams.set(k, v);
|
|
79
|
+
}
|
|
80
|
+
const data = await fetchJson(url, { 'Authorization': authHeader(), ...extraHeaders });
|
|
81
|
+
if (!validate(data)) throw configurationError('unexpected API response structure');
|
|
82
|
+
return data;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function getIssue(issueKey) {
|
|
86
|
+
return request(`/rest/api/3/issue/${encodeURIComponent(issueKey)}`, {
|
|
87
|
+
expand: 'renderedFields',
|
|
88
|
+
}, {
|
|
89
|
+
validate: (data) => typeof data.key === 'string' && data.fields && typeof data.fields === 'object' && !Array.isArray(data.fields),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function getIssueComments(issueKey) {
|
|
94
|
+
const data = await request(`/rest/api/3/issue/${encodeURIComponent(issueKey)}/comment`, {
|
|
95
|
+
orderBy: 'created',
|
|
96
|
+
maxResults: 100,
|
|
97
|
+
}, {
|
|
98
|
+
validate: (data) => Array.isArray(data.comments),
|
|
99
|
+
});
|
|
100
|
+
return data.comments;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function searchIssues(jql, maxResults = 50, nextPageToken = '') {
|
|
104
|
+
const fields = 'summary,status,assignee,priority,updated,issuetype,reporter,customfield_10010';
|
|
105
|
+
const data = await request('/rest/api/3/search/jql', {
|
|
106
|
+
jql,
|
|
107
|
+
fields,
|
|
108
|
+
maxResults,
|
|
109
|
+
nextPageToken,
|
|
110
|
+
}, {
|
|
111
|
+
validate: (data) => Array.isArray(data.issues)
|
|
112
|
+
&& (data.isLast === undefined || typeof data.isLast === 'boolean')
|
|
113
|
+
&& (data.nextPageToken == null || typeof data.nextPageToken === 'string'),
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
issues: data.issues,
|
|
117
|
+
nextPageToken: data.nextPageToken || null,
|
|
118
|
+
isLast: data.isLast !== false,
|
|
119
|
+
maxResults,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function getMyIssues() {
|
|
124
|
+
const project = get('serviceDesk.defaultProject');
|
|
125
|
+
const jql = project
|
|
126
|
+
? `project = ${project} AND assignee = currentUser() AND statusCategory != Done ORDER BY updated DESC`
|
|
127
|
+
: `assignee = currentUser() AND statusCategory != Done ORDER BY updated DESC`;
|
|
128
|
+
return searchIssues(jql);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let _serviceDeskIdCache = null;
|
|
132
|
+
|
|
133
|
+
async function getServiceDeskId(projectKey) {
|
|
134
|
+
if (_serviceDeskIdCache && _serviceDeskIdCache.projectKey === projectKey) {
|
|
135
|
+
return _serviceDeskIdCache.id;
|
|
136
|
+
}
|
|
137
|
+
const data = await request('/rest/servicedeskapi/servicedesk', { start: 0, limit: 100 }, {
|
|
138
|
+
extraHeaders: { 'X-ExperimentalApi': 'opt-in' },
|
|
139
|
+
validate: (data) => Array.isArray(data.values),
|
|
140
|
+
});
|
|
141
|
+
const match = data.values.find((sd) => sd.projectKey === projectKey);
|
|
142
|
+
if (!match) {
|
|
143
|
+
throw new Error(`No Service Desk found for project ${projectKey}`);
|
|
144
|
+
}
|
|
145
|
+
_serviceDeskIdCache = { projectKey, id: match.id };
|
|
146
|
+
return match.id;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function listQueues() {
|
|
150
|
+
const projectKey = get('serviceDesk.defaultProject');
|
|
151
|
+
if (!projectKey) throw new Error('serviceDesk.defaultProject is not configured');
|
|
152
|
+
const sdId = await getServiceDeskId(projectKey);
|
|
153
|
+
const data = await request(`/rest/servicedeskapi/servicedesk/${sdId}/queue`, { start: 0, limit: 100 }, {
|
|
154
|
+
extraHeaders: { 'X-ExperimentalApi': 'opt-in' },
|
|
155
|
+
validate: (data) => Array.isArray(data.values),
|
|
156
|
+
});
|
|
157
|
+
return data.values.map((q) => ({ id: q.id, name: q.name, jql: q.jql }));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export async function findQueue(nameOrId) {
|
|
161
|
+
const queues = await listQueues();
|
|
162
|
+
const idMatch = queues.find((q) => String(q.id) === String(nameOrId));
|
|
163
|
+
if (idMatch) return idMatch;
|
|
164
|
+
const lower = nameOrId.toLowerCase();
|
|
165
|
+
const exact = queues.find((q) => q.name.toLowerCase() === lower);
|
|
166
|
+
if (exact) return exact;
|
|
167
|
+
const partial = queues.filter((q) => q.name.toLowerCase().includes(lower));
|
|
168
|
+
if (partial.length === 1) return partial[0];
|
|
169
|
+
if (partial.length > 1) {
|
|
170
|
+
const err = new Error(`Ambiguous queue "${nameOrId}" — matches: ${partial.map((q) => q.name).join(', ')}`);
|
|
171
|
+
err.candidates = partial;
|
|
172
|
+
throw err;
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`No queue found matching "${nameOrId}"`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function searchByQueue(nameOrId, maxResults = 50, nextPageToken = '') {
|
|
178
|
+
const queue = await findQueue(nameOrId);
|
|
179
|
+
const result = await searchIssues(queue.jql, maxResults, nextPageToken);
|
|
180
|
+
return { ...result, queue };
|
|
181
|
+
}
|
package/src/commands/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { getAll, set, runSetup, configPath,
|
|
2
|
+
import { getAll, set, runSetup, configPath, schema } from '../config/store.js';
|
|
3
3
|
import { heading, field, mask, success, error, divider } from '../utils/output.js';
|
|
4
4
|
|
|
5
5
|
const config = new Command('config')
|
|
@@ -17,29 +17,15 @@ config
|
|
|
17
17
|
.alias('get')
|
|
18
18
|
.description('Show current configuration')
|
|
19
19
|
.action(() => {
|
|
20
|
-
if (!isConfigured()) {
|
|
21
|
-
error('Not configured yet. Run: dev config setup');
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
20
|
const all = getAll();
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
field('Base URL', all.jira.baseUrl);
|
|
35
|
-
field('Token', mask(all.jira.token));
|
|
36
|
-
field('Default project', all.jira.defaultProject);
|
|
37
|
-
|
|
38
|
-
heading('Confluence');
|
|
39
|
-
field('Base URL', all.confluence.baseUrl);
|
|
40
|
-
field('Email', all.confluence.email);
|
|
41
|
-
field('Token', mask(all.confluence.token));
|
|
42
|
-
field('Default space', all.confluence.defaultSpace);
|
|
22
|
+
for (const [section, definition] of Object.entries(schema)) {
|
|
23
|
+
heading(definition.title);
|
|
24
|
+
for (const [key, property] of Object.entries(definition.properties)) {
|
|
25
|
+
const value = all[section]?.[key] ?? '';
|
|
26
|
+
field(property.title, property.writeOnly ? mask(value) : value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
43
29
|
|
|
44
30
|
console.log('');
|
|
45
31
|
divider();
|
|
@@ -51,11 +37,8 @@ config
|
|
|
51
37
|
.command('set <key> <value>')
|
|
52
38
|
.description('Set a config value (e.g. bitbucket.workspace my-ws)')
|
|
53
39
|
.action((key, value) => {
|
|
54
|
-
const validKeys = [
|
|
55
|
-
|
|
56
|
-
'jira.baseUrl', 'jira.token', 'jira.defaultProject',
|
|
57
|
-
'confluence.baseUrl', 'confluence.email', 'confluence.token', 'confluence.defaultSpace',
|
|
58
|
-
];
|
|
40
|
+
const validKeys = Object.entries(schema).flatMap(([section, definition]) =>
|
|
41
|
+
Object.keys(definition.properties).map((key) => `${section}.${key}`));
|
|
59
42
|
if (!validKeys.includes(key)) {
|
|
60
43
|
error(`Invalid key: ${key}`);
|
|
61
44
|
console.log(`Valid keys: ${validKeys.join(', ')}`);
|