Skip to content

Commit 2870b5d

Browse files
author
Danny McCormick
committed
Added wiki sample
1 parent 88063af commit 2870b5d

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

samples/samples.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"creation",
55
"task",
66
"filecontainer",
7-
"git"
7+
"git",
8+
"wiki"
89
]

samples/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"creation.ts",
1212
"task.ts",
1313
"filecontainer.ts",
14-
"git.ts"
14+
"git.ts",
15+
"wiki.ts"
1516
]
1617
}

samples/wiki.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as common from './common';
2+
import * as nodeApi from 'azure-devops-node-api';
3+
4+
import * as CoreApi from 'azure-devops-node-api/CoreApi'
5+
import * as CoreInterfaces from 'azure-devops-node-api/interfaces/CoreInterfaces'
6+
import * as WikiApi from 'azure-devops-node-api/WikiApi';
7+
import * as WikiInterfaces from 'azure-devops-node-api/interfaces/WikiInterfaces';
8+
9+
export async function run() {
10+
let webApi: nodeApi.WebApi = await common.getWebApi();
11+
let wikiApiObject: WikiApi.IWikiApi = await webApi.getWikiApi();
12+
let coreApiObject: CoreApi.ICoreApi = await webApi.getCoreApi();
13+
14+
common.banner('Wiki Samples');
15+
let project: string = common.getProject();
16+
let projectObject: CoreInterfaces.TeamProject = await coreApiObject.getProject(project);
17+
console.log('Project:', project);
18+
19+
common.heading('Get all wikis');
20+
const wikis: WikiInterfaces.WikiV2[] = await wikiApiObject.getAllWikis(project);
21+
console.log("Wikis", wikis.map((wiki) => wiki.name));
22+
23+
let wikiId: string;
24+
if (wikis.length > 0) {
25+
wikiId = wikis[0].id;
26+
}
27+
else {
28+
common.heading("Create a wiki");
29+
const wikiParams: WikiInterfaces.WikiCreateParametersV2 = <WikiInterfaces.WikiCreateParametersV2>{name: "Hello Wiki", projectId: projectObject.id};
30+
const newWiki = await wikiApiObject.createWiki(wikiParams, project);
31+
console.log("Wiki created:", newWiki.name);
32+
wikiId = newWiki.id;
33+
}
34+
35+
common.heading("Get the text from a wiki");
36+
const textStream: NodeJS.ReadableStream = await wikiApiObject.getPageText(project, wikiId)
37+
console.log("Wiki text", textStream.read().toString());
38+
39+
if (wikis.length == 0) {
40+
common.heading("Delete the created wiki");
41+
await wikiApiObject.deleteWiki(wikiId, project);
42+
console.log("Wiki deleted");
43+
}
44+
}

0 commit comments

Comments
 (0)