Skip to content

Commit

Permalink
fix:pytest command and ui updates(#78)
Browse files Browse the repository at this point in the history
* fix:correcting python command

Signed-off-by: Aditya-eddy <[email protected]>

* chore:adding pytest installation and correcting github-signin

Signed-off-by: Aditya-eddy <[email protected]>

* chore:correcting github login , correcting the signout feature, correcting additional_prompts

Signed-off-by: Aditya-eddy <[email protected]>

* fix:fixing the keploy.yaml page to read values from the file

Signed-off-by: Aditya-eddy <[email protected]>

---------

Signed-off-by: Aditya-eddy <[email protected]>
  • Loading branch information
Aditya-eddy authored Oct 17, 2024
1 parent 19204f6 commit 39be915
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 42 deletions.
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 @@ 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"){

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
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 @@ 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];
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -335,4 +338,23 @@ async function ensureTestFileExists(sourceFilePath: string , DirectoryPath:strin
}
}

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 @@ 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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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")

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
});
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

0 comments on commit 39be915

Please sign in to comment.