@@ -7,38 +7,38 @@ import * as WikiApi from 'azure-devops-node-api/WikiApi';
77import * as WikiInterfaces from 'azure-devops-node-api/interfaces/WikiInterfaces' ;
88
99export 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 ( ) ;
10+ const webApi : nodeApi . WebApi = await common . getWebApi ( ) ;
11+ const wikiApiObject : WikiApi . IWikiApi = await webApi . getWikiApi ( ) ;
12+ const coreApiObject : CoreApi . ICoreApi = await webApi . getCoreApi ( ) ;
1313
1414 common . banner ( 'Wiki Samples' ) ;
15- let project : string = common . getProject ( ) ;
16- let projectObject : CoreInterfaces . TeamProject = await coreApiObject . getProject ( project ) ;
15+ const project : string = common . getProject ( ) ;
16+ const projectObject : CoreInterfaces . TeamProject = await coreApiObject . getProject ( project ) ;
1717 console . log ( 'Project:' , project ) ;
1818
1919 common . heading ( 'Get all wikis' ) ;
2020 const wikis : WikiInterfaces . WikiV2 [ ] = await wikiApiObject . getAllWikis ( project ) ;
2121 console . log ( "Wikis" , wikis . map ( ( wiki ) => wiki . name ) ) ;
2222
2323 let wikiId : string ;
24- if ( wikis . length > 0 ) {
25- wikiId = wikis [ 0 ] . id ;
26- }
27- else {
24+ const createNewWiki : boolean = ( wikis . length === 0 ) ;
25+ if ( createNewWiki ) {
2826 common . heading ( "Create a wiki" ) ;
2927 const wikiParams : WikiInterfaces . WikiCreateParametersV2 = < WikiInterfaces . WikiCreateParametersV2 > { name : "Hello Wiki" , projectId : projectObject . id } ;
3028 const newWiki = await wikiApiObject . createWiki ( wikiParams , project ) ;
3129 console . log ( "Wiki created:" , newWiki . name ) ;
3230 wikiId = newWiki . id ;
31+ } else {
32+ wikiId = wikis [ 0 ] . id ;
3333 }
3434
3535 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 ( ) ) ;
36+ const pageText : NodeJS . ReadableStream = await wikiApiObject . getPageText ( project , wikiId )
37+ console . log ( "Wiki text" , pageText . read ( ) . toString ( ) ) ;
3838
39- if ( wikis . length == 0 ) {
39+ if ( createNewWiki ) {
4040 common . heading ( "Delete the created wiki" ) ;
41- await wikiApiObject . deleteWiki ( wikiId , project ) ;
42- console . log ( "Wiki deleted" ) ;
41+ const deletedWiki : WikiInterfaces . WikiV2 = await wikiApiObject . deleteWiki ( wikiId , project ) ;
42+ console . log ( "Wiki" , deletedWiki . name , " deleted") ;
4343 }
4444}
0 commit comments