azdo-cli 0.2.0-develop.92 → 0.2.0-develop.94
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 +37 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -55,12 +55,18 @@ async function readResponseMessage(response) {
|
|
|
55
55
|
function normalizeFieldList(fields) {
|
|
56
56
|
return Array.from(new Set(fields.map((f) => f.trim()).filter((f) => f.length > 0)));
|
|
57
57
|
}
|
|
58
|
+
function stringifyFieldValue(value) {
|
|
59
|
+
if (typeof value === "object" && value !== null) {
|
|
60
|
+
return JSON.stringify(value);
|
|
61
|
+
}
|
|
62
|
+
return String(value);
|
|
63
|
+
}
|
|
58
64
|
function buildExtraFields(fields, requested) {
|
|
59
65
|
const result = {};
|
|
60
66
|
for (const name of requested) {
|
|
61
67
|
const val = fields[name];
|
|
62
68
|
if (val !== void 0 && val !== null) {
|
|
63
|
-
result[name] =
|
|
69
|
+
result[name] = stringifyFieldValue(val);
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
return Object.keys(result).length > 0 ? result : null;
|
|
@@ -119,7 +125,7 @@ async function getWorkItem(context, id, pat, extraFields) {
|
|
|
119
125
|
}
|
|
120
126
|
let combinedDescription = null;
|
|
121
127
|
if (descriptionParts.length === 1) {
|
|
122
|
-
combinedDescription = descriptionParts
|
|
128
|
+
combinedDescription = descriptionParts.at(0)?.value ?? null;
|
|
123
129
|
} else if (descriptionParts.length > 1) {
|
|
124
130
|
combinedDescription = descriptionParts.map((p) => `<h3>${p.label}</h3>${p.value}`).join("");
|
|
125
131
|
}
|
|
@@ -158,13 +164,13 @@ async function getWorkItemFieldValue(context, id, pat, fieldName) {
|
|
|
158
164
|
if (value === void 0 || value === null || value === "") {
|
|
159
165
|
return null;
|
|
160
166
|
}
|
|
161
|
-
return
|
|
167
|
+
return stringifyFieldValue(value);
|
|
162
168
|
}
|
|
163
169
|
async function updateWorkItem(context, id, pat, fieldName, operations) {
|
|
164
170
|
const result = await applyWorkItemPatch(context, id, pat, operations);
|
|
165
171
|
const title = result.fields["System.Title"];
|
|
166
|
-
const lastOp = operations
|
|
167
|
-
const fieldValue = lastOp
|
|
172
|
+
const lastOp = operations.at(-1);
|
|
173
|
+
const fieldValue = lastOp?.value ?? null;
|
|
168
174
|
return {
|
|
169
175
|
id: result.id,
|
|
170
176
|
rev: result.rev,
|
|
@@ -313,7 +319,7 @@ var patterns = [
|
|
|
313
319
|
];
|
|
314
320
|
function parseAzdoRemote(url) {
|
|
315
321
|
for (const pattern of patterns) {
|
|
316
|
-
const match =
|
|
322
|
+
const match = pattern.exec(url);
|
|
317
323
|
if (match) {
|
|
318
324
|
const project = match[2];
|
|
319
325
|
if (/^DefaultCollection$/i.test(project)) {
|
|
@@ -609,18 +615,18 @@ function parseRequestedFields(raw) {
|
|
|
609
615
|
}
|
|
610
616
|
function stripHtml(html) {
|
|
611
617
|
let text = html;
|
|
612
|
-
text = text.
|
|
613
|
-
text = text.
|
|
614
|
-
text = text.
|
|
615
|
-
text = text.
|
|
616
|
-
text = text.
|
|
617
|
-
text = text.
|
|
618
|
-
text = text.
|
|
619
|
-
text = text.
|
|
620
|
-
text = text.
|
|
621
|
-
text = text.
|
|
622
|
-
text = text.
|
|
623
|
-
text = text.
|
|
618
|
+
text = text.replaceAll(/<h[1-6][^>]*>(.*?)<\/h[1-6]>/gi, "\n--- $1 ---\n");
|
|
619
|
+
text = text.replaceAll(/<br\s*\/?>/gi, "\n");
|
|
620
|
+
text = text.replaceAll(/<\/?(p|div)>/gi, "\n");
|
|
621
|
+
text = text.replaceAll(/<li>/gi, "\n");
|
|
622
|
+
text = text.replaceAll(/<[^>]*>/g, "");
|
|
623
|
+
text = text.replaceAll("&", "&");
|
|
624
|
+
text = text.replaceAll("<", "<");
|
|
625
|
+
text = text.replaceAll(">", ">");
|
|
626
|
+
text = text.replaceAll(""", '"');
|
|
627
|
+
text = text.replaceAll("'", "'");
|
|
628
|
+
text = text.replaceAll(" ", " ");
|
|
629
|
+
text = text.replaceAll(/\n{3,}/g, "\n\n");
|
|
624
630
|
return text.trim();
|
|
625
631
|
}
|
|
626
632
|
function convertRichText(html, markdown) {
|
|
@@ -641,16 +647,19 @@ function summarizeDescription(text, label) {
|
|
|
641
647
|
return [`${label("Description:")}${firstThree.join("\n")}${suffix}`];
|
|
642
648
|
}
|
|
643
649
|
function formatWorkItem(workItem, short, markdown = false) {
|
|
644
|
-
const lines = [];
|
|
645
650
|
const label = (name) => name.padEnd(13);
|
|
646
|
-
lines
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
+
const lines = [
|
|
652
|
+
`${label("ID:")}${workItem.id}`,
|
|
653
|
+
`${label("Type:")}${workItem.type}`,
|
|
654
|
+
`${label("Title:")}${workItem.title}`,
|
|
655
|
+
`${label("State:")}${workItem.state}`,
|
|
656
|
+
`${label("Assigned To:")}${workItem.assignedTo ?? "Unassigned"}`
|
|
657
|
+
];
|
|
651
658
|
if (!short) {
|
|
652
|
-
lines.push(
|
|
653
|
-
|
|
659
|
+
lines.push(
|
|
660
|
+
`${label("Area:")}${workItem.areaPath}`,
|
|
661
|
+
`${label("Iteration:")}${workItem.iterationPath}`
|
|
662
|
+
);
|
|
654
663
|
}
|
|
655
664
|
lines.push(`${label("URL:")}${workItem.url}`);
|
|
656
665
|
if (workItem.extraFields) {
|
|
@@ -661,8 +670,7 @@ function formatWorkItem(workItem, short, markdown = false) {
|
|
|
661
670
|
if (short) {
|
|
662
671
|
lines.push(...summarizeDescription(descriptionText, label));
|
|
663
672
|
} else {
|
|
664
|
-
lines.push("Description:");
|
|
665
|
-
lines.push(descriptionText);
|
|
673
|
+
lines.push("Description:", descriptionText);
|
|
666
674
|
}
|
|
667
675
|
return lines.join("\n");
|
|
668
676
|
}
|
|
@@ -676,7 +684,7 @@ function createGetItemCommand() {
|
|
|
676
684
|
try {
|
|
677
685
|
context = resolveContext(options);
|
|
678
686
|
const credential = await resolvePat();
|
|
679
|
-
const fieldsList = options.fields
|
|
687
|
+
const fieldsList = options.fields === void 0 ? parseRequestedFields(loadConfig().fields) : parseRequestedFields(options.fields);
|
|
680
688
|
const workItem = await getWorkItem(context, id, credential.pat, fieldsList);
|
|
681
689
|
const markdownEnabled = options.markdown ?? loadConfig().markdown ?? false;
|
|
682
690
|
const output = formatWorkItem(workItem, options.short ?? false, markdownEnabled);
|