azdo-cli 0.2.0-develop.75 → 0.2.0-develop.88

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 (3) hide show
  1. package/README.md +82 -0
  2. package/dist/index.js +377 -23
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -12,6 +12,7 @@ Azure DevOps CLI focused on work item read/write workflows.
12
12
  - Update work item state (`set-state`)
13
13
  - Assign and unassign work items (`assign`)
14
14
  - Set any work item field by reference name (`set-field`)
15
+ - Create or update Tasks from markdown documents (`upsert`)
15
16
  - Read rich-text fields as markdown (`get-md-field`)
16
17
  - Set rich-text fields as markdown from inline text, file, or stdin (`set-md-field`)
17
18
  - Persist org/project/default fields in local config (`config`)
@@ -47,6 +48,9 @@ azdo get-item 12345
47
48
 
48
49
  # 3) Update state
49
50
  azdo set-state 12345 "Active"
51
+
52
+ # 4) Create or update a Task from markdown
53
+ azdo upsert --content $'---\nTitle: Improve markdown import UX\nState: New\n---'
50
54
  ```
51
55
 
52
56
  ## Command Cheat Sheet
@@ -57,6 +61,7 @@ azdo set-state 12345 "Active"
57
61
  | `azdo set-state <id> <state>` | Change work item state | `--json`, `--org`, `--project` |
58
62
  | `azdo assign <id> [name]` | Assign or unassign owner | `--unassign`, `--json`, `--org`, `--project` |
59
63
  | `azdo set-field <id> <field> <value>` | Update any field | `--json`, `--org`, `--project` |
64
+ | `azdo upsert [id]` | Create or update a Task from markdown | `--content`, `--file`, `--json`, `--org`, `--project` |
60
65
  | `azdo get-md-field <id> <field>` | Get field as markdown | `--org`, `--project` |
61
66
  | `azdo set-md-field <id> <field> [content]` | Set markdown field | `--file`, `--json`, `--org`, `--project` |
62
67
  | `azdo config <subcommand>` | Manage saved settings | `set`, `get`, `list`, `unset`, `wizard`, `--json` |
@@ -119,6 +124,83 @@ azdo set-md-field 12345 System.Description --file ./description.md
119
124
  cat description.md | azdo set-md-field 12345 System.Description
120
125
  ```
121
126
 
127
+ ## azdo upsert
128
+
129
+ `azdo upsert` accepts a single markdown task document and either creates a new Azure DevOps Task or updates an existing one. Omit `[id]` to create; pass `[id]` to update that work item in place.
130
+
131
+ ```bash
132
+ # Create from inline content
133
+ azdo upsert --content $'---\nTitle: Improve markdown import UX\nAssigned To: user@example.com\nState: New\n---'
134
+
135
+ # Update from a file
136
+ azdo upsert 12345 --file ./task-import.md
137
+
138
+ # JSON output
139
+ azdo upsert 12345 --content $'---\nSystem.Title: Improve markdown import UX\n---' --json
140
+ ```
141
+
142
+ The command requires exactly one source flag:
143
+
144
+ - `azdo upsert [id] --content <markdown>`
145
+ - `azdo upsert [id] --file <path>`
146
+
147
+ If `--file` succeeds, the source file is deleted after the Azure DevOps write completes. If parsing, validation, or the API call fails, the file is preserved. If deletion fails after a successful write, the command still succeeds and prints a warning.
148
+
149
+ ### Task Document Format
150
+
151
+ The document starts with YAML front matter for scalar fields, followed by optional `##` heading sections for markdown rich-text fields.
152
+
153
+ ```md
154
+ ---
155
+ Title: Improve markdown import UX
156
+ Assigned To: user@example.com
157
+ State: New
158
+ Tags: cli; markdown
159
+ Priority: null
160
+ ---
161
+
162
+ ## Description
163
+
164
+ Implement a single-command task import flow.
165
+
166
+ ## Acceptance Criteria
167
+
168
+ - Supports create when no ID is passed
169
+ - Supports update when an ID is passed
170
+ - Deletes imported files only after success
171
+ ```
172
+
173
+ Supported friendly field names:
174
+
175
+ - `Title`
176
+ - `Assigned To` / `assignedTo`
177
+ - `State`
178
+ - `Description`
179
+ - `Acceptance Criteria` / `acceptanceCriteria`
180
+ - `Tags`
181
+ - `Priority`
182
+
183
+ Raw Azure DevOps reference names are also accepted anywhere a field name is expected, for example `System.Title` or `Microsoft.VSTS.Common.AcceptanceCriteria`.
184
+
185
+ Clear semantics:
186
+
187
+ - Scalar YAML fields with `null` or an empty value are treated as clears on update.
188
+ - Rich-text heading sections with an empty body are treated as clears on update.
189
+ - Omitted fields are untouched on update.
190
+
191
+ `--json` output shape:
192
+
193
+ ```json
194
+ {
195
+ "action": "created",
196
+ "id": 12345,
197
+ "fields": {
198
+ "System.Title": "Improve markdown import UX",
199
+ "System.Description": "Implement a single-command task import flow."
200
+ }
201
+ }
202
+ ```
203
+
122
204
  ### Configuration
