azdo-cli 0.10.0-develop.479 → 0.10.0-develop.490
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/README.md +8 -0
- package/dist/index.js +296 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,6 +68,14 @@ azdo pipeline get-runs 12 --branch develop --limit 1
|
|
|
68
68
|
azdo pipeline wait 3456 # blocks; exit 0 success / non-zero failure / 124 timeout
|
|
69
69
|
azdo pipeline get-run-detail 3456 # errors, failing tests, per-stage status
|
|
70
70
|
azdo pipeline start 12 --branch develop --parameter env=staging
|
|
71
|
+
|
|
72
|
+
# Work item relations — types, add, remove, list
|
|
73
|
+
azdo relations types # list all relation types (Child, Parent, Related, ...)
|
|
74
|
+
azdo relations types --json # machine-readable JSON array
|
|
75
|
+
azdo relations add child 1000 2000 # make #2000 a child of #1000 (idempotent)
|
|
76
|
+
azdo relations remove child 1000 2000 # remove the child relation
|
|
77
|
+
azdo relations list 1000 # show all relations on work item #1000
|
|
78
|
+
azdo relations list 1000 --json # JSON: { workItemId, relations: [...] }
|
|
71
79
|
```
|
|
72
80
|
|
|
73
81
|
## Documentation
|
package/dist/index.js
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
} from "./chunk-XVXMDWQE.js";
|
|
39
39
|
|
|
40
40
|
// src/index.ts
|
|
41
|
-
import { Command as
|
|
41
|
+
import { Command as Command17 } from "commander";
|
|
42
42
|
|
|
43
43
|
// src/version.ts
|
|
44
44
|
import { readFileSync } from "fs";
|
|
@@ -4703,6 +4703,299 @@ function createDownloadAttachmentCommand() {
|
|
|
4703
4703
|
return command;
|
|
4704
4704
|
}
|
|
4705
4705
|
|
|
4706
|
+
// src/commands/relations.ts
|
|
4707
|
+
import { Command as Command16 } from "commander";
|
|
4708
|
+
|
|
4709
|
+
// src/services/relations-client.ts
|
|
4710
|
+
var API_VERSION2 = "7.1";
|
|
4711
|
+
function buildRelationTypesUrl(context) {
|
|
4712
|
+
const url = new URL(
|
|
4713
|
+
`https://dev.azure.com/${encodeURIComponent(context.org)}/_apis/wit/workitemrelationtypes`
|
|
4714
|
+
);
|
|
4715
|
+
url.searchParams.set("api-version", API_VERSION2);
|
|
4716
|
+
return url;
|
|
4717
|
+
}
|
|
4718
|
+
function buildWorkItemUrl2(context, id, expand) {
|
|
4719
|
+
const url = new URL(
|
|
4720
|
+
`https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/${id}`
|
|
4721
|
+
);
|
|
4722
|
+
url.searchParams.set("api-version", API_VERSION2);
|
|
4723
|
+
if (expand) url.searchParams.set("$expand", expand);
|
|
4724
|
+
return url;
|
|
4725
|
+
}
|
|
4726
|
+
function buildBatchWorkItemsUrl(context, ids) {
|
|
4727
|
+
const url = new URL(
|
|
4728
|
+
`https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems`
|
|
4729
|
+
);
|
|
4730
|
+
url.searchParams.set("ids", ids.join(","));
|
|
4731
|
+
url.searchParams.set("fields", "System.Id,System.Title");
|
|
4732
|
+
url.searchParams.set("api-version", API_VERSION2);
|
|
4733
|
+
return url;
|
|
4734
|
+
}
|
|
4735
|
+
function mapRelationType(raw) {
|
|
4736
|
+
return {
|
|
4737
|
+
referenceName: raw.referenceName,
|
|
4738
|
+
name: raw.name,
|
|
4739
|
+
usage: raw.attributes?.usage ?? "unknown",
|
|
4740
|
+
enabled: raw.attributes?.enabled !== false,
|
|
4741
|
+
directional: raw.attributes?.directional ?? null
|
|
4742
|
+
};
|
|
4743
|
+
}
|
|
4744
|
+
async function readJsonResponse3(response) {
|
|
4745
|
+
if (!response.ok) throw new Error(`HTTP_${response.status}`);
|
|
4746
|
+
return await response.json();
|
|
4747
|
+
}
|
|
4748
|
+
function parseTargetId(url) {
|
|
4749
|
+
const match = /\/workItems\/(\d+)$/i.exec(url);
|
|
4750
|
+
return match ? Number(match[1]) : null;
|
|
4751
|
+
}
|
|
4752
|
+
async function getWorkItemRelationTypes(context, cred) {
|
|
4753
|
+
const url = buildRelationTypesUrl(context);
|
|
4754
|
+
const response = await fetchWithErrors(url.toString(), {
|
|
4755
|
+
headers: authHeaders(cred)
|
|
4756
|
+
});
|
|
4757
|
+
const body = await readJsonResponse3(response);
|
|
4758
|
+
return (body.value ?? []).map(mapRelationType).filter((t) => t.usage === "workItemLink" && t.enabled);
|
|
4759
|
+
}
|
|
4760
|
+
async function resolveRelationType(context, cred, alias) {
|
|
4761
|
+
const types = await getWorkItemRelationTypes(context, cred);
|
|
4762
|
+
const lower = alias.toLowerCase();
|
|
4763
|
+
const match = types.find((t) => t.name.toLowerCase() === lower);
|
|
4764
|
+
if (!match) throw new Error(`UNKNOWN_RELATION_TYPE:${alias}`);
|
|
4765
|
+
return match;
|
|
4766
|
+
}
|
|
4767
|
+
async function getWorkItemWithRelations(context, cred, id) {
|
|
4768
|
+
const url = buildWorkItemUrl2(context, id, "relations");
|
|
4769
|
+
const response = await fetchWithErrors(url.toString(), {
|
|
4770
|
+
headers: authHeaders(cred)
|
|
4771
|
+
});
|
|
4772
|
+
return readJsonResponse3(response);
|
|
4773
|
+
}
|
|
4774
|
+
async function addWorkItemRelation(context, cred, type, id1, id2) {
|
|
4775
|
+
if (id1 === id2) throw new Error("SELF_RELATION");
|
|
4776
|
+
const relType = await resolveRelationType(context, cred, type);
|
|
4777
|
+
const workItem = await getWorkItemWithRelations(context, cred, id1);
|
|
4778
|
+
const targetUrl = `https://dev.azure.com/${encodeURIComponent(context.org)}/_apis/wit/workItems/${id2}`;
|
|
4779
|
+
const existing = (workItem.relations ?? []).find(
|
|
4780
|
+
(r) => r.rel === relType.referenceName && r.url.toLowerCase() === targetUrl.toLowerCase()
|
|
4781
|
+
);
|
|
4782
|
+
if (existing) {
|
|
4783
|
+
return { status: "already_exists", type: relType.name, referenceName: relType.referenceName, id1, id2 };
|
|
4784
|
+
}
|
|
4785
|
+
const patchUrl = buildWorkItemUrl2(context, id1);
|
|
4786
|
+
const response = await fetchWithErrors(patchUrl.toString(), {
|
|
4787
|
+
method: "PATCH",
|
|
4788
|
+
headers: { ...authHeaders(cred), "Content-Type": "application/json-patch+json" },
|
|
4789
|
+
body: JSON.stringify([
|
|
4790
|
+
{ op: "add", path: "/relations/-", value: { rel: relType.referenceName, url: targetUrl } }
|
|
4791
|
+
])
|
|
4792
|
+
});
|
|
4793
|
+
if (!response.ok) throw new Error(`HTTP_${response.status}`);
|
|
4794
|
+
return { status: "added", type: relType.name, referenceName: relType.referenceName, id1, id2 };
|
|
4795
|
+
}
|
|
4796
|
+
async function removeWorkItemRelation(context, cred, type, id1, id2) {
|
|
4797
|
+
if (id1 === id2) throw new Error("SELF_RELATION");
|
|
4798
|
+
const relType = await resolveRelationType(context, cred, type);
|
|
4799
|
+
const workItem = await getWorkItemWithRelations(context, cred, id1);
|
|
4800
|
+
const relations = workItem.relations ?? [];
|
|
4801
|
+
const index = relations.findIndex(
|
|
4802
|
+
(r) => r.rel === relType.referenceName && parseTargetId(r.url) === id2
|
|
4803
|
+
);
|
|
4804
|
+
if (index === -1) {
|
|
4805
|
+
return { status: "not_found", type: relType.name, referenceName: relType.referenceName, id1, id2 };
|
|
4806
|
+
}
|
|
4807
|
+
const patchUrl = buildWorkItemUrl2(context, id1);
|
|
4808
|
+
const response = await fetchWithErrors(patchUrl.toString(), {
|
|
4809
|
+
method: "PATCH",
|
|
4810
|
+
headers: { ...authHeaders(cred), "Content-Type": "application/json-patch+json" },
|
|
4811
|
+
body: JSON.stringify([{ op: "remove", path: `/relations/${index}` }])
|
|
4812
|
+
});
|
|
4813
|
+
if (!response.ok) throw new Error(`HTTP_${response.status}`);
|
|
4814
|
+
return { status: "removed", type: relType.name, referenceName: relType.referenceName, id1, id2 };
|
|
4815
|
+
}
|
|
4816
|
+
async function listWorkItemRelations(context, cred, id) {
|
|
4817
|
+
const workItem = await getWorkItemWithRelations(context, cred, id);
|
|
4818
|
+
const allRelations = workItem.relations ?? [];
|
|
4819
|
+
const wiRelations = allRelations.filter(
|
|
4820
|
+
(r) => !r.rel.startsWith("AttachedFile") && !r.rel.startsWith("Hyperlink") && !r.rel.startsWith("ArtifactLink")
|
|
4821
|
+
);
|
|
4822
|
+
if (wiRelations.length === 0) {
|
|
4823
|
+
return { workItemId: id, relations: [] };
|
|
4824
|
+
}
|
|
4825
|
+
const types = await getWorkItemRelationTypes(context, cred);
|
|
4826
|
+
const typeNameMap = new Map(types.map((t) => [t.referenceName, t.name]));
|
|
4827
|
+
const targetIds = wiRelations.map((r) => parseTargetId(r.url)).filter((n) => n !== null);
|
|
4828
|
+
const titleMap = /* @__PURE__ */ new Map();
|
|
4829
|
+
if (targetIds.length > 0) {
|
|
4830
|
+
try {
|
|
4831
|
+
const batchUrl = buildBatchWorkItemsUrl(context, targetIds);
|
|
4832
|
+
const batchResponse = await fetchWithErrors(batchUrl.toString(), {
|
|
4833
|
+
headers: authHeaders(cred)
|
|
4834
|
+
});
|
|
4835
|
+
const batchBody = await readJsonResponse3(batchResponse);
|
|
4836
|
+
for (const item of batchBody.value ?? []) {
|
|
4837
|
+
titleMap.set(item.id, item.fields["System.Title"] ?? "");
|
|
4838
|
+
}
|
|
4839
|
+
} catch {
|
|
4840
|
+
}
|
|
4841
|
+
}
|
|
4842
|
+
const relations = wiRelations.map((r) => {
|
|
4843
|
+
const targetId = parseTargetId(r.url);
|
|
4844
|
+
return {
|
|
4845
|
+
rel: r.rel,
|
|
4846
|
+
relName: typeNameMap.get(r.rel) ?? r.rel,
|
|
4847
|
+
targetId: targetId ?? 0,
|
|
4848
|
+
targetTitle: targetId !== null ? titleMap.get(targetId) ?? null : null,
|
|
4849
|
+
targetUrl: r.url,
|
|
4850
|
+
comment: r.attributes?.comment ?? null
|
|
4851
|
+
};
|
|
4852
|
+
});
|
|
4853
|
+
return { workItemId: id, relations };
|
|
4854
|
+
}
|
|
4855
|
+
|
|
4856
|
+
// src/commands/relations.ts
|
|
4857
|
+
function addCommonOptions(cmd) {
|
|
4858
|
+
return cmd.option("--json", "Output as JSON").option("--org <org>", "Azure DevOps organization").option("--project <project>", "Azure DevOps project");
|
|
4859
|
+
}
|
|
4860
|
+
async function resolveCredentials(opts) {
|
|
4861
|
+
const context = resolveContext(opts);
|
|
4862
|
+
const cred = await requireAuthCredential(context.org);
|
|
4863
|
+
return { context, cred };
|
|
4864
|
+
}
|
|
4865
|
+
function formatRelationTypes(types) {
|
|
4866
|
+
if (types.length === 0) return "No work item relation types found.";
|
|
4867
|
+
const nameWidth = Math.max(...types.map((t) => t.name.length), 4);
|
|
4868
|
+
const lines = ["Available work item relation types:", ""];
|
|
4869
|
+
for (const t of types) {
|
|
4870
|
+
lines.push(`${t.name.padEnd(nameWidth + 2)}${t.referenceName}`);
|
|
4871
|
+
}
|
|
4872
|
+
return lines.join("\n");
|
|
4873
|
+
}
|
|
4874
|
+
function formatRelationsList(workItemId, relations) {
|
|
4875
|
+
if (relations.length === 0) return `Work item #${workItemId} has no relations.`;
|
|
4876
|
+
const typeWidth = Math.max(...relations.map((r) => r.relName.length), 4) + 2;
|
|
4877
|
+
const idWidth = Math.max(...relations.map((r) => String(r.targetId).length), 4) + 1;
|
|
4878
|
+
const lines = [`Relations for work item #${workItemId}:`, ""];
|
|
4879
|
+
for (const r of relations) {
|
|
4880
|
+
const typeLabel = `[${r.relName}]`.padEnd(typeWidth);
|
|
4881
|
+
const idLabel = `#${r.targetId}`.padEnd(idWidth);
|
|
4882
|
+
lines.push(`${typeLabel} ${idLabel} ${r.targetTitle ?? "(unknown)"}`);
|
|
4883
|
+
}
|
|
4884
|
+
return lines.join("\n");
|
|
4885
|
+
}
|
|
4886
|
+
function handleRelationError(err, id1) {
|
|
4887
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4888
|
+
if (msg === "SELF_RELATION") {
|
|
4889
|
+
process.stderr.write(`Error: cannot relate a work item to itself (#${id1}).
|
|
4890
|
+
`);
|
|
4891
|
+
} else if (msg.startsWith("UNKNOWN_RELATION_TYPE:")) {
|
|
4892
|
+
const name = msg.replace("UNKNOWN_RELATION_TYPE:", "");
|
|
4893
|
+
process.stderr.write(
|
|
4894
|
+
`Error: unknown relation type "${name}". Run 'azdo relations types' to see valid names.
|
|
4895
|
+
`
|
|
4896
|
+
);
|
|
4897
|
+
} else if (msg.startsWith("NOT_FOUND")) {
|
|
4898
|
+
const target = id1 !== void 0 ? id1 : "unknown";
|
|
4899
|
+
process.stderr.write(`Error: work item #${target} not found.
|
|
4900
|
+
`);
|
|
4901
|
+
} else if (msg === "AUTH_FAILED") {
|
|
4902
|
+
process.stderr.write(
|
|
4903
|
+
`Error: authentication failed. Check your PAT has Work Items \u2192 Read & Write scope.
|
|
4904
|
+
`
|
|
4905
|
+
);
|
|
4906
|
+
} else {
|
|
4907
|
+
process.stderr.write(`Error: ${msg}
|
|
4908
|
+
`);
|
|
4909
|
+
}
|
|
4910
|
+
process.exit(1);
|
|
4911
|
+
}
|
|
4912
|
+
function parsePositiveInt(value, label) {
|
|
4913
|
+
const n = Number(value);
|
|
4914
|
+
if (!Number.isInteger(n) || n <= 0) {
|
|
4915
|
+
process.stderr.write(`Error: ${label} must be a positive integer.
|
|
4916
|
+
`);
|
|
4917
|
+
process.exit(1);
|
|
4918
|
+
}
|
|
4919
|
+
return n;
|
|
4920
|
+
}
|
|
4921
|
+
function createRelationsCommand() {
|
|
4922
|
+
const relations = new Command16("relations").description("Manage work item relations");
|
|
4923
|
+
addCommonOptions(
|
|
4924
|
+
relations.command("types").description("List all available work item relation types")
|
|
4925
|
+
).action(async (opts) => {
|
|
4926
|
+
try {
|
|
4927
|
+
const { context, cred } = await resolveCredentials(opts);
|
|
4928
|
+
const types = await getWorkItemRelationTypes(context, cred);
|
|
4929
|
+
if (opts.json) {
|
|
4930
|
+
process.stdout.write(JSON.stringify(types, null, 2) + "\n");
|
|
4931
|
+
} else {
|
|
4932
|
+
process.stdout.write(formatRelationTypes(types) + "\n");
|
|
4933
|
+
}
|
|
4934
|
+
} catch (err) {
|
|
4935
|
+
handleRelationError(err);
|
|
4936
|
+
}
|
|
4937
|
+
});
|
|
4938
|
+
addCommonOptions(
|
|
4939
|
+
relations.command("add <type> <id1> <id2>").description("Add a directed relation from work item <id1> to <id2>")
|
|
4940
|
+
).action(async (type, id1Str, id2Str, opts) => {
|
|
4941
|
+
const id1 = parsePositiveInt(id1Str, "id1");
|
|
4942
|
+
const id2 = parsePositiveInt(id2Str, "id2");
|
|
4943
|
+
try {
|
|
4944
|
+
const { context, cred } = await resolveCredentials(opts);
|
|
4945
|
+
const result = await addWorkItemRelation(context, cred, type, id1, id2);
|
|
4946
|
+
if (opts.json) {
|
|
4947
|
+
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
4948
|
+
} else if (result.status === "already_exists") {
|
|
4949
|
+
process.stdout.write(`Relation already exists: #${id1} --[${result.type}]--> #${id2}
|
|
4950
|
+
`);
|
|
4951
|
+
} else {
|
|
4952
|
+
process.stdout.write(`Added relation: #${id1} --[${result.type}]--> #${id2}
|
|
4953
|
+
`);
|
|
4954
|
+
}
|
|
4955
|
+
} catch (err) {
|
|
4956
|
+
handleRelationError(err, id1);
|
|
4957
|
+
}
|
|
4958
|
+
});
|
|
4959
|
+
addCommonOptions(
|
|
4960
|
+
relations.command("remove <type> <id1> <id2>").description("Remove a directed relation of <type> from work item <id1> to <id2>")
|
|
4961
|
+
).action(async (type, id1Str, id2Str, opts) => {
|
|
4962
|
+
const id1 = parsePositiveInt(id1Str, "id1");
|
|
4963
|
+
const id2 = parsePositiveInt(id2Str, "id2");
|
|
4964
|
+
try {
|
|
4965
|
+
const { context, cred } = await resolveCredentials(opts);
|
|
4966
|
+
const result = await removeWorkItemRelation(context, cred, type, id1, id2);
|
|
4967
|
+
if (opts.json) {
|
|
4968
|
+
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
4969
|
+
} else if (result.status === "not_found") {
|
|
4970
|
+
process.stdout.write(`No relation of type '${result.type}' found between #${id1} and #${id2}
|
|
4971
|
+
`);
|
|
4972
|
+
} else {
|
|
4973
|
+
process.stdout.write(`Removed relation: #${id1} --[${result.type}]--> #${id2}
|
|
4974
|
+
`);
|
|
4975
|
+
}
|
|
4976
|
+
} catch (err) {
|
|
4977
|
+
handleRelationError(err, id1);
|
|
4978
|
+
}
|
|
4979
|
+
});
|
|
4980
|
+
addCommonOptions(
|
|
4981
|
+
relations.command("list <id>").description("List all work item link relations on a work item")
|
|
4982
|
+
).action(async (idStr, opts) => {
|
|
4983
|
+
const id = parsePositiveInt(idStr, "id");
|
|
4984
|
+
try {
|
|
4985
|
+
const { context, cred } = await resolveCredentials(opts);
|
|
4986
|
+
const result = await listWorkItemRelations(context, cred, id);
|
|
4987
|
+
if (opts.json) {
|
|
4988
|
+
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
4989
|
+
} else {
|
|
4990
|
+
process.stdout.write(formatRelationsList(result.workItemId, result.relations) + "\n");
|
|
4991
|
+
}
|
|
4992
|
+
} catch (err) {
|
|
4993
|
+
handleRelationError(err, id);
|
|
4994
|
+
}
|
|
4995
|
+
});
|
|
4996
|
+
return relations;
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4706
4999
|
// src/services/update-check.ts
|
|
4707
5000
|
import fs2 from "fs";
|
|
4708
5001
|
import path2 from "path";
|
|
@@ -4816,7 +5109,7 @@ function exitOnEpipe(err) {
|
|
|
4816
5109
|
}
|
|
4817
5110
|
process.stdout.on("error", exitOnEpipe);
|
|
4818
5111
|
process.stderr.on("error", exitOnEpipe);
|
|
4819
|
-
var program = new
|
|
5112
|
+
var program = new Command17();
|
|
4820
5113
|
program.name("azdo").description("Azure DevOps CLI tool").version(version, "-v, --version");
|
|
4821
5114
|
program.option("--no-update-check", "Skip the check for a newer published version");
|
|
4822
5115
|
program.addCommand(createGetItemCommand());
|
|
@@ -4834,6 +5127,7 @@ program.addCommand(createPrCommand());
|
|
|
4834
5127
|
program.addCommand(createPipelineCommand());
|
|
4835
5128
|
program.addCommand(createCommentsCommand());
|
|
4836
5129
|
program.addCommand(createDownloadAttachmentCommand());
|
|
5130
|
+
program.addCommand(createRelationsCommand());
|
|
4837
5131
|
program.showHelpAfterError();
|
|
4838
5132
|
program.hook("postAction", async () => {
|
|
4839
5133
|
const notice = await getUpdateNotice({ enabled: program.opts().updateCheck });
|