Skip to content
Snippets Groups Projects
Select Git revision
  • 9f914ed2d145588436447221d231d5054d0a2a22
  • master default protected
  • feat-create_little_container_for_developer
  • feat/pipeline_publish_extension
  • feat-publish_extension_on_marketplace_with_ci
  • feat-log-in
  • feat-connect_uri_handler_with_chosse_workdir_and_connection
  • feat-choose-mission-workdir
  • 10-en-tant-qu-etudiant-je-souhaite-pouvoir-lancer-une-mission-de-type-vscode-desktop-sur-mon-ide
  • new-building-way-recorder
  • fix-commit-any-challenge-type
  • recorder-push-code
  • theia-extension
  • 0.1.2
  • 0.1.1
  • 0.0.6
  • 1.4
  • 1.3
  • 1.2
  • 1.1
20 results

gitMission.ts

Blame
  • gitMission.ts 3.03 KiB
    import simpleGit, { SimpleGit, SimpleGitOptions } from 'simple-git';
    import { PROJECT_SRC_PATH } from './config';
    import UserConfig from './userConfig';
    
    const util = require('util');
    const exec = util.promisify(require('child_process').exec);
    
    const DEFAULT_REMOTE = 'origin';
    const DEFAULT_BRANCH = 'master';
    
    export default class GitMission {
    
        private git: SimpleGit;
    
        constructor(private userConfig: UserConfig) {
            const options: Partial<SimpleGitOptions> = {
                baseDir: PROJECT_SRC_PATH,
                binary: 'git',
                maxConcurrentProcesses: 2,
            };
    
            this.git = simpleGit(options);
        }
    
        async setupSshAgent() {
            const { err, stderr, stdout } = await exec(`eval "$(ssh-agent -s)" && ssh-keyscan -p ${this.userConfig.getGiteaSshPort()} -H ${this.userConfig.getGiteaHost()} >> ~/.ssh/known_hosts`);
    
            console.log(stdout);
    
            if (err) {
                console.error(stderr);
                throw new Error(err);
            }
    
        }
    
        get author() {
    
            return this.userConfig.getUsername();
        }
    
        async init() {
            try {
    
                console.log('Setup ssh agent');
                await this.setupSshAgent();
    
                console.log('Init Git mission..');
    
                const remote = await this.readRemote();
                if (remote === DEFAULT_REMOTE) {
                    return Promise.resolve(this);
                }
    
                const remotePath = this.getRemotePath();
    
                await this.git.init();
                await this.git.addRemote(DEFAULT_REMOTE, remotePath);
                await this.git.addConfig('user.email', this.userConfig.getCurrentUserDetails().email, false, "system");
                await this.git.addConfig('user.name', `${this.userConfig.getCurrentUserDetails().lastName} ${this.userConfig.getCurrentUserDetails().firstName}`, false, "system");
    
                return Promise.resolve(this);
            } catch (e) {
                console.error(e);
                return Promise.reject(e);
            }
        }
    
        private getRemotePath() {
            return `ssh://git@${this.userConfig.getGiteaHost()}:${this.userConfig.getGiteaSshPort()}/${this.userConfig.getRemoteGitUsername()}/${this.userConfig.getMissionId()}`;