123
205
 
124
206
  ```bash
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { Command as Command9 } from "commander";
4
+ import { Command as Command10 } from "commander";
5
5
 
6
6
  // src/version.ts
7
7
  import { readFileSync } from "fs";
@@ -65,6 +65,27 @@ function buildExtraFields(fields, requested) {
65
65
  }
66
66
  return Object.keys(result).length > 0 ? result : null;
67
67
  }
68
+ function writeHeaders(pat) {
69
+ return {
70
+ ...authHeaders(pat),
71
+ "Content-Type": "application/json-patch+json"
72
+ };
73
+ }
74
+ async function readWriteResponse(response, errorCode) {
75
+ if (response.status === 400) {
76
+ const serverMessage = await readResponseMessage(response) ?? "Unknown error";
77
+ throw new Error(`${errorCode}: ${serverMessage}`);
78
+ }
79
+ if (!response.ok) {
80
+ throw new Error(`HTTP_${response.status}`);
81
+ }
82
+ const data = await response.json();
83
+ return {
84
+ id: data.id,
85
+ rev: data.rev,
86
+ fields: data.fields
87
+ };
88
+ }
68
89
  async function getWorkItem(context, id, pat, extraFields) {
69
90
  const url = new URL(
70
91
  `https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/${id}`
@@ -140,35 +161,41 @@ async function getWorkItemFieldValue(context, id, pat, fieldName) {
140
161
  return typeof value === "object" ? JSON.stringify(value) : `${value}`;
141
162
  }
142
163
  async function updateWorkItem(context, id, pat, fieldName, operations) {
164
+ const result = await applyWorkItemPatch(context, id, pat, operations);
165
+ const title = result.fields["System.Title"];
166
+ const lastOp = operations[operations.length - 1];
167
+ const fieldValue = lastOp.value ?? null;
168
+ return {
169
+ id: result.id,
170
+ rev: result.rev,
171
+ title: typeof title === "string" ? title : "",
172
+ fieldName,
173
+ fieldValue
174
+ };
175
+ }
176
+ async function createWorkItem(context, workItemType, pat, operations) {
177
+ const url = new URL(
178
+ `https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/$${encodeURIComponent(workItemType)}`
179
+ );
180
+ url.searchParams.set("api-version", "7.1");
181
+ const response = await fetchWithErrors(url.toString(), {
182
+ method: "POST",
183
+ headers: writeHeaders(pat),
184
+ body: JSON.stringify(operations)
185
+ });
186
+ return readWriteResponse(response, "CREATE_REJECTED");
187
+ }
188
+ async function applyWorkItemPatch(context, id, pat, operations) {
143
189
  const url = new URL(
144
190
  `https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/${id}`
145
191
  );
146
192
  url.searchParams.set("api-version", "7.1");
147
193
  const response = await fetchWithErrors(url.toString(), {
148
194
  method: "PATCH",
149
- headers: {
150
- ...authHeaders(pat),
151
- "Content-Type": "application/json-patch+json"
152
- },
195
+ headers: writeHeaders(pat),
153
196
  body: JSON.stringify(operations)
154
197
  });
155
- if (response.status === 400) {
156
- const serverMessage = await readResponseMessage(response) ?? "Unknown error";
157
- throw new Error(`UPDATE_REJECTED: ${serverMessage}`);
158
- }
159
- if (!response.ok) {
160
- throw new Error(`HTTP_${response.status}`);
161
- }
162
- const data = await response.json();
163
- const lastOp = operations[operations.length - 1];
164
- const fieldValue = lastOp.value ?? null;
165
- return {
166
- id: data.id,
167
- rev: data.rev,
168
- title: data.fields["System.Title"],
169
- fieldName,
170
- fieldValue
171
- };
198
+ return readWriteResponse(response, "UPDATE_REJECTED");
172
199
  }
173
200
 
174
201
  // src/services/auth.ts
@@ -509,6 +536,24 @@ function validateOrgProjectPair(options) {
509
536
  process.exit(1);
510
537
  }
511
538
  }
539
+ function validateSource(options) {
540
+ const hasContent = options.content !== void 0;
541
+ const hasFile = options.file !== void 0;
542
+ if (hasContent === hasFile) {
543
+ process.stderr.write("Error: provide exactly one of --content or --file\n");
544
+ process.exit(1);
545
+ }
546
+ }
547
+ function formatCreateError(err) {
548
+ const error = err instanceof Error ? err : new Error(String(err));
549
+ const message = error.message.startsWith("CREATE_REJECTED:") ? error.message.replace("CREATE_REJECTED:", "").trim() : error.message;
550
+ const requiredMatches = [...message.matchAll(/field ['"]([^'"]+)['"]/gi)];
551
+ if (requiredMatches.length > 0) {
552
+ const fields = Array.from(new Set(requiredMatches.map((match) => match[1])));
553
+ return `Create rejected: ${message} (fields: ${fields.join(", ")})`;
554
+ }
555
+ return `Create rejected: ${message}`;
556
+ }
512
557
  function handleCommandError(err, id, context, scope = "write", exit = true) {
513
558
  const error = err instanceof Error ? err : new Error(String(err));
514
559
  const msg = error.message;
@@ -535,6 +580,9 @@ function handleCommandError(err, id, context, scope = "write", exit = true) {
535
580
  } else if (msg.startsWith("BAD_REQUEST:")) {
536
581
  const serverMsg = msg.replace("BAD_REQUEST: ", "");
537
582
  process.stderr.write(`Error: Request rejected: ${serverMsg}
