azdo-cli 0.24.0-feature-059-delete-item.906 → 0.24.0-feature-060-pr-comment-anchor.908
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 +239 -121
- 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 Command20 } from "commander";
|
|
52
52
|
|
|
53
53
|
// src/version.ts
|
|
54
54
|
import { readFileSync } from "fs";
|
|
@@ -967,25 +967,6 @@ 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
|
-
}
|
|
989
970
|
async function downloadAttachment(url, cred) {
|
|
990
971
|
const response = await fetchWithErrors(url, { headers: authHeaders(cred) });
|
|
991
972
|
if (!response.ok) {
|
|
@@ -4315,7 +4296,7 @@ async function getPullRequestThread(context, repo, cred, prId, threadId) {
|
|
|
4315
4296
|
const data = await readJsonResponse(response);
|
|
4316
4297
|
return toActiveCommentThread(data);
|
|
4317
4298
|
}
|
|
4318
|
-
async function createPullRequestThread(context, repo, cred, prId, content, status2) {
|
|
4299
|
+
async function createPullRequestThread(context, repo, cred, prId, content, status2, anchor) {
|
|
4319
4300
|
const url = new URL(
|
|
4320
4301
|
`https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/git/repositories/${encodeURIComponent(repo)}/pullRequests/${prId}/threads`
|
|
4321
4302
|
);
|
|
@@ -4326,6 +4307,10 @@ async function createPullRequestThread(context, repo, cred, prId, content, statu
|
|
|
4326
4307
|
if (status2 !== void 0) {
|
|
4327
4308
|
payload.status = status2;
|
|
4328
4309
|
}
|
|
4310
|
+
if (anchor !== void 0) {
|
|
4311
|
+
payload.threadContext = anchor.threadContext;
|
|
4312
|
+
payload.pullRequestThreadContext = anchor.pullRequestThreadContext;
|
|
4313
|
+
}
|
|
4329
4314
|
const response = await fetchWithErrors(url.toString(), {
|
|
4330
4315
|
method: "POST",
|
|
4331
4316
|
headers: {
|
|
@@ -4337,6 +4322,42 @@ async function createPullRequestThread(context, repo, cred, prId, content, statu
|
|
|
4337
4322
|
const data = await readJsonResponse(response);
|
|
4338
4323
|
return toActiveCommentThread(data);
|
|
4339
4324
|
}
|
|
4325
|
+
function buildIterationsUrl(context, repo, prId, suffix = "") {
|
|
4326
|
+
const url = new URL(
|
|
4327
|
+
`https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/git/repositories/${encodeURIComponent(repo)}/pullRequests/${prId}/iterations${suffix}`
|
|
4328
|
+
);
|
|
4329
|
+
url.searchParams.set("api-version", "7.1");
|
|
4330
|
+
return url;
|
|
4331
|
+
}
|
|
4332
|
+
async function getLatestPullRequestIterationId(context, repo, cred, prId) {
|
|
4333
|
+
const url = buildIterationsUrl(context, repo, prId);
|
|
4334
|
+
const response = await fetchWithErrors(url.toString(), { headers: authHeaders(cred) });
|
|
4335
|
+
const data = await readJsonResponse(response);
|
|
4336
|
+
const ids = (data.value ?? []).map((iteration) => iteration.id);
|
|
4337
|
+
if (ids.length === 0) {
|
|
4338
|
+
throw new Error(`Pull request #${prId} has no iterations.`);
|
|
4339
|
+
}
|
|
4340
|
+
return Math.max(...ids);
|
|
4341
|
+
}
|
|
4342
|
+
async function getPullRequestIterationChanges(context, repo, cred, prId, iterationId) {
|
|
4343
|
+
const changes = [];
|
|
4344
|
+
let skip = 0;
|
|
4345
|
+
for (; ; ) {
|
|
4346
|
+
const url = buildIterationsUrl(context, repo, prId, `/${iterationId}/changes`);
|
|
4347
|
+
url.searchParams.set("$top", "2000");
|
|
4348
|
+
if (skip > 0) {
|
|
4349
|
+
url.searchParams.set("$skip", String(skip));
|
|
4350
|
+
}
|
|
4351
|
+
const response = await fetchWithErrors(url.toString(), { headers: authHeaders(cred) });
|
|
4352
|
+
const page = await readJsonResponse(response);
|
|
4353
|
+
changes.push(...page.changeEntries ?? []);
|
|
4354
|
+
const next = page.nextSkip ?? 0;
|
|
4355
|
+
if (next <= skip) {
|
|
4356
|
+
return changes;
|
|
4357
|
+
}
|
|
4358
|
+
skip = next;
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4340
4361
|
function buildThreadCommentUrl(context, repo, prId, threadId) {
|
|
4341
4362
|
const url = new URL(
|
|
4342
4363
|
`https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/git/repositories/${encodeURIComponent(repo)}/pullRequests/${prId}/threads/${threadId}/comments`
|
|
@@ -4660,6 +4681,35 @@ async function resolvePullRequestTemplate(context, repo, cred, defaultBranch, ta
|
|
|
4660
4681
|
return firstMatchingTemplate(context, repo, cred, defaultBranch, defaultTemplateCandidates(), "default");
|
|
4661
4682
|
}
|
|
4662
4683
|
|
|
4684
|
+
// src/services/thread-anchor.ts
|
|
4685
|
+
var LINE_END_OFFSET = 1e3;
|
|
4686
|
+
function normalizeThreadFilePath(raw) {
|
|
4687
|
+
let path5 = raw.trim().replaceAll("\\", "/");
|
|
4688
|
+
while (path5.startsWith("./")) {
|
|
4689
|
+
path5 = path5.slice(2);
|
|
4690
|
+
}
|
|
4691
|
+
path5 = path5.replace(/^\/+/, "");
|
|
4692
|
+
return path5 === "" ? null : `/${path5}`;
|
|
4693
|
+
}
|
|
4694
|
+
function buildThreadAnchorContext(filePath, line, endLine, side) {
|
|
4695
|
+
const start = { line, offset: 1 };
|
|
4696
|
+
const end = { line: endLine, offset: LINE_END_OFFSET };
|
|
4697
|
+
return side === "right" ? { filePath, rightFileStart: start, rightFileEnd: end } : { filePath, leftFileStart: start, leftFileEnd: end };
|
|
4698
|
+
}
|
|
4699
|
+
function buildPullRequestThreadContext(iterationId, changeTrackingId) {
|
|
4700
|
+
const context = {
|
|
4701
|
+
iterationContext: { firstComparingIteration: 1, secondComparingIteration: iterationId }
|
|
4702
|
+
};
|
|
4703
|
+
if (changeTrackingId !== void 0) {
|
|
4704
|
+
context.changeTrackingId = changeTrackingId;
|
|
4705
|
+
}
|
|
4706
|
+
return context;
|
|
4707
|
+
}
|
|
4708
|
+
function findChangeTrackingId(changes, filePath, side) {
|
|
4709
|
+
const match = changes.find((change) => change.item?.path === filePath) ?? (side === "left" ? changes.find((change) => change.originalPath === filePath) : void 0);
|
|
4710
|
+
return match?.changeTrackingId;
|
|
4711
|
+
}
|
|
4712
|
+
|
|
4663
4713
|
// src/commands/pr.ts
|
|
4664
4714
|
function parsePositivePrNumber(raw) {
|
|
4665
4715
|
if (!/^\d+$/.test(raw)) {
|
|
@@ -5813,6 +5863,130 @@ var CREATABLE_THREAD_STATUSES = [
|
|
|
5813
5863
|
"byDesign",
|
|
5814
5864
|
"pending"
|
|
5815
5865
|
];
|
|
5866
|
+
var THREAD_ANCHOR_SIDES = ["right", "left"];
|
|
5867
|
+
function parseCommentAddStatus(raw) {
|
|
5868
|
+
if (raw === void 0) {
|
|
5869
|
+
return void 0;
|
|
5870
|
+
}
|
|
5871
|
+
const match = CREATABLE_THREAD_STATUSES.find((candidate) => candidate === raw);
|
|
5872
|
+
if (match === void 0) {
|
|
5873
|
+
writeError(`Invalid --status "${raw}"; expected one of ${CREATABLE_THREAD_STATUSES.join(", ")}.`);
|
|
5874
|
+
return null;
|
|
5875
|
+
}
|
|
5876
|
+
return match;
|
|
5877
|
+
}
|
|
5878
|
+
function parseLineOption(flag, raw) {
|
|
5879
|
+
const value = parsePositivePrNumber(raw);
|
|
5880
|
+
if (value === null) {
|
|
5881
|
+
writeError(`Invalid ${flag} "${raw}"; expected a positive integer (1-based line number).`);
|
|
5882
|
+
}
|
|
5883
|
+
return value;
|
|
5884
|
+
}
|
|
5885
|
+
function parseCommentAnchorOptions(options) {
|
|
5886
|
+
if (options.filePath === void 0) {
|
|
5887
|
+
const stray = [
|
|
5888
|
+
["--line", options.line],
|
|
5889
|
+
["--end-line", options.endLine],
|
|
5890
|
+
["--side", options.side],
|
|
5891
|
+
["--allow-unchanged-file", options.allowUnchangedFile]
|
|
5892
|
+
].find(([, value]) => value !== void 0);
|
|
5893
|
+
if (stray !== void 0) {
|
|
5894
|
+
writeError(`${stray[0]} requires --file-path.`);
|
|
5895
|
+
return null;
|
|
5896
|
+
}
|
|
5897
|
+
return void 0;
|
|
5898
|
+
}
|
|
5899
|
+
if (options.line === void 0) {
|
|
5900
|
+
writeError("--file-path requires --line.");
|
|
5901
|
+
return null;
|
|
5902
|
+
}
|
|
5903
|
+
const filePath = normalizeThreadFilePath(options.filePath);
|
|
5904
|
+
if (filePath === null) {
|
|
5905
|
+
writeError(`Invalid --file-path "${options.filePath}"; expected a repository file path.`);
|
|
5906
|
+
return null;
|
|
5907
|
+
}
|
|
5908
|
+
const line = parseLineOption("--line", options.line);
|
|
5909
|
+
if (line === null) {
|
|
5910
|
+
return null;
|
|
5911
|
+
}
|
|
5912
|
+
const endLine = options.endLine === void 0 ? line : parseLineOption("--end-line", options.endLine);
|
|
5913
|
+
if (endLine === null) {
|
|
5914
|
+
return null;
|
|
5915
|
+
}
|
|
5916
|
+
if (endLine < line) {
|
|
5917
|
+
writeError(`--end-line (${endLine}) must not be less than --line (${line}).`);
|
|
5918
|
+
return null;
|
|
5919
|
+
}
|
|
5920
|
+
const side = THREAD_ANCHOR_SIDES.find((candidate) => candidate === (options.side ?? "right"));
|
|
5921
|
+
if (side === void 0) {
|
|
5922
|
+
writeError(`Invalid --side "${options.side}"; expected ${THREAD_ANCHOR_SIDES.join(" or ")}.`);
|
|
5923
|
+
return null;
|
|
5924
|
+
}
|
|
5925
|
+
return { filePath, line, endLine, side, allowUnchangedFile: options.allowUnchangedFile === true };
|
|
5926
|
+
}
|
|
5927
|
+
async function resolveCommentAnchor(target, request) {
|
|
5928
|
+
const prId = target.pullRequest.id;
|
|
5929
|
+
const iterationId = await getLatestPullRequestIterationId(target.context, target.repo, target.pat, prId);
|
|
5930
|
+
const changes = await getPullRequestIterationChanges(target.context, target.repo, target.pat, prId, iterationId);
|
|
5931
|
+
const changeTrackingId = findChangeTrackingId(changes, request.filePath, request.side);
|
|
5932
|
+
if (changeTrackingId === void 0 && !request.allowUnchangedFile) {
|
|
5933
|
+
writeError(
|
|
5934
|
+
`${request.filePath} is not among the files changed by pull request #${prId} (iteration ${iterationId}). Check the path, or pass --allow-unchanged-file to post the comment anyway.`,
|
|
5935
|
+
3
|
|
5936
|
+
);
|
|
5937
|
+
return null;
|
|
5938
|
+
}
|
|
5939
|
+
return {
|
|
5940
|
+
request,
|
|
5941
|
+
iterationId,
|
|
5942
|
+
changeTrackingId,
|
|
5943
|
+
threadContext: buildThreadAnchorContext(request.filePath, request.line, request.endLine, request.side),
|
|
5944
|
+
pullRequestThreadContext: buildPullRequestThreadContext(iterationId, changeTrackingId)
|
|
5945
|
+
};
|
|
5946
|
+
}
|
|
5947
|
+
function describeCommentAnchor(anchor) {
|
|
5948
|
+
const { filePath, line, endLine, side } = anchor.request;
|
|
5949
|
+
const lines = line === endLine ? `line ${line}` : `lines ${line}-${endLine}`;
|
|
5950
|
+
const tracking = anchor.changeTrackingId === void 0 ? "no changeTrackingId" : `changeTrackingId ${anchor.changeTrackingId}`;
|
|
5951
|
+
return ` at ${filePath} ${lines} (${side} side, iteration ${anchor.iterationId}, ${tracking})`;
|
|
5952
|
+
}
|
|
5953
|
+
function warnIfUntracked(anchor) {
|
|
5954
|
+
if (anchor !== void 0 && anchor.changeTrackingId === void 0) {
|
|
5955
|
+
process.stderr.write(
|
|
5956
|
+
`Note: ${anchor.request.filePath} is not among the pull request's changed files, so the thread is posted without a changeTrackingId and will not follow the line across later pushes.
|
|
5957
|
+
`
|
|
5958
|
+
);
|
|
5959
|
+
}
|
|
5960
|
+
}
|
|
5961
|
+
function withAnchorFields(result, anchor) {
|
|
5962
|
+
if (anchor === void 0) {
|
|
5963
|
+
return result;
|
|
5964
|
+
}
|
|
5965
|
+
return {
|
|
5966
|
+
...result,
|
|
5967
|
+
threadContext: anchor.threadContext,
|
|
5968
|
+
pullRequestThreadContext: anchor.pullRequestThreadContext,
|
|
5969
|
+
changeTracked: anchor.changeTrackingId !== void 0
|
|
5970
|
+
};
|
|
5971
|
+
}
|
|
5972
|
+
function writeCommentAddDryRun(prId, body, status2, anchor, json) {
|
|
5973
|
+
if (json) {
|
|
5974
|
+
const dryResult = withAnchorFields(
|
|
5975
|
+
{ pullRequestId: prId, threadId: null, commentId: null, status: status2 ?? null, content: body, dryRun: true },
|
|
5976
|
+
anchor
|
|
5977
|
+
);
|
|
5978
|
+
process.stdout.write(`${JSON.stringify(dryResult, null, 2)}
|
|
5979
|
+
`);
|
|
5980
|
+
return;
|
|
5981
|
+
}
|
|
5982
|
+
const statusSuffix = status2 === void 0 ? "" : ` with status ${status2}`;
|
|
5983
|
+
const anchorSuffix = anchor === void 0 ? "" : describeCommentAnchor(anchor);
|
|
5984
|
+
process.stdout.write(
|
|
5985
|
+
`Dry run: would post a new comment thread${statusSuffix} on pull request #${prId}${anchorSuffix} (${body.length} chars).
|
|
5986
|
+
${body}
|
|
5987
|
+
`
|
|
5988
|
+
);
|
|
5989
|
+
}
|
|
5816
5990
|
async function runCommentAdd(text, options) {
|
|
5817
5991
|
let context;
|
|
5818
5992
|
try {
|
|
@@ -5820,16 +5994,13 @@ async function runCommentAdd(text, options) {
|
|
|
5820
5994
|
if (body === null) {
|
|
5821
5995
|
return;
|
|
5822
5996
|
}
|
|
5823
|
-
|
|
5824
|
-
if (
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
return;
|
|
5831
|
-
}
|
|
5832
|
-
status2 = match;
|
|
5997
|
+
const status2 = parseCommentAddStatus(options.status);
|
|
5998
|
+
if (status2 === null) {
|
|
5999
|
+
return;
|
|
6000
|
+
}
|
|
6001
|
+
const anchorRequest = parseCommentAnchorOptions(options);
|
|
6002
|
+
if (anchorRequest === null) {
|
|
6003
|
+
return;
|
|
5833
6004
|
}
|
|
5834
6005
|
const target = await resolvePullRequestTarget(options, {
|
|
5835
6006
|
onContextResolved: (resolved) => {
|
|
@@ -5839,26 +6010,13 @@ async function runCommentAdd(text, options) {
|
|
|
5839
6010
|
if (target === null) {
|
|
5840
6011
|
return;
|
|
5841
6012
|
}
|
|
6013
|
+
const anchor = anchorRequest === void 0 ? void 0 : await resolveCommentAnchor(target, anchorRequest);
|
|
6014
|
+
if (anchor === null) {
|
|
6015
|
+
return;
|
|
6016
|
+
}
|
|
6017
|
+
warnIfUntracked(anchor);
|
|
5842
6018
|
if (options.dryRun === true) {
|
|
5843
|
-
|
|
5844
|
-
pullRequestId: target.pullRequest.id,
|
|
5845
|
-
threadId: null,
|
|
5846
|
-
commentId: null,
|
|
5847
|
-
status: status2 ?? null,
|
|
5848
|
-
content: body,
|
|
5849
|
-
dryRun: true
|
|
5850
|
-
};
|
|
5851
|
-
if (options.json) {
|
|
5852
|
-
process.stdout.write(`${JSON.stringify(dryResult, null, 2)}
|
|
5853
|
-
`);
|
|
5854
|
-
return;
|
|
5855
|
-
}
|
|
5856
|
-
const statusSuffix = status2 === void 0 ? "" : ` with status ${status2}`;
|
|
5857
|
-
process.stdout.write(
|
|
5858
|
-
`Dry run: would post a new comment thread${statusSuffix} on pull request #${target.pullRequest.id} (${body.length} chars).
|
|
5859
|
-
${body}
|
|
5860
|
-
`
|
|
5861
|
-
);
|
|
6019
|
+
writeCommentAddDryRun(target.pullRequest.id, body, status2, anchor, options.json);
|
|
5862
6020
|
return;
|
|
5863
6021
|
}
|
|
5864
6022
|
const thread = await createPullRequestThread(
|
|
@@ -5867,24 +6025,29 @@ ${body}
|
|
|
5867
6025
|
target.pat,
|
|
5868
6026
|
target.pullRequest.id,
|
|
5869
6027
|
body,
|
|
5870
|
-
status2
|
|
6028
|
+
status2,
|
|
6029
|
+
...anchor === void 0 ? [] : [{ threadContext: anchor.threadContext, pullRequestThreadContext: anchor.pullRequestThreadContext }]
|
|
5871
6030
|
);
|
|
5872
6031
|
const created = thread.comments[0];
|
|
5873
|
-
const result =
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
6032
|
+
const result = withAnchorFields(
|
|
6033
|
+
{
|
|
6034
|
+
pullRequestId: target.pullRequest.id,
|
|
6035
|
+
threadId: thread.id,
|
|
6036
|
+
commentId: created?.id ?? null,
|
|
6037
|
+
status: thread.status,
|
|
6038
|
+
content: created?.content ?? body,
|
|
6039
|
+
dryRun: false
|
|
6040
|
+
},
|
|
6041
|
+
anchor
|
|
6042
|
+
);
|
|
5881
6043
|
if (options.json) {
|
|
5882
6044
|
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
5883
6045
|
`);
|
|
5884
6046
|
return;
|
|
5885
6047
|
}
|
|
6048
|
+
const anchorSuffix = anchor === void 0 ? "" : describeCommentAnchor(anchor);
|
|
5886
6049
|
process.stdout.write(
|
|
5887
|
-
`Comment posted to pull request #${target.pullRequest.id} (thread #${thread.id}).
|
|
6050
|
+
`Comment posted to pull request #${target.pullRequest.id} (thread #${thread.id})${anchorSuffix}.
|
|
5888
6051
|
`
|
|
5889
6052
|
);
|
|
5890
6053
|
} catch (err) {
|
|
@@ -5896,18 +6059,21 @@ function buildCommentAddCommand(name, description) {
|
|
|
5896
6059
|
withCommonPrOptions(configureUnwrappedHelp(command)).description(description).argument("[text]", "body of the new comment; omit when using --file").option("--file <path>", "read the comment body from a UTF-8 file instead of the inline argument").option(
|
|
5897
6060
|
"--status <status>",
|
|
5898
6061
|
`thread status (${CREATABLE_THREAD_STATUSES.join(" | ")}); omit for a plain, non-resolvable comment`
|
|
6062
|
+
).option("--file-path <path>", "anchor the thread to this repository file (Files tab); requires --line").option("--line <n>", "first line of the anchored range (1-based)").option("--end-line <n>", "last line of the anchored range (default: --line)").option("--side <side>", "right (new version, default) or left (old version, for deleted lines)").option(
|
|
6063
|
+
"--allow-unchanged-file",
|
|
6064
|
+
"post even when --file-path is not among the pull request's changed files (the thread will not follow the line across pushes)"
|
|
5899
6065
|
).option("--dry-run", "resolve the target pull request and print what would be posted, without writing anything").option("--pr-number <N>", PR_NUMBER_HELP).option("--json", "output JSON").action(async (text, _options, command2) => {
|
|
5900
6066
|
await runCommentAdd(text, mergedPrOptions(command2));
|
|
5901
6067
|
});
|
|
5902
6068
|
return command;
|
|
5903
6069
|
}
|
|
5904
6070
|
function createPrCommentsAddCommand() {
|
|
5905
|
-
return buildCommentAddCommand("add", "Post a new comment thread on the pull request overview");
|
|
6071
|
+
return buildCommentAddCommand("add", "Post a new comment thread on the pull request overview, or on a file and line");
|
|
5906
6072
|
}
|
|
5907
6073
|
function createPrCommentAddCommand() {
|
|
5908
6074
|
return buildCommentAddCommand(
|
|
5909
6075
|
"comment-add",
|
|
5910
|
-
'Post a new comment thread on the pull request overview (alias of "azdo pr comments add")'
|
|
6076
|
+
'Post a new comment thread on the pull request overview, or on a file and line (alias of "azdo pr comments add")'
|
|
5911
6077
|
);
|
|
5912
6078
|
}
|
|
5913
6079
|
function parseExplicitCommentId(options) {
|
|
@@ -6197,13 +6363,15 @@ async function attachWorkItemIds(context, repo, cred, pullRequests) {
|
|
|
6197
6363
|
const result = new Array(pullRequests.length);
|
|
6198
6364
|
let next = 0;
|
|
6199
6365
|
const worker = async () => {
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
next += 1;
|
|
6203
|
-
const pullRequest = pullRequests[index];
|
|
6204
|
-
const workItemIds = await getPullRequestWorkItemIds(context, repo, cred, pullRequest.id);
|
|
6205
|
-
result[index] = { ...pullRequest, workItemIds };
|
|
6366
|
+
if (next >= pullRequests.length) {
|
|
6367
|
+
return;
|
|
6206
6368
|
}
|
|
6369
|
+
const index = next;
|
|
6370
|
+
next += 1;
|
|
6371
|
+
const pullRequest = pullRequests[index];
|
|
6372
|
+
const workItemIds = await getPullRequestWorkItemIds(context, repo, cred, pullRequest.id);
|
|
6373
|
+
result[index] = { ...pullRequest, workItemIds };
|
|
6374
|
+
await worker();
|
|
6207
6375
|
};
|
|
6208
6376
|
await Promise.all(Array.from({ length: Math.min(WORK_ITEM_LOOKUP_CONCURRENCY, pullRequests.length) }, worker));
|
|
6209
6377
|
return result;
|
|
@@ -8023,57 +8191,8 @@ function createDeleteAttachmentCommand() {
|
|
|
8023
8191
|
return command;
|
|
8024
8192
|
}
|
|
8025
8193
|
|
|
8026
|
-
// src/commands/delete-item.ts
|
|
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
8194
|
// src/commands/relations.ts
|
|
8076
|
-
import { Command as
|
|
8195
|
+
import { Command as Command19 } from "commander";
|
|
8077
8196
|
|
|
8078
8197
|
// src/services/relations-client.ts
|
|
8079
8198
|
var API_VERSION2 = "7.1";
|
|
@@ -8290,7 +8409,7 @@ function parsePositiveInt(value, label) {
|
|
|
8290
8409
|
return n;
|
|
8291
8410
|
}
|
|
8292
8411
|
function createRelationsCommand() {
|
|
8293
|
-
const relations = new
|
|
8412
|
+
const relations = new Command19("relations").description("Manage work item relations");
|
|
8294
8413
|
addCommonOptions(
|
|
8295
8414
|
relations.command("types").description("List all available work item relation types")
|
|
8296
8415
|
).action(async (opts) => {
|
|
@@ -8485,7 +8604,7 @@ async function getUpdateNotice(opts) {
|
|
|
8485
8604
|
|
|
8486
8605
|
// src/program.ts
|
|
8487
8606
|
function createProgram() {
|
|
8488
|
-
const program2 = new
|
|
8607
|
+
const program2 = new Command20();
|
|
8489
8608
|
program2.name("azdo").description("Azure DevOps CLI tool").version(version, "-v, --version");
|
|
8490
8609
|
program2.option("--no-update-check", "Skip the check for a newer published version");
|
|
8491
8610
|
program2.option("--trace <filepath>", "Append redacted HTTP request/response trace to a file (owner-read-only permissions)");
|
|
@@ -8507,7 +8626,6 @@ function createProgram() {
|
|
|
8507
8626
|
program2.addCommand(createDownloadAttachmentCommand());
|
|
8508
8627
|
program2.addCommand(createAddAttachmentCommand());
|
|
8509
8628
|
program2.addCommand(createDeleteAttachmentCommand());
|
|
8510
|
-
program2.addCommand(createDeleteItemCommand());
|
|
8511
8629
|
program2.addCommand(createRelationsCommand());
|
|
8512
8630
|
program2.showHelpAfterError();
|
|
8513
8631
|
program2.hook("preAction", () => {
|