From 1bdab0f22941cca1765056355350958af38c9d70 Mon Sep 17 00:00:00 2001 From: Monil Patel Date: Wed, 8 Jun 2022 10:20:57 -0700 Subject: [PATCH] add comment with more information about context --- src/Samples/Menu/Menu.ts | 50 ++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Samples/Menu/Menu.ts b/src/Samples/Menu/Menu.ts index b315cff..557061c 100644 --- a/src/Samples/Menu/Menu.ts +++ b/src/Samples/Menu/Menu.ts @@ -1,16 +1,46 @@ import "es6-promise/auto"; + import * as SDK from "azure-devops-extension-sdk"; -import { CommonServiceIds, getClient, IHostPageLayoutService } from "azure-devops-extension-api"; -import { BuildDefinition, BuildRestClient } from "azure-devops-extension-api/Build"; + +import { + BuildDefinition, + BuildRestClient, +} from "azure-devops-extension-api/Build"; +import { + CommonServiceIds, + IHostPageLayoutService, + getClient, +} from "azure-devops-extension-api"; SDK.register("sample-build-menu", () => { - return { - execute: async (context: BuildDefinition) => { - const result = await getClient(BuildRestClient).getDefinition(context.project.id, context.id, undefined, undefined, undefined, true); - const dialogSvc = await SDK.getService(CommonServiceIds.HostPageLayoutService); - dialogSvc.openMessageDialog(`Fetched build definition ${result.name}. Latest build: ${JSON.stringify(result.latestBuild)}`, { showCancel: false }); - } - } + return { + /** + * Based on the target of the menu item, context can contain relevant data from the initial page the menu was accessed from + * + * Example: When targeting Azure Repos menu (ms.vss-code-web.source-item-menu), context will contain the following properties: + * - gitRepository: The currently selected git repository + * - version: The currently selected branch + */ + execute: async (context: BuildDefinition) => { + const result = await getClient(BuildRestClient).getDefinition( + context.project.id, + context.id, + undefined, + undefined, + undefined, + true + ); + const dialogSvc = await SDK.getService( + CommonServiceIds.HostPageLayoutService + ); + dialogSvc.openMessageDialog( + `Fetched build definition ${ + result.name + }. Latest build: ${JSON.stringify(result.latestBuild)}`, + { showCancel: false } + ); + }, + }; }); -SDK.init(); \ No newline at end of file +SDK.init();