Skip to content

Commit

Permalink
change login procedure in theia environment
Browse files Browse the repository at this point in the history
  • Loading branch information
artemis_admin committed Nov 19, 2024
1 parent 48a2baa commit 09f07a3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
11 changes: 7 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
} from "./shared/repository";
import { sync_problem_statement_with_workspace } from "./problemStatement/problem_statement";
import { NotAuthenticatedError } from "./authentication/not_authenticated.error";
import { initTheia } from "./theia/theia";
import { initTheia, theiaEnv } from "./theia/theia";
import { initSettings } from "./shared/settings";

export var authenticationProvider: ArtemisAuthenticationProvider;

Expand All @@ -29,10 +30,12 @@ export function activate(context: vscode.ExtensionContext) {
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "scorpio" is now active!');

initAuthentication(context);

initTheia();

initSettings();

initAuthentication(context);

const sidebar = initSidebar(context);

registerCommands(context, sidebar);
Expand Down Expand Up @@ -60,7 +63,7 @@ function initAuthentication(
(async () => {
if (
await vscode.authentication.getSession(AUTH_ID, [], {
createIfNone: false,
createIfNone: theiaEnv != null,
})
) {
vscode.commands.executeCommand(
Expand Down
24 changes: 13 additions & 11 deletions src/shared/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ export type Settings = {
easter_egg: boolean;
};

export const settings: Settings = (() =>{
export var settings: Settings

export function initSettings() {
if (theiaEnv) {
return getSettingsForTheia();
settings = getSettingsForTheia();
} else{
return getSettingsForVscode();
settings = getSettingsForVscode();
}
})();

vscode.workspace.onDidChangeConfiguration((e) => {
if (theiaEnv) {
handleSettingsChangeForTheia(e);
} else {
handleSettingsChangeForVscode(e);
}
});
vscode.workspace.onDidChangeConfiguration((e) => {
if (theiaEnv) {
handleSettingsChangeForTheia(e);
} else {
handleSettingsChangeForVscode(e);
}
});
}

function getSettingsForVscode(): Settings {
const base_url = vscode.workspace.getConfiguration("scorpio").get<string>("artemis.apiBaseUrl");
Expand Down
7 changes: 5 additions & 2 deletions src/theia/cloning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ export async function cloneTheia(cloneUrl: URL) {

try {
await git.clone(cloneUrl.toString(), clonePath);

} catch (e: any) {
vscode.window.showErrorMessage(`Error cloning repository: ${e.message}`);
}
try {
await git.addConfig("user.name", theiaEnv?.GIT_USER!, undefined, GitConfigScope.global);
await git.addConfig("user.email", theiaEnv?.GIT_MAIL!, undefined, GitConfigScope.global);
} catch (e: any) {
vscode.window.showErrorMessage(`Error cloning repository: ${e.message}`);
vscode.window.showErrorMessage(`Error setting git config: ${e.message}`);
}
}
4 changes: 2 additions & 2 deletions src/theia/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export async function handleSettingsChangeForTheia(e: vscode.ConfigurationChange

if (e.affectsConfiguration("scorpio.artemis.apiBaseUrl")) {
// url should not be changed in theia environement
vscode.window.showWarningMessage("Artemis API URL can not be changed in theia environment");
vscode.window.showWarningMessage("Artemis URL can not be changed in theia environment");
config.update("artemis.apiBaseUrl", settings.base_url, vscode.ConfigurationTarget.Global);
}

if (e.affectsConfiguration("scorpio.artemis.clientBaseUrl")) {
// url should not be changed in theia environement
vscode.window.showWarningMessage("Artemis Client URL can not be changed in theia environment");
vscode.window.showWarningMessage("Artemis URL can not be changed in theia environment");
config.update("artemis.clientBaseUrl", settings.client_url, vscode.ConfigurationTarget.Global);
}

Expand Down
16 changes: 3 additions & 13 deletions src/theia/theia.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as vscode from "vscode";
import { cloneTheia } from "./cloning";
import { AUTH_ID } from "../authentication/authentication_provider";
import { exit } from "process";
import { execSync } from "child_process";

Expand Down Expand Up @@ -34,9 +33,11 @@ function readTheiaEnv(): theiaEnv | undefined {
};
}

export const theiaEnv: theiaEnv | undefined = readTheiaEnv();
export var theiaEnv: theiaEnv | undefined;

export async function initTheia() {
theiaEnv = readTheiaEnv();

if (!theiaEnv) {
return;
}
Expand All @@ -57,17 +58,6 @@ export async function initTheia() {

vscode.commands.executeCommand("setContext", "scorpio.theia", true);

// make authentication
if (
await vscode.authentication.getSession(AUTH_ID, [], {
createIfNone: true,
})
) {
vscode.commands.executeCommand("setContext", "scorpio.authenticated", true);
} else {
vscode.window.showErrorMessage("User could not be authenticated with token in environment");
}

// clone repository
cloneTheia(theiaEnv.GIT_URI!);

Expand Down

0 comments on commit 09f07a3

Please sign in to comment.