diff --git a/NodeApp/src/commander/assignment/subcommands/AssignmentCreateCommand.ts b/NodeApp/src/commander/assignment/subcommands/AssignmentCreateCommand.ts index 25d8f79a7362948eca623440336a3066d47a978e..51242423158dea1245f1192589176ae3a90d8823 100644 --- a/NodeApp/src/commander/assignment/subcommands/AssignmentCreateCommand.ts +++ b/NodeApp/src/commander/assignment/subcommands/AssignmentCreateCommand.ts @@ -5,8 +5,8 @@ import Assignment from '../../../sharedByClients/models/Assignment'; import DojoBackendManager from '../../../managers/DojoBackendManager'; import Toolbox from '../../../shared/helpers/Toolbox'; import * as Gitlab from '@gitbeaker/rest'; -import GlobalHelper from '../../../helpers/GlobalHelper'; import TextStyle from '../../../types/TextStyle'; +import GitlabManager from '../../../managers/GitlabManager'; type CommandOptions = { name: string, template?: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean } @@ -37,7 +37,7 @@ class AssignmentCreateCommand extends CommanderCommand { throw new Error(); } - this.members = await GlobalHelper.gitlabManager.fetchMembers(options); + this.members = await GitlabManager.fetchMembers(options); if ( !this.members ) { throw new Error(); } @@ -84,7 +84,7 @@ class AssignmentCreateCommand extends CommanderCommand { if ( options.clone ) { console.log(TextStyle.BLOCK('Please wait while we are cloning the repository...')); - await GlobalHelper.gitlabManager.cloneRepository(options.clone, this.assignment.gitlabCreationInfo.ssh_url_to_repo, undefined, true, 0); + await GitlabManager.cloneRepository(options.clone, this.assignment.gitlabCreationInfo.ssh_url_to_repo, undefined, true, 0); } } diff --git a/NodeApp/src/commander/auth/subcommands/AuthTestCommand.ts b/NodeApp/src/commander/auth/subcommands/AuthTestCommand.ts index 163678ba63089f08451fa10ebe9f3ff212841c20..e2d18f8e0cd02004939d24aab7841a5c9b8ed050 100644 --- a/NodeApp/src/commander/auth/subcommands/AuthTestCommand.ts +++ b/NodeApp/src/commander/auth/subcommands/AuthTestCommand.ts @@ -1,6 +1,6 @@ import CommanderCommand from '../../CommanderCommand'; import SessionManager from '../../../managers/SessionManager'; -import GlobalHelper from '../../../helpers/GlobalHelper'; +import GitlabManager from '../../../managers/GitlabManager'; class AuthTestCommand extends CommanderCommand { @@ -8,13 +8,13 @@ class AuthTestCommand extends CommanderCommand { protected defineCommand() { this.command - .description('test availability of registered Dojo API and Gitlab API sessions') - .action(this.commandAction.bind(this)); + .description('test availability of registered Dojo API and Gitlab API sessions') + .action(this.commandAction.bind(this)); } protected async commandAction(): Promise<void> { await SessionManager.testSession(); - await GlobalHelper.gitlabManager.testToken(); + await GitlabManager.testToken(); } } diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts index 335f44f9aef75f69b8e2f08fbc373a55902fa881..8a0d7ea5aa83a020396d9aa09019c3c6f30552c1 100644 --- a/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts +++ b/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts @@ -5,8 +5,8 @@ import AccessesHelper from '../../../helpers/AccessesHelper'; import Assignment from '../../../sharedByClients/models/Assignment'; import Exercise from '../../../sharedByClients/models/Exercise'; import * as Gitlab from '@gitbeaker/rest'; -import GlobalHelper from '../../../helpers/GlobalHelper'; import TextStyle from '../../../types/TextStyle'; +import GitlabManager from '../../../managers/GitlabManager'; type CommandOptions = { assignment: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean } @@ -36,7 +36,7 @@ class ExerciseCreateCommand extends CommanderCommand { throw new Error(); } - this.members = await GlobalHelper.gitlabManager.fetchMembers(options); + this.members = await GitlabManager.fetchMembers(options); if ( !this.members ) { throw new Error(); } @@ -87,7 +87,7 @@ class ExerciseCreateCommand extends CommanderCommand { if ( options.clone ) { console.log(TextStyle.BLOCK('Please wait while we are cloning the repository...')); - await GlobalHelper.gitlabManager.cloneRepository(options.clone, this.exercise.gitlabCreationInfo.ssh_url_to_repo, `DojoExercise - ${ this.exercise.assignmentName }`, true, 0); + await GitlabManager.cloneRepository(options.clone, this.exercise.gitlabCreationInfo.ssh_url_to_repo, `DojoExercise - ${ this.exercise.assignmentName }`, true, 0); } } diff --git a/NodeApp/src/helpers/AccessesHelper.ts b/NodeApp/src/helpers/AccessesHelper.ts index 9b868cf427645409971dcd5e52d9c28d34cbfe33..c9ff5e1bdaa823ca011eba7fa057e1c0b949a74e 100644 --- a/NodeApp/src/helpers/AccessesHelper.ts +++ b/NodeApp/src/helpers/AccessesHelper.ts @@ -1,5 +1,5 @@ import SessionManager from '../managers/SessionManager'; -import GlobalHelper from './GlobalHelper'; +import GitlabManager from '../managers/GitlabManager'; class AccessesHelper { @@ -11,7 +11,7 @@ class AccessesHelper { } if ( testGitlab ) { - return (await GlobalHelper.gitlabManager.testToken(true)).every(result => result); + return (await GitlabManager.testToken(true)).every(result => result); } else { return true; } @@ -25,7 +25,7 @@ class AccessesHelper { } if ( testGitlab ) { - return (await GlobalHelper.gitlabManager.testToken(true)).every(result => result); + return (await GitlabManager.testToken(true)).every(result => result); } else { return true; } diff --git a/NodeApp/src/helpers/GlobalHelper.ts b/NodeApp/src/helpers/GlobalHelper.ts index 50192cb34aab75aacb9b4e7b3fdabf9a202a35b1..8ecac86046acc962b43ca8212468150e3ac0b803 100644 --- a/NodeApp/src/helpers/GlobalHelper.ts +++ b/NodeApp/src/helpers/GlobalHelper.ts @@ -1,7 +1,6 @@ import { Command, Option } from 'commander'; import Config from '../config/Config'; import SessionManager from '../managers/SessionManager'; -import GitlabManager from '../managers/GitlabManager'; class GlobalHelper { @@ -16,13 +15,11 @@ class GlobalHelper { } - private readonly refreshGitlabTokenFunction = async () => { + public readonly refreshGitlabTokenFunction = async () => { await SessionManager.refreshTokens(); return SessionManager.gitlabCredentials.accessToken ?? ''; }; - - readonly gitlabManager = new GitlabManager('', this.refreshGitlabTokenFunction.bind(this)); } diff --git a/NodeApp/src/managers/GitlabManager.ts b/NodeApp/src/managers/GitlabManager.ts index b24ab00b76fab46e3e5b9c887a88fee61a079cf3..9291be49dced0d043b285bd14824eecd5bb0f702 100644 --- a/NodeApp/src/managers/GitlabManager.ts +++ b/NodeApp/src/managers/GitlabManager.ts @@ -4,12 +4,17 @@ import { spawn } from 'child_process'; import { NotificationSettingSchema, UserSchema } from '@gitbeaker/rest'; import * as GitlabCore from '@gitbeaker/core'; import SharedGitlabManager from '../shared/managers/SharedGitlabManager'; +import GlobalHelper from '../helpers/GlobalHelper'; type getGitlabUser = (param: number | string) => Promise<UserSchema | undefined> class GitlabManager extends SharedGitlabManager { + constructor() { + super('', GlobalHelper.refreshGitlabTokenFunction.bind(GlobalHelper)); + } + public async testToken(verbose: boolean = true): Promise<[ boolean, boolean ]> { if ( verbose ) { ora('Checking Gitlab token: ').start().info(); @@ -208,4 +213,4 @@ class GitlabManager extends SharedGitlabManager { } -export default GitlabManager; +export default new GitlabManager(); diff --git a/NodeApp/src/managers/SessionManager.ts b/NodeApp/src/managers/SessionManager.ts index 27264fca7fbc84911ebd6db4cdb6e6e9ff5319c8..9e8638e76317efa713155974c3b9460c88eb3f21 100644 --- a/NodeApp/src/managers/SessionManager.ts +++ b/NodeApp/src/managers/SessionManager.ts @@ -18,9 +18,9 @@ import inquirer from 'inquirer'; import GitlabToken from '../shared/types/Gitlab/GitlabToken'; import open from 'open'; import { sessionConfigFile } from '../config/ConfigFiles'; -import GlobalHelper from '../helpers/GlobalHelper'; import TextStyle from '../types/TextStyle'; import DojoBackendHelper from '../sharedByClients/helpers/Dojo/DojoBackendHelper'; +import GitlabManager from './GitlabManager'; class LoginServer { @@ -117,7 +117,7 @@ class SessionManager { sessionConfigFile.setParam(LocalConfigKeys.GITLAB, credentials); if ( credentials.accessToken ) { - GlobalHelper.gitlabManager.setToken(credentials.accessToken); + GitlabManager.setToken(credentials.accessToken); } } @@ -208,7 +208,7 @@ class SessionManager { }).start(); let gitlabTokens: GitlabToken; try { - gitlabTokens = await GlobalHelper.gitlabManager.getTokens(gitlabCode); + gitlabTokens = await GitlabManager.getTokens(gitlabCode); this.gitlabCredentials = { refreshToken: gitlabTokens.refresh_token, accessToken : gitlabTokens.access_token @@ -219,7 +219,7 @@ class SessionManager { throw error; } - const isGitlabTokensValid = (await GlobalHelper.gitlabManager.testToken()).every(value => value); + const isGitlabTokensValid = (await GitlabManager.testToken()).every(value => value); if ( !isGitlabTokensValid ) { throw new Error('Gitlab tokens are invalid'); } diff --git a/NodeApp/src/shared b/NodeApp/src/shared index 87bb71b1c38a784550d12efe7626e62323355813..e1ffeb584f5c7805befd951cb82ca179eabcaabb 160000 --- a/NodeApp/src/shared +++ b/NodeApp/src/shared @@ -1 +1 @@ -Subproject commit 87bb71b1c38a784550d12efe7626e62323355813 +Subproject commit e1ffeb584f5c7805befd951cb82ca179eabcaabb