forked from microsoft/azure-devops-node-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
filecontainer.ts
46 lines (39 loc) · 1.65 KB
/
filecontainer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as cm from "./common";
import * as vm from "azure-devops-node-api";
import * as ti from "azure-devops-node-api/interfaces/FileContainerInterfaces";
export async function run() {
try
{
let vsts: vm.WebApi = await cm.getWebApi();
let fileContainerApi = await vsts.getFileContainerApi();
let containers = await fileContainerApi.getContainers(null, null);
if (containers.length > 0) {
let container = containers[0];
console.log(`found container ${container.name}`);
let containerId = container.id;
let items = await fileContainerApi.getItems(containerId, null, null, null, null, null, null, false);
console.log(`found ${items.length} items`);
let item = items.filter((item) => {
return item.itemType === ti.ContainerItemType.File;
})[0];
if (item) {
console.log(`downloading ${item.path}`);
let restResponse = await fileContainerApi.getItem(containerId, null, item.path, item.path.substring(item.path.lastIndexOf("/") + 1));
let output = "";
await new Promise((resolve, reject) => {
restResponse.result.on("data", (chunk) => {
output += chunk;
});
restResponse.result.on("end", () => {
resolve(output);
});
});
console.log(`downloaded ${item.path}`);
console.log(output);
}
}
}
catch (err) {
console.error(`Error: ${err.stack}`);
}
}