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.
Files changed (2) hide show
  1. package/dist/index.js +37 -29
  2. 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] = String(val);
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[0].value;
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 typeof value === "object" ? JSON.stringify(value) : `${value}`;
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[operations.length - 1];
167
- const fieldValue = lastOp.value ?? null;
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 = url.match(pattern);
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.replace(/<h[1-6][^>]*>(.*?)<\/h[1-6]>/gi, "\n--- $1 ---\n");
613
- text = text.replace(/<br\s*\/?>/gi, "\n");
614
- text = text.replace(/<\/?(p|div)>/gi, "\n");
615
- text = text.replace(/<li>/gi, "\n");
616
- text = text.replace(/<[^>]*>/g, "");
617
- text = text.replace(/&amp;/g, "&");
618
- text = text.replace(/&lt;/g, "<");
619
- text = text.replace(/&gt;/g, ">");
620
- text = text.replace(/&quot;/g, '"');
621
- text = text.replace(/&#39;/g, "'");
622
- text = text.replace(/&nbsp;/g, " ");
623
- text = text.replace(/\n{3,}/g, "\n\n");
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("&amp;", "&");
624
+ text = text.replaceAll("&lt;", "<");
625
+ text = text.replaceAll("&gt;", ">");
626
+ text = text.replaceAll("&quot;", '"');
627
+ text = text.replaceAll("&#39;", "'");
628
+ text = text.replaceAll("&nbsp;", " ");
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.push(`${label("ID:")}${workItem.id}`);
647
- lines.push(`${label("Type:")}${workItem.type}`);
648
- lines.push(`${label("Title:")}${workItem.title}`);
649
- lines.push(`${label("State:")}${workItem.state}`);
650
- lines.push(`${label("Assigned To:")}${workItem.assignedTo ?? "Unassigned"}`);
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(`${label("Area:")}${workItem.areaPath}`);
653
- lines.push(`${label("Iteration:")}${workItem.iterationPath}`);
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 !== void 0 ? parseRequestedFields(options.fields) : parseRequestedFields(loadConfig().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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azdo-cli",
3
- "version": "0.2.0-develop.92",
3
+ "version": "0.2.0-develop.94",
4
4
  "description": "Azure DevOps CLI tool",
5
5
  "type": "module",
6
6
  "bin": {