azdo-cli 0.22.0-feature-053-comments-edit-delete.824 → 0.22.0-feature-053-comments-edit-delete.826
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 +72 -95
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -916,16 +916,11 @@ async function listWorkItemComments(context, id, cred) {
|
|
|
916
916
|
comments
|
|
917
917
|
};
|
|
918
918
|
}
|
|
919
|
-
async function
|
|
920
|
-
const url = buildWorkItemCommentsUrl(context, id);
|
|
921
|
-
url.searchParams.set("format", format);
|
|
919
|
+
async function sendCommentRequest(url, cred, method, body) {
|
|
922
920
|
const response = await fetchWithErrors(url.toString(), {
|
|
923
|
-
method
|
|
924
|
-
headers: {
|
|
925
|
-
|
|
926
|
-
"Content-Type": "application/json"
|
|
927
|
-
},
|
|
928
|
-
body: JSON.stringify({ text })
|
|
921
|
+
method,
|
|
922
|
+
headers: body === void 0 ? authHeaders(cred) : { ...authHeaders(cred), "Content-Type": "application/json" },
|
|
923
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
929
924
|
});
|
|
930
925
|
if (response.status === 400) {
|
|
931
926
|
const serverMessage = await readResponseMessage(response) ?? "Unknown error";
|
|
@@ -934,38 +929,15 @@ async function addWorkItemComment(context, id, cred, text, format = "html") {
|
|
|
934
929
|
if (!response.ok) {
|
|
935
930
|
throw httpError(response);
|
|
936
931
|
}
|
|
937
|
-
|
|
938
|
-
return {
|
|
939
|
-
workItemId: data.workItemId ?? id,
|
|
940
|
-
commentId: data.commentId ?? data.id ?? 0,
|
|
941
|
-
text: typeof data.text === "string" ? data.text : text,
|
|
942
|
-
author: data.createdBy?.displayName ?? null,
|
|
943
|
-
createdAt: data.createdDate ?? null,
|
|
944
|
-
url: data.url ?? null
|
|
945
|
-
};
|
|
932
|
+
return response;
|
|
946
933
|
}
|
|
947
|
-
async function
|
|
948
|
-
const url = buildWorkItemCommentUrl(context, id, commentId);
|
|
934
|
+
async function writeCommentText(url, cred, method, text, format, fallback) {
|
|
949
935
|
url.searchParams.set("format", format);
|
|
950
|
-
const response = await
|
|
951
|
-
method: "PATCH",
|
|
952
|
-
headers: {
|
|
953
|
-
...authHeaders(cred),
|
|
954
|
-
"Content-Type": "application/json"
|
|
955
|
-
},
|
|
956
|
-
body: JSON.stringify({ text })
|
|
957
|
-
});
|
|
958
|
-
if (response.status === 400) {
|
|
959
|
-
const serverMessage = await readResponseMessage(response) ?? "Unknown error";
|
|
960
|
-
throw new Error(`BAD_REQUEST: ${serverMessage}`);
|
|
961
|
-
}
|
|
962
|
-
if (!response.ok) {
|
|
963
|
-
throw httpError(response);
|
|
964
|
-
}
|
|
936
|
+
const response = await sendCommentRequest(url, cred, method, { text });
|
|
965
937
|
const data = await response.json();
|
|
966
938
|
return {
|
|
967
|
-
workItemId: data.workItemId ??
|
|
968
|
-
commentId: data.commentId ?? data.id ?? commentId,
|
|
939
|
+
workItemId: data.workItemId ?? fallback.workItemId,
|
|
940
|
+
commentId: data.commentId ?? data.id ?? fallback.commentId,
|
|
969
941
|
text: typeof data.text === "string" ? data.text : text,
|
|
970
942
|
author: data.createdBy?.displayName ?? null,
|
|
971
943
|
createdAt: data.createdDate ?? null,
|
|
@@ -973,18 +945,32 @@ async function updateWorkItemComment(context, id, commentId, cred, text, format
|
|
|
973
945
|
url: data.url ?? null
|
|
974
946
|
};
|
|
975
947
|
}
|
|
976
|
-
async function
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
|
|
948
|
+
async function addWorkItemComment(context, id, cred, text, format = "html") {
|
|
949
|
+
const written = await writeCommentText(
|
|
950
|
+
buildWorkItemCommentsUrl(context, id),
|
|
951
|
+
cred,
|
|
952
|
+
"POST",
|
|
953
|
+
text,
|
|
954
|
+
format,
|
|
955
|
+
{ workItemId: id, commentId: 0 }
|
|
956
|
+
);
|
|
957
|
+
return {
|
|
958
|
+
workItemId: written.workItemId,
|
|
959
|
+
commentId: written.commentId,
|
|
960
|
+
text: written.text,
|
|
961
|
+
author: written.author,
|
|
962
|
+
createdAt: written.createdAt,
|
|
963
|
+
url: written.url
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
async function updateWorkItemComment(context, id, commentId, cred, text, format = "html") {
|
|
967
|
+
return writeCommentText(buildWorkItemCommentUrl(context, id, commentId), cred, "PATCH", text, format, {
|
|
968
|
+
workItemId: id,
|
|
969
|
+
commentId
|
|
980
970
|
});
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
}
|
|
985
|
-
if (!response.ok) {
|
|
986
|
-
throw httpError(response);
|
|
987
|
-
}
|
|
971
|
+
}
|
|
972
|
+
async function deleteWorkItemComment(context, id, commentId, cred) {
|
|
973
|
+
await sendCommentRequest(buildWorkItemCommentUrl(context, id, commentId), cred, "DELETE");
|
|
988
974
|
return { workItemId: id, commentId, deleted: true };
|
|
989
975
|
}
|
|
990
976
|
async function updateWorkItem(context, id, cred, fieldName, operations) {
|
|
@@ -7692,6 +7678,26 @@ function createPipelineCommand() {
|
|
|
7692
7678
|
|
|
7693
7679
|
// src/commands/comments.ts
|
|
7694
7680
|
import { Command as Command15 } from "commander";
|
|
7681
|
+
async function runCommentWrite(options, target, request, humanLine) {
|
|
7682
|
+
let context;
|
|
7683
|
+
try {
|
|
7684
|
+
context = resolveContext(options);
|
|
7685
|
+
const credential = await requireAuthCredential(context.org);
|
|
7686
|
+
const result = await request(context, credential);
|
|
7687
|
+
process.stdout.write(options.json ? `${JSON.stringify(result, null, 2)}
|
|
7688
|
+
` : `${humanLine(result)}
|
|
7689
|
+
`);
|
|
7690
|
+
} catch (err) {
|
|
7691
|
+
if (target.commentId === void 0) {
|
|
7692
|
+
handleCommandError(err, target.id, context, "write");
|
|
7693
|
+
} else {
|
|
7694
|
+
handleCommentWriteError(err, target.id, target.commentId, context);
|
|
7695
|
+
}
|
|
7696
|
+
}
|
|
7697
|
+
}
|
|
7698
|
+
function commentFormat(options) {
|
|
7699
|
+
return options.markdown === true ? "markdown" : "html";
|
|
7700
|
+
}
|
|
7695
7701
|
function writeError3(message) {
|
|
7696
7702
|
process.stderr.write(`Error: ${message}
|
|
7697
7703
|
`);
|
|
@@ -7746,22 +7752,12 @@ function createCommentsAddCommand() {
|
|
|
7746
7752
|
if (text.trim() === "") {
|
|
7747
7753
|
writeError3("Comment text must be a non-empty string.");
|
|
7748
7754
|
}
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
if (options.json) {
|
|
7756
|
-
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
7757
|
-
`);
|
|
7758
|
-
return;
|
|
7759
|
-
}
|
|
7760
|
-
process.stdout.write(`Added comment #${result.commentId} to work item #${result.workItemId}
|
|
7761
|
-
`);
|
|
7762
|
-
} catch (err) {
|
|
7763
|
-
handleCommandError(err, id, context, "write");
|
|
7764
|
-
}
|
|
7755
|
+
await runCommentWrite(
|
|
7756
|
+
options,
|
|
7757
|
+
{ id },
|
|
7758
|
+
(context, credential) => addWorkItemComment(context, id, credential, text, commentFormat(options)),
|
|
7759
|
+
(result) => `Added comment #${result.commentId} to work item #${result.workItemId}`
|
|
7760
|
+
);
|
|
7765
7761
|
});
|
|
7766
7762
|
return command;
|
|
7767
7763
|
}
|
|
@@ -7803,22 +7799,12 @@ function createCommentsEditCommand() {
|
|
|
7803
7799
|
const id = parseWorkItemId(idStr);
|
|
7804
7800
|
const commentId = parseCommentId(commentIdStr);
|
|
7805
7801
|
const body = resolveEditText(text, options.file);
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
if (options.json) {
|
|
7813
|
-
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
7814
|
-
`);
|
|
7815
|
-
return;
|
|
7816
|
-
}
|
|
7817
|
-
process.stdout.write(`Updated comment #${result.commentId} on work item #${result.workItemId}
|
|
7818
|
-
`);
|
|
7819
|
-
} catch (err) {
|
|
7820
|
-
handleCommentWriteError(err, id, commentId, context);
|
|
7821
|
-
}
|
|
7802
|
+
await runCommentWrite(
|
|
7803
|
+
options,
|
|
7804
|
+
{ id, commentId },
|
|
7805
|
+
(context, credential) => updateWorkItemComment(context, id, commentId, credential, body, commentFormat(options)),
|
|
7806
|
+
(result) => `Updated comment #${result.commentId} on work item #${result.workItemId}`
|
|
7807
|
+
);
|
|
7822
7808
|
});
|
|
7823
7809
|
return command;
|
|
7824
7810
|
}
|
|
@@ -7828,21 +7814,12 @@ function createCommentsDeleteCommand() {
|
|
|
7828
7814
|
validateOrgProjectPair(options);
|
|
7829
7815
|
const id = parseWorkItemId(idStr);
|
|
7830
7816
|
const commentId = parseCommentId(commentIdStr);
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
7838
|
-
`);
|
|
7839
|
-
return;
|
|
7840
|
-
}
|
|
7841
|
-
process.stdout.write(`Deleted comment #${result.commentId} from work item #${result.workItemId}
|
|
7842
|
-
`);
|
|
7843
|
-
} catch (err) {
|
|
7844
|
-
handleCommentWriteError(err, id, commentId, context);
|
|
7845
|
-
}
|
|
7817
|
+
await runCommentWrite(
|
|
7818
|
+
options,
|
|
7819
|
+
{ id, commentId },
|
|
7820
|
+
(context, credential) => deleteWorkItemComment(context, id, commentId, credential),
|
|
7821
|
+
(result) => `Deleted comment #${result.commentId} from work item #${result.workItemId}`
|
|
7822
|
+
);
|
|
7846
7823
|
});
|
|
7847
7824
|
return command;
|
|
7848
7825
|
}
|