Skip to content

Commit a31bfae

Browse files
authored
fix samples (#588)
1 parent b0f028c commit a31bfae

File tree

4 files changed

+121
-42
lines changed

4 files changed

+121
-42
lines changed

samples/creation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function run() {
5858
/********** Dashboard **********/
5959
printSectionStart("Dashboard");
6060
const dashboardApi = await vstsCollectionLevel.getDashboardApi();
61-
const widgetTypes: WidgetTypesResponse = await dashboardApi.getWidgetTypes(WidgetScope.Collection_User);
61+
const widgetTypes: WidgetTypesResponse = await dashboardApi.getWidgetTypes(WidgetScope.Collection_User, common.getProject());
6262

6363
if (widgetTypes) {
6464
console.log(`found ${widgetTypes.widgetTypes.length} widget types`);

samples/dashboard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function run(projectId: string) {
5757
typeId: null,
5858
url: null
5959
};
60-
const widgetMetadata: DashboardInterfaces.WidgetMetadataResponse = await dashboardApiObject.getWidgetMetadata('ms.vss-dashboards-web.Microsoft.VisualStudioOnline.Dashboards.OtherLinksWidget');
60+
const widgetMetadata: DashboardInterfaces.WidgetMetadataResponse = await dashboardApiObject.getWidgetMetadata('ms.vss-dashboards-web.Microsoft.VisualStudioOnline.Dashboards.OtherLinksWidget', projectId);
6161
console.log('Creating widget with metadata:', widgetMetadata);
6262
widget = await dashboardApiObject.createWidget(widget, teamContext, dashboard.id);
6363
//Ensure its been created and we can get it.
@@ -72,7 +72,7 @@ export async function run(projectId: string) {
7272
console.log('Widget name updated to', widget.name);
7373

7474
common.heading('Get Widget data');
75-
const widgetTypes: DashboardInterfaces.WidgetTypesResponse = await dashboardApiObject.getWidgetTypes(DashboardInterfaces.WidgetScope.Project_Team);
75+
const widgetTypes: DashboardInterfaces.WidgetTypesResponse = await dashboardApiObject.getWidgetTypes(DashboardInterfaces.WidgetScope.Project_Team, projectId);
7676
console.log('First widget type:', widgetTypes.widgetTypes[0]);
7777

7878
common.heading('Delete a widget');

samples/package-lock.json

Lines changed: 103 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/run.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let samples: string[] = require("./samples.json");
1212
let coreApi: cApi.ICoreApi;
1313
const maxLoops: number = 500;
1414

15-
let selection: string = process.argv[2];
15+
const selection: string = process.argv[2];
1616
if (selection) {
1717
if (samples.indexOf(selection) == -1) {
1818
console.error("Not a valid sample. See list of samples");
@@ -41,7 +41,19 @@ async function createProject(projectId: string): Promise<boolean> {
4141
revision: null,
4242
state: null,
4343
url: null};
44-
await coreApi.queueCreateProject(projectToCreate);
44+
let num = 0;
45+
while (num < maxLoops) {
46+
try {
47+
await coreApi.queueCreateProject(projectToCreate);
48+
break;
49+
} catch (err) {
50+
const errTypeKey = err.result.typeKey.toString();
51+
if (!(errTypeKey == 'ProjectWorkPendingException' || errTypeKey == 'ProjectAlreadyExistsException')) {
52+
throw err;
53+
}
54+
num++;
55+
}
56+
}
4557

4658
//Poll until project exists
4759
let project: coreInterfaces.TeamProject = null;
@@ -114,11 +126,4 @@ async function runSamples(selected?: string) {
114126
}
115127
}
116128

117-
function run() {
118-
runSamples();
119-
}
120-
121-
runSamples(process.argv[2]);
122-
123-
124-
129+
runSamples(selection);

0 commit comments

Comments
 (0)