Skip to content
Snippets Groups Projects
Select Git revision
  • b319f1252f2a866177be954f34385584a2a15346
  • master default protected
2 results

fmpi_task_generic.h

Blame
  • GitlabManager.ts 7.15 KiB
    import LocalConfig     from '../config/LocalConfig';
    import LocalConfigKeys from '../types/LocalConfigKeys';
    import axios           from 'axios';
    import Config          from '../config/Config';
    import ora             from 'ora';
    import GitlabUser      from '../shared/types/Gitlab/GitlabUser';
    import GitlabRoutes    from '../shared/types/Gitlab/GitlabRoutes';
    
    
    class GitlabManager {
        private _token: string | null = null;
    
        constructor() { }
    
        private static _instance: GitlabManager;
    
        public static get instance(): GitlabManager {
            if ( !GitlabManager._instance ) {
                GitlabManager._instance = new GitlabManager();
            }
    
            return GitlabManager._instance;
        }
    
        private getApiUrl(route: GitlabRoutes): string {
            return `${ Config.gitlab.apiURL }${ route }`;
        }
    
        get isLogged(): boolean {
            return this._token !== null;
        }
    
        get token(): string {
            return this._token || '';
        }
    
        set token(token: string) {
            this._token = token;
    
            LocalConfig.updateConfig(LocalConfigKeys.GITLAB_PERSONAL_TOKEN, token);
        }
    
        login(token: string): void {
            this.token = token;
        }
    
        logout(): void {
            this.token = '';
        }
    
        public async testToken(verbose: boolean = true): Promise<[ boolean, boolean ]> {
            if ( verbose ) {
                ora('Checking Gitlab token: ').start().info();
            }
    
            let result: [ boolean, boolean ] = [ false, false ];
    
            type NotificationSettings = { level: string }
    
            let notificationSettings: NotificationSettings = { level: 'error' };
    
            // Test read access
            {
                const spinnerRead: ora.Ora = ora({
                                                     text  : `Read access`,
                                                     indent: 4
                                                 });
                if ( verbose ) {
                    spinnerRead.start();
                }