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

fix:correcting python command #78

Merged
merged 5 commits into from
Oct 17, 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
12 changes: 12 additions & 0 deletions scripts/utg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
11 changes: 10 additions & 1 deletion src/SidebarProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,22 @@
console.log('Navigate to ' + value);
let sveltePageJs: vscode.Uri;
let sveltePageCss: vscode.Uri;
if(value = "KeployChatBot"){
if(value == "KeployChatBot"){

Check warning on line 81 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Expected '===' and instead saw '=='

Check warning on line 81 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Expected '===' and instead saw '=='

Check warning on line 81 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Expected '===' and instead saw '=='
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 {
Expand Down Expand Up @@ -430,7 +439,7 @@
}
}
case "progressStatus":{
if(progressBarVisible == true && data.value == "false"){

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Expected '===' and instead saw '=='
console.log("progressbarVisible and data value: ",progressBarVisible,data.value);
await this._context.globalState.update("progressVisible", false);
}
Expand Down
24 changes: 23 additions & 1 deletion src/Utg.ts
Original file line number Diff line number Diff line change
@@ -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';


Expand Down Expand Up @@ -76,6 +77,8 @@
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];
Expand Down Expand Up @@ -104,7 +107,7 @@
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') {
Expand Down Expand Up @@ -147,7 +150,7 @@
const originalClassName = path.basename(sourceFilePath, '.java');
const testFileName = `${originalClassName}Tests.java`;
const testFilePath = path.join(fullTestDir, testFileName);
const JavaClassName = `${originalClassName}Tests`

Check warning on line 153 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 153 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 153 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon

testFilePaths.push(testFilePath);

Expand Down Expand Up @@ -335,4 +338,23 @@
}
}

async function getPythonVersion(): Promise<string> {
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;
68 changes: 41 additions & 27 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,44 +565,46 @@
} 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
Expand Down Expand Up @@ -639,6 +641,8 @@
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);
Expand Down Expand Up @@ -712,8 +716,18 @@
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")

Check warning on line 730 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 730 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 730 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon
});

context.subscriptions.push(showSidebarDisposable);
Expand All @@ -721,7 +735,7 @@
let runAdditionalPrompts = vscode.commands.registerCommand('keploy.runAdditionalPrompts', async (additionalPrompts: string) => {
console.log("value inside the function: ", functionName, ExtentionName, additionalPrompts);
await vscode.commands.executeCommand('keploy.utg', FunctionFilePath, functionName, ExtentionName, additionalPrompts);
})

Check warning on line 738 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 738 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 738 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon

context.subscriptions.push(runAdditionalPrompts);

Expand Down
33 changes: 21 additions & 12 deletions webviews/components/KeployHome.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading