diff --git a/scripts/utg.sh b/scripts/utg.sh index 60dff1b..acd611c 100644 --- a/scripts/utg.sh +++ b/scripts/utg.sh @@ -13,7 +13,19 @@ extension="${sourceFilePath##*.}" # If the file is a Python file, install pytest-cov if [ "$extension" = "py" ]; then + echo "Checking if pytest is installed..." + + # Check if pytest is installed + if ! pip3 show pytest > /dev/null 2>&1; then + echo "pytest is not installed. Installing pytest..." + pip3 install pytest --break-system-packages + else + echo "pytest is already installed." + fi + echo "Checking if pytest-cov is installed..." + + # Check if pytest-cov is installed if ! pip3 show pytest-cov > /dev/null 2>&1; then echo "pytest-cov is not installed. Installing pytest-cov..." pip3 install pytest-cov --break-system-packages diff --git a/sidebar/sidebar.js b/sidebar/sidebar.js index 7966832..bab9e9a 100644 --- a/sidebar/sidebar.js +++ b/sidebar/sidebar.js @@ -420,12 +420,13 @@ document.addEventListener('addUsersClick', function (e) { }); // Listen for custom events from the Svelte component -document.addEventListener('getKeployConfig', () => { +document.addEventListener('getKeployConfigForSvelte', () => { vscode.postMessage({ type: 'getKeployConfig', }); }); + document.addEventListener('updateKeployConfig', (e) => { const config = e.detail.config; vscode.postMessage({ diff --git a/src/SidebarProvider.ts b/src/SidebarProvider.ts index 61e66c6..a6c1b8a 100644 --- a/src/SidebarProvider.ts +++ b/src/SidebarProvider.ts @@ -78,13 +78,22 @@ export class SidebarProvider implements vscode.WebviewViewProvider { console.log('Navigate to ' + value); let sveltePageJs: vscode.Uri; let sveltePageCss: vscode.Uri; - if(value = "KeployChatBot"){ + if(value == "KeployChatBot"){ sveltePageJs = webviewView.webview.asWebviewUri( vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "KeployChat.js") ); sveltePageCss = webviewView.webview.asWebviewUri( vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "KeployChat.css") ); + } + else if (value === 'Config') { + + sveltePageJs = webviewView.webview.asWebviewUri( + vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "Config.js") + ); + sveltePageCss = webviewView.webview.asWebviewUri( + vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "Config.css") + ); } else { diff --git a/src/Utg.ts b/src/Utg.ts index cbe1e36..5118f48 100644 --- a/src/Utg.ts +++ b/src/Utg.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import * as fs from 'fs'; import * as path from 'path'; +import { exec } from 'child_process'; import axios, { AxiosResponse } from 'axios'; @@ -76,6 +77,8 @@ async function Utg(context: vscode.ExtensionContext , additional_prompts?:string coverageReportPath = "./coverage/cobertura-coverage.xml"; } else if (extension === '.py') { + const pythonCommand = await getPythonVersion(); // Get python version (python or python3) + if (testFilesPath && testFilesPath.length > 0) { // Use only the first path from testFilesPath testFilePaths = [testFilesPath[0].fsPath]; @@ -104,7 +107,7 @@ async function Utg(context: vscode.ExtensionContext , additional_prompts?:string fs.writeFileSync(defaultTestFilePath, testContent); } } - command = `pytest --cov=${path.basename(sourceFilePath, '.py')} --cov-report=xml:coverage.xml ${testFilePaths[0]}`; + command = `${pythonCommand} -m pytest --cov=${path.basename(sourceFilePath, '.py')} --cov-report=xml:coverage.xml ${testFilePaths[0]}`; coverageReportPath = "./coverage.xml"; } else if (extension === '.java') { @@ -335,4 +338,23 @@ async function ensureTestFileExists(sourceFilePath: string , DirectoryPath:strin } } +async function getPythonVersion(): Promise { + return new Promise((resolve, reject) => { + exec('python --version', (error, stdout, stderr) => { + if (error) { + exec('python3 --version', (error3, stdout3, stderr3) => { + if (error3) { + vscode.window.showErrorMessage('Python is not installed.'); + reject('Python not found'); + } else { + resolve('python3'); + } + }); + } else { + resolve('python'); + } + }); + }); +} + export default Utg; diff --git a/src/extension.ts b/src/extension.ts index 1817cac..f22c4ed 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -565,44 +565,46 @@ export function activate(context: vscode.ExtensionContext) { } else { vscode.commands.executeCommand('setContext', 'keploy.signedOut', true); // Register the sign-in command if not signed in - let signInCommand = vscode.commands.registerCommand('keploy.SignInWithGithub', async () => { - try { - const result = await getGitHubAccessToken(); + } + let signInCommand = vscode.commands.registerCommand('keploy.SignInWithGithub', async () => { + try { + const result = await getGitHubAccessToken(); - if (result) { - const { accessToken, email } = result; + if (result) { + const { accessToken, email } = result; - getInstallationID(); + getInstallationID(); - // Store the access token in global state - await context.globalState.update('accessToken', accessToken); + // Store the access token in global state + await context.globalState.update('accessToken', accessToken); - const { emailID, isValid, error, JwtToken } = await validateFirst(accessToken, "https://api.keploy.io"); + const { emailID, isValid, error, JwtToken } = await validateFirst(accessToken, "https://api.keploy.io"); - console.log({ emailID, isValid, error, JwtToken }); + console.log({ emailID, isValid, error, JwtToken }); - await context.globalState.update('JwtToken', JwtToken); + await context.globalState.update('JwtToken', JwtToken); + await context.globalState.update('SignedOthers', true); - // if (isValid) { - vscode.window.showInformationMessage('You are now signed in!'); - vscode.commands.executeCommand('setContext', 'keploy.signedIn', true); - vscode.commands.executeCommand('setContext', 'keploy.signedOut', false); - // } else { - // console.log('Validation failed for the user !'); - // } + // if (isValid) { + vscode.window.showInformationMessage('You are now signed in!'); + vscode.commands.executeCommand('setContext', 'keploy.signedIn', true); + vscode.commands.executeCommand('setContext', 'keploy.signedOut', false); + // } else { + // console.log('Validation failed for the user !'); + // } - } else { - console.log('Failed to get the session or email.'); - vscode.window.showInformationMessage('Failed to sign in Keploy!'); - } - } catch (error) { - // console.error('Error during sign-in:', error); + } else { + console.log('Failed to get the session or email.'); vscode.window.showInformationMessage('Failed to sign in Keploy!'); } - }); - context.subscriptions.push(signInCommand); + } catch (error) { + // console.error('Error during sign-in:', error); + vscode.window.showInformationMessage('Failed to sign in Keploy!'); + } + }); + context.subscriptions.push(signInCommand); + - } let signInWithOthersCommand = vscode.commands.registerCommand('keploy.SignInWithOthers', async () => { try { await SignInWithOthers(); // The result will now be handled in the URI handler @@ -639,6 +641,8 @@ export function activate(context: vscode.ExtensionContext) { vscode.window.showInformationMessage('You have been signed out.'); vscode.commands.executeCommand('setContext', 'keploy.signedIn', false); vscode.commands.executeCommand('setContext', 'keploy.signedOut', true); + sidebarProvider.postMessage("Config"); + }); context.subscriptions.push(signout); @@ -712,6 +716,16 @@ export function activate(context: vscode.ExtensionContext) { functionName = FunctionName; ExtentionName = FileExtentionName; FunctionFilePath = filePath; + const signedIn = await context.globalState.get('accessToken'); + const signedInOthers = await context.globalState.get('SignedOthers'); + const SubscriptionEnded = await context.globalState.get('SubscriptionEnded') !== undefined ? context.globalState.get('SubscriptionEnded') : true; + const token = await context.globalState.get<'string'>('JwtToken'); + console.log("SubscriptionEnded Value: ", SubscriptionEnded); + if (!signedIn && !signedInOthers) { + // Redirect to the website if signed in + await vscode.commands.executeCommand('keploy.SignInWithOthers'); + return; + } vscode.commands.executeCommand('workbench.view.extension.Keploy-Sidebar'); sidebarProvider.postMessage("KeployChatBot") }); diff --git a/webviews/components/KeployHome.svelte b/webviews/components/KeployHome.svelte index e1c6cb9..596ed19 100644 --- a/webviews/components/KeployHome.svelte +++ b/webviews/components/KeployHome.svelte @@ -28,21 +28,30 @@ // On mount, request config and set up listeners onMount(() => { // Dispatch a custom event to request the Keploy config - const getConfigEvent = new CustomEvent('getKeployConfig'); + setTimeout(() => { + const getConfigEvent = new CustomEvent('getKeployConfigForSvelte'); document.dispatchEvent(getConfigEvent); + console.log("Dispatched getKeployConfigForSvelte event"); + }, 100); // 100ms delay + console.log("starting the onMount for the KeployConfig"); // Listen for the response from sidebar.js - document.addEventListener('keployConfig', event => { - const config = event.detail.config; - - // Set the form fields with the values from the config - appName = config.appName || ''; - command = config.command || ''; - containerName = config.containerName || ''; - networkName = config.networkName || 'default'; - delay = config.test?.delay || 5; - apiTimeout = config.test?.apiTimeout || 5; - mongoPassword = config.test?.mongoPassword || ''; + window.addEventListener('message', event => { + const message = event.data; + + if (message.type === 'keployConfig') { + console.log("In the svelete directly taking values ;)" ,message ); + const config = message.config; + + // Set the form fields with the values from the config + appName = config.appName || ''; + command = config.command || ''; + containerName = config.containerName || ''; + networkName = config.networkName || 'default'; + delay = config.test?.delay || 5; + apiTimeout = config.test?.apiTimeout || 5; + mongoPassword = config.test?.mongoPassword || ''; + } }); // Initialize DOM elements