azdo-cli 0.24.0-develop.902 → 0.24.0-feature-059-delete-item.906
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 +73 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
} from "./chunk-DNOOZIXA.js";
|
|
49
49
|
|
|
50
50
|
// src/program.ts
|
|
51
|
-
import { Command as
|
|
51
|
+
import { Command as Command21 } from "commander";
|
|
52
52
|
|
|
53
53
|
// src/version.ts
|
|
54
54
|
import { readFileSync } from "fs";
|
|
@@ -967,6 +967,25 @@ async function applyWorkItemPatch(context, id, cred, operations) {
|
|
|
967
967
|
});
|
|
968
968
|
return readWriteResponse(response, "UPDATE_REJECTED");
|
|
969
969
|
}
|
|
970
|
+
async function deleteWorkItem(context, id, cred, permanent = false) {
|
|
971
|
+
const url = new URL(
|
|
972
|
+
`https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/${id}`
|
|
973
|
+
);
|
|
974
|
+
if (permanent) url.searchParams.set("destroy", "true");
|
|
975
|
+
url.searchParams.set("api-version", "7.1");
|
|
976
|
+
const response = await fetchWithErrors(url.toString(), {
|
|
977
|
+
method: "DELETE",
|
|
978
|
+
headers: authHeaders(cred)
|
|
979
|
+
});
|
|
980
|
+
if (response.status === 400) {
|
|
981
|
+
const serverMessage = await readResponseMessage(response) ?? "Unknown error";
|
|
982
|
+
throw new Error(`BAD_REQUEST: ${serverMessage}`);
|
|
983
|
+
}
|
|
984
|
+
if (!response.ok) {
|
|
985
|
+
throw httpError(response);
|
|
986
|
+
}
|
|
987
|
+
return { id, permanent };
|
|
988
|
+
}
|
|
970
989
|
async function downloadAttachment(url, cred) {
|
|
971
990
|
const response = await fetchWithErrors(url, { headers: authHeaders(cred) });
|
|
972
991
|
if (!response.ok) {
|
|
@@ -8004,8 +8023,57 @@ function createDeleteAttachmentCommand() {
|
|
|
8004
8023
|
return command;
|
|
8005
8024
|
}
|
|
8006
8025
|
|
|
8007
|
-
// src/commands/
|
|
8026
|
+
// src/commands/delete-item.ts
|
|
8008
8027
|
import { Command as Command19 } from "commander";
|
|
8028
|
+
function createDeleteItemCommand() {
|
|
8029
|
+
const command = new Command19("delete-item");
|
|
8030
|
+
command.description("Delete an Azure DevOps work item (moves it to the Recycle Bin unless --permanent)").argument("<id>", "work item ID").option("--permanent", "destroy the work item permanently instead of moving it to the Recycle Bin").option("-y, --yes", "skip the interactive confirmation prompt").option("--json", "output { id, permanent, deleted }").option("--org <org>", "Azure DevOps organization").option("--project <project>", "Azure DevOps project").action(
|
|
8031
|
+
async (idStr, options) => {
|
|
8032
|
+
const id = parseWorkItemId(idStr);
|
|
8033
|
+
validateOrgProjectPair(options);
|
|
8034
|
+
const permanent = options.permanent === true;
|
|
8035
|
+
let context;
|
|
8036
|
+
try {
|
|
8037
|
+
context = resolveContext(options);
|
|
8038
|
+
const credential = await requireAuthCredential(context.org);
|
|
8039
|
+
let confirmed = options.yes === true;
|
|
8040
|
+
if (!confirmed) {
|
|
8041
|
+
if (!process.stdin.isTTY) {
|
|
8042
|
+
process.stderr.write(
|
|
8043
|
+
"Error: confirmation required. Re-run with --yes to skip the prompt in a non-interactive shell.\n"
|
|
8044
|
+
);
|
|
8045
|
+
process.exitCode = 1;
|
|
8046
|
+
return;
|
|
8047
|
+
}
|
|
8048
|
+
const question = permanent ? `Permanently delete work item ${id}? This cannot be undone. [y/N] ` : `Delete work item ${id} (moves it to the Recycle Bin)? [y/N] `;
|
|
8049
|
+
confirmed = await promptYesNo(question);
|
|
8050
|
+
}
|
|
8051
|
+
if (!confirmed) {
|
|
8052
|
+
process.stderr.write("Aborted: work item not deleted.\n");
|
|
8053
|
+
process.exitCode = 1;
|
|
8054
|
+
return;
|
|
8055
|
+
}
|
|
8056
|
+
await deleteWorkItem(context, id, credential, permanent);
|
|
8057
|
+
if (options.json) {
|
|
8058
|
+
process.stdout.write(`${JSON.stringify({ id, permanent, deleted: true }, null, 2)}
|
|
8059
|
+
`);
|
|
8060
|
+
} else {
|
|
8061
|
+
process.stdout.write(
|
|
8062
|
+
permanent ? `Permanently deleted work item ${id}
|
|
8063
|
+
` : `Deleted work item ${id}
|
|
8064
|
+
`
|
|
8065
|
+
);
|
|
8066
|
+
}
|
|
8067
|
+
} catch (err) {
|
|
8068
|
+
handleCommandError(err, id, context, "write");
|
|
8069
|
+
}
|
|
8070
|
+
}
|
|
8071
|
+
);
|
|
8072
|
+
return command;
|
|
8073
|
+
}
|
|
8074
|
+
|
|
8075
|
+
// src/commands/relations.ts
|
|
8076
|
+
import { Command as Command20 } from "commander";
|
|
8009
8077
|
|
|
8010
8078
|
// src/services/relations-client.ts
|
|
8011
8079
|
var API_VERSION2 = "7.1";
|
|
@@ -8222,7 +8290,7 @@ function parsePositiveInt(value, label) {
|
|
|
8222
8290
|
return n;
|
|
8223
8291
|
}
|
|
8224
8292
|
function createRelationsCommand() {
|
|
8225
|
-
const relations = new
|
|
8293
|
+
const relations = new Command20("relations").description("Manage work item relations");
|
|
8226
8294
|
addCommonOptions(
|
|
8227
8295
|
relations.command("types").description("List all available work item relation types")
|
|
8228
8296
|
).action(async (opts) => {
|
|
@@ -8417,7 +8485,7 @@ async function getUpdateNotice(opts) {
|
|
|
8417
8485
|
|
|
8418
8486
|
// src/program.ts
|
|
8419
8487
|
function createProgram() {
|
|
8420
|
-
const program2 = new
|
|
8488
|
+
const program2 = new Command21();
|
|
8421
8489
|
program2.name("azdo").description("Azure DevOps CLI tool").version(version, "-v, --version");
|
|
8422
8490
|
program2.option("--no-update-check", "Skip the check for a newer published version");
|
|
8423
8491
|
program2.option("--trace <filepath>", "Append redacted HTTP request/response trace to a file (owner-read-only permissions)");
|
|
@@ -8439,6 +8507,7 @@ function createProgram() {
|
|
|
8439
8507
|
program2.addCommand(createDownloadAttachmentCommand());
|
|
8440
8508
|
program2.addCommand(createAddAttachmentCommand());
|
|
8441
8509
|
program2.addCommand(createDeleteAttachmentCommand());
|
|
8510
|
+
program2.addCommand(createDeleteItemCommand());
|
|
8442
8511
|
program2.addCommand(createRelationsCommand());
|
|
8443
8512
|
program2.showHelpAfterError();
|
|
8444
8513
|
program2.hook("preAction", () => {
|