583
+ `);
584
+ } else if (msg.startsWith("CREATE_REJECTED:")) {
585
+ process.stderr.write(`Error: ${formatCreateError(error)}
538
586
  `);
539
587
  } else if (msg.startsWith("UPDATE_REJECTED:")) {
540
588
  const serverMsg = msg.replace("UPDATE_REJECTED: ", "");
@@ -1047,8 +1095,313 @@ function createSetMdFieldCommand() {
1047
1095
  return command;
1048
1096
  }
1049
1097
 
1098
+ // src/commands/upsert.ts
1099
+ import { existsSync as existsSync2, readFileSync as readFileSync3, unlinkSync } from "fs";
1100
+ import { Command as Command9 } from "commander";
1101
+
1102
+ // src/services/task-document.ts
1103
+ var FIELD_ALIASES = /* @__PURE__ */ new Map([
1104
+ ["title", "System.Title"],
1105
+ ["assignedto", "System.AssignedTo"],
1106
+ ["assigned to", "System.AssignedTo"],
1107
+ ["state", "System.State"],
1108
+ ["description", "System.Description"],
1109
+ ["acceptancecriteria", "Microsoft.VSTS.Common.AcceptanceCriteria"],
1110
+ ["acceptance criteria", "Microsoft.VSTS.Common.AcceptanceCriteria"],
1111
+ ["tags", "System.Tags"],
1112
+ ["priority", "Microsoft.VSTS.Common.Priority"]
1113
+ ]);
1114
+ var RICH_TEXT_FIELDS = /* @__PURE__ */ new Set([
1115
+ "System.Description",
1116
+ "Microsoft.VSTS.Common.AcceptanceCriteria"
1117
+ ]);
1118
+ var REFERENCE_NAME_PATTERN = /^[A-Z][A-Za-z0-9]*(\.[A-Za-z0-9]+)+$/;
1119
+ function normalizeAlias(name) {
1120
+ return name.trim().replaceAll(/\s+/g, " ").toLowerCase();
1121
+ }
1122
+ function parseScalarValue(rawValue, fieldName) {
1123
+ if (rawValue === void 0) {
1124
+ throw new Error(`Malformed YAML front matter: missing value for "${fieldName}"`);
1125
+ }
1126
+ const trimmed = rawValue.trim();
1127
+ if (trimmed === "" || trimmed === "null" || trimmed === "~") {
1128
+ return null;
1129
+ }
1130
+ if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
1131
+ return trimmed.slice(1, -1);
1132
+ }
1133
+ if (/^[[{]|^[>|]-?$/.test(trimmed)) {
1134
+ throw new Error(`Malformed YAML front matter: unsupported value for "${fieldName}"`);
1135
+ }
1136
+ return trimmed;
1137
+ }
1138
+ function parseFrontMatter(content) {
1139
+ if (!content.startsWith("---")) {
1140
+ return { frontMatter: "", remainder: content };
1141
+ }
1142
+ const frontMatterPattern = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
1143
+ const match = frontMatterPattern.exec(content);
1144
+ if (!match) {
1145
+ throw new Error('Malformed YAML front matter: missing closing "---"');
1146
+ }
1147
+ return {
1148
+ frontMatter: match[1],
1149
+ remainder: content.slice(match[0].length)
1150
+ };
1151
+ }
1152
+ function assertKnownField(name, kind) {
1153
+ const resolved = resolveFieldName(name);
1154
+ if (!resolved) {
1155
+ const prefix = kind === "rich-text" ? "Unknown rich-text field" : "Unknown field";
1156
+ throw new Error(`${prefix}: ${name}`);
1157
+ }
1158
+ if (kind === "rich-text" && !RICH_TEXT_FIELDS.has(resolved)) {
1159
+ throw new Error(`Unknown rich-text field: ${name}`);
1160
+ }
1161
+ return resolved;
1162
+ }
1163
+ function pushField(fields, seen, refName, value, kind) {
1164
+ if (seen.has(refName)) {
1165
+ throw new Error(`Duplicate field: ${refName}`);
1166
+ }
1167
+ seen.add(refName);
1168
+ fields.push({
1169
+ refName,
1170
+ value,
1171
+ op: value === null ? "clear" : "set",
1172
+ kind
1173
+ });
1174
+ }
1175
+ function parseScalarFields(frontMatter, fields, seen) {
1176
+ if (frontMatter.trim() === "") {
1177
+ return;
1178
+ }
1179
+ for (const rawLine of frontMatter.split(/\r?\n/)) {
1180
+ const line = rawLine.trim();
1181
+ if (line === "") {
1182
+ continue;
1183
+ }
1184
+ const separatorIndex = rawLine.indexOf(":");
1185
+ if (separatorIndex <= 0) {
1186
+ throw new Error(`Malformed YAML front matter: ${rawLine.trim()}`);
1187
+ }
1188
+ const rawName = rawLine.slice(0, separatorIndex).trim();
1189
+ const rawValue = rawLine.slice(separatorIndex + 1);
1190
+ const refName = assertKnownField(rawName, "scalar");
1191
+ const value = parseScalarValue(rawValue, rawName);
1192
+ pushField(fields, seen, refName, value, "scalar");
1193
+ }
1194
+ }
1195
+ function parseRichTextSections(content, fields, seen) {
1196
+ const normalizedContent = content.replaceAll("\r\n", "\n");
1197
+ const lines = normalizedContent.split("\n");
1198
+ const headings = [];
1199
+ for (let index = 0; index < lines.length; index += 1) {
1200
+ const line = lines[index];
1201
+ if (!line.startsWith("##")) {
1202
+ continue;
1203
+ }
1204
+ const headingBody = line.slice(2);
1205
+ if (headingBody.trim() === "" || !headingBody.startsWith(" ") && !headingBody.startsWith(" ")) {
1206
+ continue;
1207
+ }
1208
+ headings.push({
1209
+ lineIndex: index,
1210
+ rawName: headingBody.trim()
1211
+ });
1212
+ }
1213
+ if (headings.length === 0) {
1214
+ return;
1215
+ }
1216
+ for (let index = 0; index < headings[0].lineIndex; index += 1) {
1217
+ if (lines[index].trim() !== "") {
1218
+ throw new Error("Unexpected content before the first markdown heading section");
1219
+ }
1220
+ }
1221
+ for (let index = 0; index < headings.length; index += 1) {
1222
+ const { lineIndex, rawName } = headings[index];
1223
+ const refName = assertKnownField(rawName, "rich-text");
1224
+ const bodyStart = lineIndex + 1;
1225
+ const bodyEnd = index + 1 < headings.length ? headings[index + 1].lineIndex : lines.length;
1226
+ const rawBody = lines.slice(bodyStart, bodyEnd).join("\n");
1227
+ const value = rawBody.trim() === "" ? null : rawBody.trimEnd();
1228
+ pushField(fields, seen, refName, value, "rich-text");
1229
+ }
1230
+ }
1231
+ function resolveFieldName(name) {
1232
+ const trimmed = name.trim();
1233
+ if (trimmed === "") {
1234
+ return null;
1235
+ }
1236
+ const alias = FIELD_ALIASES.get(normalizeAlias(trimmed));
1237
+ if (alias) {
1238
+ return alias;
1239
+ }
1240
+ return REFERENCE_NAME_PATTERN.test(trimmed) ? trimmed : null;
1241
+ }
1242
+ function parseTaskDocument(content) {
1243
+ const { frontMatter, remainder } = parseFrontMatter(content);
1244
+ const fields = [];
1245
+ const seen = /* @__PURE__ */ new Set();
1246
+ parseScalarFields(frontMatter, fields, seen);
1247
+ parseRichTextSections(remainder, fields, seen);
1248
+ return { fields };
1249
+ }
1250
+
1251
+ // src/commands/upsert.ts
1252
+ function fail2(message) {
1253
+ process.stderr.write(`Error: ${message}
1254
+ `);
1255
+ process.exit(1);
1256
+ }
1257
+ function loadSourceContent(options) {
1258
+ validateSource(options);
1259
+ if (options.content !== void 0) {
1260
+ return { content: options.content };
1261
+ }
1262
+ const filePath = options.file;
1263
+ if (!existsSync2(filePath)) {
1264
+ fail2(`File not found: ${filePath}`);
1265
+ }
1266
+ try {
1267
+ return {
1268
+ content: readFileSync3(filePath, "utf-8"),
1269
+ sourceFile: filePath
1270
+ };
1271
+ } catch {
1272
+ fail2(`Cannot read file: ${filePath}`);
1273
+ }
1274
+ }
1275
+ function toPatchOperations(fields, action) {
1276
+ const operations = [];
1277
+ for (const field of fields) {
1278
+ if (field.op === "clear") {
1279
+ if (action === "updated") {
1280
+ operations.push({ op: "remove", path: `/fields/${field.refName}` });
1281
+ }
1282
+ continue;
1283
+ }
1284
+ operations.push({ op: "add", path: `/fields/${field.refName}`, value: field.value ?? "" });
1285
+ if (field.kind === "rich-text") {
1286
+ operations.push({
1287
+ op: "add",
1288
+ path: `/multilineFieldsFormat/${field.refName}`,
1289
+ value: "Markdown"
1290
+ });
1291
+ }
1292
+ }
1293
+ return operations;
1294
+ }
1295
+ function buildAppliedFields(fields) {
1296
+ const applied = {};
1297
+ for (const field of fields) {
1298
+ applied[field.refName] = field.value;
1299
+ }
1300
+ return applied;
1301
+ }
1302
+ function ensureTitleForCreate(fields) {
1303
+ const titleField = fields.find((field) => field.refName === "System.Title");
1304
+ if (!titleField || titleField.op === "clear" || titleField.value === null || titleField.value.trim() === "") {
1305
+ fail2("Title is required when creating a task.");
1306
+ }
1307
+ }
1308
+ function writeSuccess(result, options) {
1309
+ if (options.json) {
1310
+ process.stdout.write(`${JSON.stringify(result)}
1311
+ `);
1312
+ return;
1313
+ }
1314
+ const verb = result.action === "created" ? "Created" : "Updated";
1315
+ const fields = Object.keys(result.fields).join(", ");
1316
+ const suffix = fields ? ` (${fields})` : "";
1317
+ process.stdout.write(`${verb} task #${result.id}${suffix}
1318
+ `);
1319
+ }
1320
+ function cleanupSourceFile(sourceFile) {
1321
+ if (!sourceFile) {
1322
+ return;
1323
+ }
1324
+ try {
1325
+ unlinkSync(sourceFile);
1326
+ } catch {
1327
+ process.stderr.write(`Warning: upsert succeeded but could not delete source file: ${sourceFile}
1328
+ `);
1329
+ }
1330
+ }
1331
+ function buildUpsertResult(action, writeResult, fields) {
1332
+ const appliedFields = buildAppliedFields(fields);
1333
+ return {
1334
+ action,
1335
+ id: writeResult.id,
1336
+ fields: appliedFields
1337
+ };
1338
+ }
1339
+ function isUpdateWriteError(err) {
1340
+ return err.message === "AUTH_FAILED" || err.message === "PERMISSION_DENIED" || err.message === "NOT_FOUND" || err.message === "NETWORK_ERROR" || err.message.startsWith("BAD_REQUEST:") || err.message.startsWith("UPDATE_REJECTED:");
1341
+ }
1342
+ function isCreateWriteError(err) {
1343
+ return err.message === "AUTH_FAILED" || err.message === "PERMISSION_DENIED" || err.message === "NETWORK_ERROR" || err.message.startsWith("BAD_REQUEST:") || err.message.startsWith("HTTP_");
1344
+ }
1345
+ function handleUpsertError(err, id, context) {
1346
+ if (!(err instanceof Error)) {
1347
+ process.stderr.write(`Error: ${String(err)}
1348
+ `);
1349
+ process.exit(1);
1350
+ }
1351
+ if (id === void 0 && err.message.startsWith("CREATE_REJECTED:")) {
1352
+ process.stderr.write(`Error: ${formatCreateError(err)}
1353
+ `);
1354
+ process.exit(1);
1355
+ }
1356
+ if (id !== void 0 && isUpdateWriteError(err)) {
1357
+ handleCommandError(err, id, context, "write");
1358
+ return;
1359
+ }
1360
+ if (id === void 0 && isCreateWriteError(err)) {
1361
+ handleCommandError(err, 0, context, "write");
1362
+ return;
1363
+ }
1364
+ process.stderr.write(`Error: ${err.message}
1365
+ `);
1366
+ process.exit(1);
1367
+ }
1368
+ function createUpsertCommand() {
1369
+ const command = new Command9("upsert");
1370
+ command.description("Create or update a Task from a markdown document").argument("[id]", "work item ID to update; omit to create a new Task").option("--content <markdown>", "task document content").option("--file <path>", "read task document from file").option("--json", "output result as JSON").option("--org <org>", "Azure DevOps organization").option("--project <project>", "Azure DevOps project").action(async (idStr, options) => {
1371
+ validateOrgProjectPair(options);
1372
+ const id = idStr === void 0 ? void 0 : parseWorkItemId(idStr);
1373
+ const { content, sourceFile } = loadSourceContent(options);
1374
+ let context;
1375
+ try {
1376
+ context = resolveContext(options);
1377
+ const document = parseTaskDocument(content);
1378
+ const action = id === void 0 ? "created" : "updated";
1379
+ if (action === "created") {
1380
+ ensureTitleForCreate(document.fields);
1381
+ }
1382
+ const operations = toPatchOperations(document.fields, action);
1383
+ const credential = await resolvePat();
1384
+ let writeResult;
1385
+ if (action === "created") {
1386
+ writeResult = await createWorkItem(context, "Task", credential.pat, operations);
1387
+ } else {
1388
+ if (id === void 0) {
1389
+ fail2("Work item ID is required for updates.");
1390
+ }
1391
+ writeResult = await applyWorkItemPatch(context, id, credential.pat, operations);
1392
+ }
1393
+ const result = buildUpsertResult(action, writeResult, document.fields);
1394
+ writeSuccess(result, options);
1395
+ cleanupSourceFile(sourceFile);
1396
+ } catch (err) {
1397
+ handleUpsertError(err, id, context);
1398
+ }
1399
+ });
1400
+ return command;
1401
+ }
1402
+
1050
1403
  // src/index.ts
1051
- var program = new Command9();
1404
+ var program = new Command10();
1052
1405
  program.name("azdo").description("Azure DevOps CLI tool").version(version, "-v, --version");
1053
1406
  program.addCommand(createGetItemCommand());
1054
1407
  program.addCommand(createClearPatCommand());
@@ -1058,6 +1411,7 @@ program.addCommand(createAssignCommand());
1058
1411
  program.addCommand(createSetFieldCommand());
1059
1412
  program.addCommand(createGetMdFieldCommand());
1060
1413
  program.addCommand(createSetMdFieldCommand());
1414
+ program.addCommand(createUpsertCommand());
1061
1415
  program.showHelpAfterError();
1062
1416
  program.parse();
1063
1417
  if (process.argv.length <= 2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azdo-cli",
3
- "version": "0.2.0-develop.75",
3
+ "version": "0.2.0-develop.88",
4
4
  "description": "Azure DevOps CLI tool",
5
5
  "type": "module",
6
6
  "bin": {