Skip to content

Commit

Permalink
fix samples (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisRumyantsev committed Mar 7, 2024
1 parent b0f028c commit a31bfae
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 42 deletions.
2 changes: 1 addition & 1 deletion samples/creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function run() {
/********** Dashboard **********/
printSectionStart("Dashboard");
const dashboardApi = await vstsCollectionLevel.getDashboardApi();
const widgetTypes: WidgetTypesResponse = await dashboardApi.getWidgetTypes(WidgetScope.Collection_User);
const widgetTypes: WidgetTypesResponse = await dashboardApi.getWidgetTypes(WidgetScope.Collection_User, common.getProject());

if (widgetTypes) {
console.log(`found ${widgetTypes.widgetTypes.length} widget types`);
Expand Down
4 changes: 2 additions & 2 deletions samples/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function run(projectId: string) {
typeId: null,
url: null
};
const widgetMetadata: DashboardInterfaces.WidgetMetadataResponse = await dashboardApiObject.getWidgetMetadata('ms.vss-dashboards-web.Microsoft.VisualStudioOnline.Dashboards.OtherLinksWidget');
const widgetMetadata: DashboardInterfaces.WidgetMetadataResponse = await dashboardApiObject.getWidgetMetadata('ms.vss-dashboards-web.Microsoft.VisualStudioOnline.Dashboards.OtherLinksWidget', projectId);
console.log('Creating widget with metadata:', widgetMetadata);
widget = await dashboardApiObject.createWidget(widget, teamContext, dashboard.id);
//Ensure its been created and we can get it.
Expand All @@ -72,7 +72,7 @@ export async function run(projectId: string) {
console.log('Widget name updated to', widget.name);

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

common.heading('Delete a widget');
Expand Down
132 changes: 103 additions & 29 deletions samples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions samples/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let samples: string[] = require("./samples.json");
let coreApi: cApi.ICoreApi;
const maxLoops: number = 500;

let selection: string = process.argv[2];
const selection: string = process.argv[2];
if (selection) {
if (samples.indexOf(selection) == -1) {
console.error("Not a valid sample. See list of samples");
Expand Down Expand Up @@ -41,7 +41,19 @@ async function createProject(projectId: string): Promise<boolean> {
revision: null,
state: null,
url: null};
await coreApi.queueCreateProject(projectToCreate);
let num = 0;
while (num < maxLoops) {
try {
await coreApi.queueCreateProject(projectToCreate);
break;
} catch (err) {
const errTypeKey = err.result.typeKey.toString();
if (!(errTypeKey == 'ProjectWorkPendingException' || errTypeKey == 'ProjectAlreadyExistsException')) {
throw err;
}
num++;
}
}

//Poll until project exists
let project: coreInterfaces.TeamProject = null;
Expand Down Expand Up @@ -114,11 +126,4 @@ async function runSamples(selected?: string) {
}
}

function run() {
runSamples();
}

runSamples(process.argv[2]);



runSamples(selection);

0 comments on commit a31bfae

Please sign in to comment.