azdo-cli 0.2.0-develop.24 → 0.2.0-develop.41
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 +20 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,15 +37,18 @@ function buildExtraFields(fields, requested) {
|
|
|
37
37
|
return Object.keys(result).length > 0 ? result : null;
|
|
38
38
|
}
|
|
39
39
|
async function getWorkItem(context, id, pat, extraFields) {
|
|
40
|
-
|
|
40
|
+
const url = new URL(
|
|
41
|
+
`https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/${id}`
|
|
42
|
+
);
|
|
43
|
+
url.searchParams.set("api-version", "7.1");
|
|
41
44
|
if (extraFields && extraFields.length > 0) {
|
|
42
45
|
const allFields = [...DEFAULT_FIELDS, ...extraFields];
|
|
43
|
-
url
|
|
46
|
+
url.searchParams.set("fields", allFields.join(","));
|
|
44
47
|
}
|
|
45
48
|
const token = Buffer.from(`:${pat}`).toString("base64");
|
|
46
49
|
let response;
|
|
47
50
|
try {
|
|
48
|
-
response = await fetch(url, {
|
|
51
|
+
response = await fetch(url.toString(), {
|
|
49
52
|
headers: {
|
|
50
53
|
Authorization: `Basic ${token}`
|
|
51
54
|
}
|
|
@@ -91,11 +94,14 @@ async function getWorkItem(context, id, pat, extraFields) {
|
|
|
91
94
|
};
|
|
92
95
|
}
|
|
93
96
|
async function updateWorkItem(context, id, pat, fieldName, operations) {
|
|
94
|
-
const url =
|
|
97
|
+
const url = new URL(
|
|
98
|
+
`https://dev.azure.com/${encodeURIComponent(context.org)}/${encodeURIComponent(context.project)}/_apis/wit/workitems/${id}`
|
|
99
|
+
);
|
|
100
|
+
url.searchParams.set("api-version", "7.1");
|
|
95
101
|
const token = Buffer.from(`:${pat}`).toString("base64");
|
|
96
102
|
let response;
|
|
97
103
|
try {
|
|
98
|
-
response = await fetch(url, {
|
|
104
|
+
response = await fetch(url.toString(), {
|
|
99
105
|
method: "PATCH",
|
|
100
106
|
headers: {
|
|
101
107
|
Authorization: `Basic ${token}`,
|
|
@@ -166,6 +172,10 @@ async function deletePat() {
|
|
|
166
172
|
}
|
|
167
173
|
|
|
168
174
|
// src/services/auth.ts
|
|
175
|
+
function normalizePat(rawPat) {
|
|
176
|
+
const trimmedPat = rawPat.trim();
|
|
177
|
+
return trimmedPat.length > 0 ? trimmedPat : null;
|
|
178
|
+
}
|
|
169
179
|
async function promptForPat() {
|
|
170
180
|
if (!process.stdin.isTTY) {
|
|
171
181
|
return null;
|
|
@@ -217,8 +227,11 @@ async function resolvePat() {
|
|
|
217
227
|
}
|
|
218
228
|
const promptedPat = await promptForPat();
|
|
219
229
|
if (promptedPat !== null) {
|
|
220
|
-
|
|
221
|
-
|
|
230
|
+
const normalizedPat = normalizePat(promptedPat);
|
|
231
|
+
if (normalizedPat !== null) {
|
|
232
|
+
await storePat(normalizedPat);
|
|
233
|
+
return { pat: normalizedPat, source: "prompt" };
|
|
234
|
+
}
|
|
222
235
|
}
|
|
223
236
|
throw new Error(
|
|
224
237
|
"Authentication cancelled. Set AZDO_PAT environment variable or run again to enter a PAT."
|