Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: Support ttk add plugin #5759

Merged
merged 15 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class GenerateClientCommand extends Command {
if (!deepLinkParams.name && this._openApiTreeProvider.apiTitle) {
deepLinkParams.name = getSanitizedString(this._openApiTreeProvider.apiTitle);
}
availableStateInfo = transformToGenerationConfig(deepLinkParams);
availableStateInfo = await transformToGenerationConfig(deepLinkParams);
} else {
const pluginName = getSanitizedString(this._openApiTreeProvider.apiTitle);
availableStateInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ suite('GenerateClientCommand Test Suite', () => {
assert.strictEqual(!treeProvider.descriptionUrl, false);
vscodeWindowSpy.verify();
sinon.assert.calledOnceWithMatch(getlanguageInfoFn, context);
let stateInfo = transformToGenerationConfig(pluginParams);
let stateInfo = await transformToGenerationConfig(pluginParams);
sinon.assert.calledOnceWithMatch(generateStepsFn, stateInfo, undefined , pluginParams);
sinon.assert.calledOnce(showUpgradeWarningMessageStub);
sinon.assert.calledOnceWithMatch(getExtensionSettingsStub, "kiota");
Expand Down
46 changes: 38 additions & 8 deletions vscode/microsoft-kiota/src/utilities/deep-linking.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as path from 'path';
import { promises as fs } from 'fs';

import { GenerateState } from "../modules/steps/generateSteps";
import { KiotaGenerationLanguage, KiotaPluginType } from "../types/enums";
import { allGenerationLanguagesToString, getSanitizedString, parseGenerationLanguage, parsePluginType } from "../util";
Expand All @@ -8,8 +11,8 @@ export function isDeeplinkEnabled(deepLinkParams: Partial<IntegrationParams>): b
return Object.values(deepLinkParams).filter(property => property).length >= minimumNumberOfParams;
}

export function transformToGenerationConfig(deepLinkParams: Partial<IntegrationParams>)
: Partial<GenerateState> {
export async function transformToGenerationConfig(deepLinkParams: Partial<IntegrationParams>)
: Promise<Partial<GenerateState>> {
const generationConfig: Partial<GenerateState> = {};
if (deepLinkParams.kind === "client") {
generationConfig.generationType = "client";
Expand All @@ -34,7 +37,7 @@ export function transformToGenerationConfig(deepLinkParams: Partial<IntegrationP
}
generationConfig.outputPath =
(deepLinkParams.source && deepLinkParams.source?.toLowerCase() === 'ttk')
? createTemporaryFolder()
? await determineOutputPath(deepLinkParams)
: undefined;
}
return generationConfig;
Expand All @@ -49,7 +52,8 @@ export interface IntegrationParams {
source: string;
ttkContext: {
lastCommand: string;
}
},
projectPath: string;
};

export function validateDeepLinkQueryParams(queryParameters: Partial<IntegrationParams>):
Expand All @@ -59,6 +63,8 @@ export function validateDeepLinkQueryParams(queryParameters: Partial<Integration
const descriptionurl = queryParameters["descriptionurl"];
const name = getSanitizedString(queryParameters["name"]);
const source = getSanitizedString(queryParameters["source"]);
let projectPath = queryParameters["projectPath"];

let lowercasedKind: string = queryParameters["kind"]?.toLowerCase() ?? "";
let validKind: string | undefined = ["plugin", "client"].indexOf(lowercasedKind) > -1 ? lowercasedKind : undefined;
if (!validKind) {
Expand Down Expand Up @@ -103,14 +109,38 @@ export function validateDeepLinkQueryParams(queryParameters: Partial<Integration
errormsg.push("Invalid parameter 'type' deeplinked. Expected values: " + acceptedPluginTypes.join(","));
}

if (projectPath && !path.isAbsolute(projectPath)) {
projectPath = undefined;
errormsg.push(`A relative paths is not supported for the projectPath parameter`);
calebkiage marked this conversation as resolved.
Show resolved Hide resolved
}
validQueryParams = {
descriptionurl: descriptionurl,
name: name,
descriptionurl,
name,
kind: validKind,
type: providedType,
language: givenLanguage,
source: source,
ttkContext: queryParameters.ttkContext ? queryParameters.ttkContext : undefined
source,
ttkContext: queryParameters.ttkContext,
projectPath
};
return [validQueryParams, errormsg];
}

async function determineOutputPath(deepLinkParams: Partial<IntegrationParams>): Promise<string | undefined> {
if (deepLinkParams.projectPath) {
try {
const exists = await fs.access(deepLinkParams.projectPath).then(() => true).catch(() => false);
if (!exists) {
try {
await fs.mkdir(deepLinkParams.projectPath);
} catch (err: unknown) {
throw new Error(`Error creating directory: ${(err as Error).message}`);
}
}
return deepLinkParams.projectPath;
} catch (error) {
return createTemporaryFolder();
}
}
return createTemporaryFolder();
}
Loading