Skip to content
Snippets Groups Projects
Commit 8f533e94 authored by Mohamed AZIKIOU's avatar Mohamed AZIKIOU
Browse files

feat: commit on command run

parent 122c6aca
No related branches found
No related tags found
1 merge request!28feat: commit on command run
Pipeline #15545 failed
......@@ -63,12 +63,10 @@ export default class GitMission {
async init() {
try {
this.log('Setup ssh agent');
await this.setupSshAgent();
await this.git.init();
this.log('Init Git mission..');
const remote = await this.readRemote();
if (remote === defaultRemote) {
......
import { window, ExtensionContext, workspace, commands } from 'vscode';
import Controller from './core/controller';
import isDocker from './core/utils/isdocker';
import Recorder from './recorder';
import Recorder from './recorder/recorder';
import { extensionError as error } from './recorder/utils/log';
import { DepNodeProvider } from './theia/deadlockPanel';
import UserConfigTheia from './theia/userConfigTheia';
import { CommandTreeProvider } from './view/CommandTree';
import StartedMissionsView from './view/startedMissionsView';
// TODO: refactor remove this
export const userConfig = new UserConfigTheia();
export async function activate(context: ExtensionContext) {
window.showInformationMessage('Bienvenue sur Deadlock!');
Controller.getInstance(context);
const workspaceFolders = workspace.workspaceFolders?.toString() ?? '';
......@@ -34,6 +34,6 @@ export async function activate(context: ExtensionContext) {
error('Cannot init userConfig');
}
if (isDocker()) {
new Recorder().run();
Recorder.instance.run();
}
}
......@@ -10,6 +10,26 @@ import { clearFilesExceptGit, copyProjectSources, renameTempToUserGitFiles } fro
import aquirePermissions from './utils/permission';
export default class Recorder {
private _gitMission?: GitMission;
private userConfig?: UserConfigNode;
private static _instance?: Recorder;
private constructor() {
Recorder._instance = this;
}
public static get instance(): Recorder {
if (!this._instance) {
return new Recorder();
}
return this._instance;
}
public get gitMission(): GitMission {
// TODO refactor remove !
return this._gitMission!;
}
async setupProject(userConfig: UserConfig, gitMission?: GitMission) {
if (!userConfig.isProfessor()) {
await copyProjectSources(PROJECT_SRC_PATH, PROJECT_DEADLOCK_DESKTOP_PATH, ['.git/']);
......@@ -41,31 +61,23 @@ export default class Recorder {
}
async run() {
const userConfig = new UserConfigNode();
let gitMission;
this.userConfig = new UserConfigNode();
try {
await aquirePermissions();
await userConfig.init();
gitMission = await new GitMission(userConfig).init();
await this.setupFromRemoteRepo(gitMission);
} catch (e) {
error('Cannot setup user repo.');
error(e);
}
// TODO refactor remove this
await this.userConfig.init();
this._gitMission = await new GitMission(this.userConfig).init();
await this.setupFromRemoteRepo(this._gitMission);
await this.setupProject(this.userConfig, this._gitMission);
try {
await this.setupProject(userConfig, gitMission);
if (ENABLE_AUTOMATIC_SAVE) new AutomaticSave(PROJECT_DEADLOCK_DESKTOP_PATH, this._gitMission);
} catch (e) {
error('Error while setup project sources');
error('Error while setup automatic save');
error(e);
}
try {
if (ENABLE_AUTOMATIC_SAVE) new AutomaticSave(PROJECT_DEADLOCK_DESKTOP_PATH, gitMission);
} catch (e) {
error('Error while setup automatic save');
error('Cannot setup user repo.');
error(e);
}
}
......
import * as chokidar from 'chokidar';
import { watch } from 'chokidar';
export default class FileWatcher {
constructor(
......@@ -11,7 +11,7 @@ export default class FileWatcher {
}
setupWatcher() {
const watcher = chokidar.watch(this.watchFilePatterns, {
const watcher = watch(this.watchFilePatterns, {
cwd: this.folderToWatch,
ignored: this.ignoreFilePatterns,
ignoreInitial: true,
......
import { exec as execCallback, execSync } from 'child_process';
import { copyFileSync, existsSync, lstatSync, PathLike, readdirSync, renameSync, rmdirSync } from 'fs';
import { copyFileSync, existsSync, lstatSync, PathLike, readdirSync, renameSync } from 'fs';
import { join } from 'path';
import { log } from './log';
import { promisify } from 'util';
import { mkdir, rmdir, unlink, rm } from 'fs/promises';
import { mkdir, unlink, rm } from 'fs/promises';
const exec = promisify(execCallback);
const PREFIX = '[DEADLOCK-RECORDER]';
......@@ -24,7 +24,7 @@ export async function clearFilesExceptGit(path: string) {
if (file !== '.git') {
const curPath = join(path, file);
if (lstatSync(curPath).isDirectory()) {
rmdirSync(curPath, { recursive: true });
await rm(curPath, { recursive: true });
} else {
await unlink(curPath);
}
......@@ -90,7 +90,7 @@ export async function removeFilesOrDirectories(...paths: string[]) {
export async function emptyDirectories(...directoryPaths: string[]) {
directoryPaths.forEach(async (directoryPath) => {
await rmdir(directoryPath, { recursive: true });
await rm(directoryPath, { recursive: true });
await mkdir(directoryPath);
});
}
......@@ -3,6 +3,8 @@ import ChallengeYaml, { MissionCommand as MissionCommandYaml } from '../model/ch
import { parse } from 'yaml';
import { readFileSync } from 'fs';
import { commands, ExtensionContext, ThemeColor, ThemeIcon, TreeDataProvider, TreeItem, window } from 'vscode';
import { commitAndPushOnQueue, CommitFrom } from '../recorder/utils/gitea';
import Recorder from '../recorder/recorder';
export class CommandTreeProvider implements TreeDataProvider<MissionCommand> {
challenge: ChallengeYaml;
......@@ -48,6 +50,7 @@ class MissionCommand extends TreeItem {
});
terminal.sendText(missionCommandYaml.command);
terminal.show();
commitAndPushOnQueue(Recorder.instance.gitMission, CommitFrom.Run);
});
this.command = {
title: missionCommandYaml.name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment