azdo-cli 0.2.0-hotfix-0-2-5.63 → 0.2.4
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/dist/index.js +13 -49
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -42,19 +42,6 @@ async function fetchWithErrors(url, init) {
|
|
|
42
42
|
if (response.status === 404) throw new Error("NOT_FOUND");
|
|
43
43
|
return response;
|
|
44
44
|
}
|
|
45
|
-
async function readResponseMessage(response) {
|
|
46
|
-
try {
|
|
47
|
-
const body = await response.json();
|
|
48
|
-
if (typeof body.message === "string" && body.message.trim() !== "") {
|
|
49
|
-
return body.message.trim();
|
|
50
|
-
}
|
|
51
|
-
} catch {
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
function normalizeFieldList(fields) {
|
|
56
|
-
return Array.from(new Set(fields.map((f) => f.trim()).filter((f) => f.length > 0)));
|
|
57
|
-
}
|
|
58
45
|
function buildExtraFields(fields, requested) {
|
|
59
46
|
const result = {};
|
|
60
47
|
for (const name of requested) {
|
|
@@ -70,18 +57,11 @@ async function getWorkItem(context, id, pat, extraFields) {
|
|
|
70
57
|
`https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/${id}`
|
|
71
58
|
);
|
|
72
59
|
url.searchParams.set("api-version", "7.1");
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const allFields = normalizeFieldList([...DEFAULT_FIELDS, ...normalizedExtraFields]);
|
|
60
|
+
if (extraFields && extraFields.length > 0) {
|
|
61
|
+
const allFields = [...DEFAULT_FIELDS, ...extraFields];
|
|
76
62
|
url.searchParams.set("fields", allFields.join(","));
|
|
77
63
|
}
|
|
78
64
|
const response = await fetchWithErrors(url.toString(), { headers: authHeaders(pat) });
|
|
79
|
-
if (response.status === 400) {
|
|
80
|
-
const serverMessage = await readResponseMessage(response);
|
|
81
|
-
if (serverMessage) {
|
|
82
|
-
throw new Error(`BAD_REQUEST: ${serverMessage}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
65
|
if (!response.ok) {
|
|
86
66
|
throw new Error(`HTTP_${response.status}`);
|
|
87
67
|
}
|
|
@@ -113,7 +93,7 @@ async function getWorkItem(context, id, pat, extraFields) {
|
|
|
113
93
|
areaPath: data.fields["System.AreaPath"],
|
|
114
94
|
iterationPath: data.fields["System.IterationPath"],
|
|
115
95
|
url: data._links.html.href,
|
|
116
|
-
extraFields:
|
|
96
|
+
extraFields: extraFields && extraFields.length > 0 ? buildExtraFields(data.fields, extraFields) : null
|
|
117
97
|
};
|
|
118
98
|
}
|
|
119
99
|
async function getWorkItemFieldValue(context, id, pat, fieldName) {
|
|
@@ -123,12 +103,6 @@ async function getWorkItemFieldValue(context, id, pat, fieldName) {
|
|
|
123
103
|
url.searchParams.set("api-version", "7.1");
|
|
124
104
|
url.searchParams.set("fields", fieldName);
|
|
125
105
|
const response = await fetchWithErrors(url.toString(), { headers: authHeaders(pat) });
|
|
126
|
-
if (response.status === 400) {
|
|
127
|
-
const serverMessage = await readResponseMessage(response);
|
|
128
|
-
if (serverMessage) {
|
|
129
|
-
throw new Error(`BAD_REQUEST: ${serverMessage}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
106
|
if (!response.ok) {
|
|
133
107
|
throw new Error(`HTTP_${response.status}`);
|
|
134
108
|
}
|
|
@@ -153,7 +127,12 @@ async function updateWorkItem(context, id, pat, fieldName, operations) {
|
|
|
153
127
|
body: JSON.stringify(operations)
|
|
154
128
|
});
|
|
155
129
|
if (response.status === 400) {
|
|
156
|
-
|
|
130
|
+
let serverMessage = "Unknown error";
|
|
131
|
+
try {
|
|
132
|
+
const body = await response.json();
|
|
133
|
+
if (body.message) serverMessage = body.message;
|
|
134
|
+
} catch {
|
|
135
|
+
}
|
|
157
136
|
throw new Error(`UPDATE_REJECTED: ${serverMessage}`);
|
|
158
137
|
}
|
|
159
138
|
if (!response.ok) {
|
|
@@ -442,7 +421,7 @@ function validateOrgProjectPair(options) {
|
|
|
442
421
|
process.exit(1);
|
|
443
422
|
}
|
|
444
423
|
}
|
|
445
|
-
function handleCommandError(err, id, context, scope = "write"
|
|
424
|
+
function handleCommandError(err, id, context, scope = "write") {
|
|
446
425
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
447
426
|
const msg = error.message;
|
|
448
427
|
const scopeLabel = scope === "read" ? "Work Items (read)" : "Work Items (Read & Write)";
|
|
@@ -465,10 +444,6 @@ function handleCommandError(err, id, context, scope = "write", exit = true) {
|
|
|
465
444
|
process.stderr.write(
|
|
466
445
|
"Error: Could not connect to Azure DevOps. Check your network connection.\n"
|
|
467
446
|
);
|
|
468
|
-
} else if (msg.startsWith("BAD_REQUEST:")) {
|
|
469
|
-
const serverMsg = msg.replace("BAD_REQUEST: ", "");
|
|
470
|
-
process.stderr.write(`Error: Request rejected: ${serverMsg}
|
|
471
|
-
`);
|
|
472
447
|
} else if (msg.startsWith("UPDATE_REJECTED:")) {
|
|
473
448
|
const serverMsg = msg.replace("UPDATE_REJECTED: ", "");
|
|
474
449
|
process.stderr.write(`Error: Update rejected: ${serverMsg}
|
|
@@ -477,21 +452,10 @@ function handleCommandError(err, id, context, scope = "write", exit = true) {
|
|
|
477
452
|
process.stderr.write(`Error: ${msg}
|
|
478
453
|
`);
|
|
479
454
|
}
|
|
480
|
-
|
|
481
|
-
process.exit(1);
|
|
482
|
-
} else {
|
|
483
|
-
process.exitCode = 1;
|
|
484
|
-
}
|
|
455
|
+
process.exit(1);
|
|
485
456
|
}
|
|
486
457
|
|
|
487
458
|
// src/commands/get-item.ts
|
|
488
|
-
function parseRequestedFields(raw) {
|
|
489
|
-
if (raw === void 0) return void 0;
|
|
490
|
-
const source = Array.isArray(raw) ? raw : [raw];
|
|
491
|
-
const tokens = source.flatMap((entry) => entry.split(/[,\s]+/)).map((field) => field.trim()).filter((field) => field.length > 0);
|
|
492
|
-
if (tokens.length === 0) return void 0;
|
|
493
|
-
return Array.from(new Set(tokens));
|
|
494
|
-
}
|
|
495
459
|
function stripHtml(html) {
|
|
496
460
|
let text = html;
|
|
497
461
|
text = text.replace(/<h[1-6][^>]*>(.*?)<\/h[1-6]>/gi, "\n--- $1 ---\n");
|
|
@@ -551,12 +515,12 @@ function createGetItemCommand() {
|
|
|
551
515
|
try {
|
|
552
516
|
context = resolveContext(options);
|
|
553
517
|
const credential = await resolvePat();
|
|
554
|
-
const fieldsList = options.fields
|
|
518
|
+
const fieldsList = options.fields ? options.fields.split(",").map((f) => f.trim()) : loadConfig().fields;
|
|
555
519
|
const workItem = await getWorkItem(context, id, credential.pat, fieldsList);
|
|
556
520
|
const output = formatWorkItem(workItem, options.short ?? false);
|
|
557
521
|
process.stdout.write(output + "\n");
|
|
558
522
|
} catch (err) {
|
|
559
|
-
handleCommandError(err, id, context, "read"
|
|
523
|
+
handleCommandError(err, id, context, "read");
|
|
560
524
|
}
|
|
561
525
|
}
|
|
562
526
|
);
|