Skip to content

Commit

Permalink
perf(auth): add command for add auth in vsc (#13053)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethBWSong authored Jan 15, 2025
1 parent 8841ff2 commit a81d2ab
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,11 @@
"command": "fx-extension.findSimilarIssue",
"title": "%teamstoolkit.handlers.similarIssues%",
"category": "Teams"
},
{
"command": "fx-extension.addAuthAction",
"title": "%teamstoolkit.commands.addAuthAction%",
"category": "Teams"
}
],
"taskDefinitions": [
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
"teamstoolkit.commandsTreeViewProvider.officeAddIn.stopDebugTitle": "Stop Previewing Your Office Add-in",
"teamstoolkit.commandsTreeViewProvider.officeAddIn.stopDebugDescription": "Stop debugging the Office Add-in project",
"teamstoolkit.commandsTreeViewProvider.syncManifest": "Sync Manifest",
"teamstoolkit.commands.addAuthAction": "Add Configurations to Support Actions with Authentication in Declarative Agent",
"teamstoolkit.common.readMore": "Read more",
"teamstoolkit.common.signin": "Sign in",
"teamstoolkit.common.signout": "Sign out",
Expand Down
7 changes: 7 additions & 0 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ import {
refreshEnvironment,
} from "./handlers/envHandlers";
import {
addAuthActionHandler,
addPluginHandler,
addWebpartHandler,
copilotPluginAddAPIHandler,
Expand Down Expand Up @@ -727,6 +728,12 @@ function registerTeamsFxCommands(context: vscode.ExtensionContext) {
if (featureFlagManager.getBooleanValue(FeatureFlags.SyncManifest)) {
registerInCommandController(context, "fx-extension.syncManifest", syncManifestHandler);
}

const addAuthActionCmd = vscode.commands.registerCommand(
"fx-extension.addAuthAction",
(...args) => Correlator.run(addAuthActionHandler, args)
);
context.subscriptions.push(addAuthActionCmd);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/vscode-extension/src/handlers/lifecycleHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ export async function copilotPluginAddAPIHandler(args: any[]) {
return result;
}

export async function addAuthActionHandler(...args: unknown[]) {
ExtTelemetry.sendTelemetryEvent(TelemetryEvent.AddAuthActionStart, getTriggerFromProperty(args));
const inputs = getSystemInputs();
return await runCommand(Stage.addAuthAction, inputs);
}

function handleTriggerKiotaCommand(
args: any[],
result: any,
Expand Down
4 changes: 4 additions & 0 deletions packages/vscode-extension/src/handlers/sharedOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export async function runCommand(
result = await core.kiotaRegenerate(inputs);
break;
}
case Stage.addAuthAction: {
result = await core.addAuthAction(inputs);
break;
}
default:
throw new SystemError(
ExtensionSource,
Expand Down
2 changes: 2 additions & 0 deletions packages/vscode-extension/src/telemetry/extTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export namespace ExtTelemetry {
return TelemetryEvent.SyncManifest;
case Stage.addPlugin:
return TelemetryEvent.AddPlugin;
case Stage.addAuthAction:
return TelemetryEvent.AddAuthAction;
default:
return undefined;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/vscode-extension/src/telemetry/extTelemetryEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ export enum TelemetryEvent {

KiotaRegenerateStart = "kiota-regenerate-start",
KiotaRegenerate = "kiota-regenerate",

AddAuthActionStart = "add-auth-action-start",
AddAuthAction = "add-auth-action",
}

export enum TelemetryProperty {
Expand Down
18 changes: 18 additions & 0 deletions packages/vscode-extension/test/handlers/lifecycleHandlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as vscode from "vscode";
import * as globalVariables from "../../src/globalVariables";
import * as copilotHandler from "../../src/handlers/copilotChatHandlers";
import {
addAuthActionHandler,
addPluginHandler,
addWebpartHandler,
copilotPluginAddAPIHandler,
Expand Down Expand Up @@ -588,4 +589,21 @@ describe("Lifecycle handlers", () => {
mockedEnvRestore();
});
});

describe("AddAuthActionHandler", async () => {
const sandbox = sinon.createSandbox();

afterEach(() => {
sandbox.restore();
});

it("happy path", async () => {
sandbox.stub(globalVariables, "core").value(new MockCore());
const addPluginHanlder = sandbox.spy(globalVariables.core, "addAuthAction");

await addAuthActionHandler();

sinon.assert.calledOnce(addPluginHanlder);
});
});
});
4 changes: 4 additions & 0 deletions packages/vscode-extension/test/mocks/mockCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,8 @@ export class MockCore {
async kiotaRegenerate(inputs: Inputs): Promise<Result<any, FxError>> {
return ok(undefined);
}

async addAuthAction(inputs: Inputs): Promise<Result<any, FxError>> {
return ok(undefined);
}
}

0 comments on commit a81d2ab

Please sign in to comment.