3 files + 17 − 39 Inline Compare changes Side-by-side Inline Show whitespace changes Files 3 config/SharedConfig.ts +0 −31 Original line number Diff line number Diff line Loading @@ -4,42 +4,11 @@ class SharedConfig { public readonly logsFolder: string; public gitlab: { URL: string, apiURL: string }; public readonly login: { gitlab: { client: { id: string }, url: { redirect: string, token: string } } }; constructor() { this.production = process.env.NODE_ENV === 'production'; this.logsFolder = process.env.LOGS_FOLDER ?? ''; this.gitlab = { URL : process.env.GITLAB_URL ?? '', apiURL: process.env.GITLAB_API_URL ?? '' }; this.login = { gitlab: { client: { id: process.env.LOGIN_GITLAB_CLIENT_ID ?? '' }, url : { redirect: process.env.LOGIN_GITLAB_URL_REDIRECT ?? '', token : process.env.LOGIN_GITLAB_URL_TOKEN ?? '' } } }; } } Loading helpers/Dojo/SharedAssignmentHelper.ts +8 −2 Original line number Diff line number Diff line Loading @@ -3,10 +3,16 @@ import DojoStatusCode from '../../types/Dojo/DojoStatusCode.js'; import Json5FileValidator from '../Json5FileValidator.js'; import * as Gitlab from '@gitbeaker/rest'; import GitlabPipelineStatus from '../../types/Gitlab/GitlabPipelineStatus.js'; import GitlabManager from '../../../managers/GitlabManager.js'; import SharedGitlabManager from '../../managers/SharedGitlabManager'; class SharedAssignmentHelper { private gitlabManager!: SharedGitlabManager; init(gitlabManager: SharedGitlabManager) { this.gitlabManager = gitlabManager; } validateDescriptionFile(filePathOrStr: string, isFile: boolean = true, version: number = 1): { content: AssignmentFile | undefined, isValid: boolean, error: string | null } { if ( version === 1 ) { return Json5FileValidator.validateFile(AssignmentFile, filePathOrStr, isFile); Loading @@ -20,7 +26,7 @@ class SharedAssignmentHelper { } async isPublishable(repositoryId: number): Promise<{ isPublishable: boolean, lastPipeline: Gitlab.PipelineSchema | null, status?: { code: DojoStatusCode, message: string } }> { const pipelines = await GitlabManager.getRepositoryPipelines(repositoryId, 'main'); const pipelines = await this.gitlabManager.getRepositoryPipelines(repositoryId, 'main'); if ( pipelines.length > 0 ) { const lastPipeline = pipelines[0]; if ( lastPipeline.status !== GitlabPipelineStatus.SUCCESS.valueOf() ) { Loading managers/SharedGitlabManager.ts +9 −6 Original line number Diff line number Diff line import axios from 'axios'; import SharedConfig from '../config/SharedConfig.js'; import * as GitlabCore from '@gitbeaker/core'; import { GitbeakerRequestError } from '@gitbeaker/requester-utils'; import { Gitlab, PipelineSchema, ProjectSchema, UserSchema } from '@gitbeaker/rest'; Loading @@ -12,11 +11,11 @@ class SharedGitlabManager { setToken(token: string) { this.api = new Gitlab(Object.assign({ host: SharedConfig.gitlab.URL host: this.gitlabUrl ?? '' }, this.refreshTokenFunction ? { oauthToken: token } : { token: token })); } constructor(token: string, refreshTokenFunction?: () => Promise<string>) { constructor(public gitlabUrl: string, token: string, public clientId?: string, public urlRedirect?: string, public urlToken?: string, refreshTokenFunction?: () => Promise<string>) { this.refreshTokenFunction = refreshTokenFunction; this.setToken(token); } Loading @@ -36,13 +35,17 @@ class SharedGitlabManager { } async getTokens(codeOrRefresh: string, isRefresh: boolean = false, clientSecret: string = ''): Promise<GitlabToken> { const response = await axios.post<GitlabToken>(SharedConfig.login.gitlab.url.token, { client_id : SharedConfig.login.gitlab.client.id, if ( !this.urlToken ) { throw new Error('Error when initializing GitlabManager'); } const response = await axios.post<GitlabToken>(this.urlToken, { client_id : this.clientId, client_secret: clientSecret, grant_type : isRefresh ? 'refresh_token' : 'authorization_code', refresh_token: codeOrRefresh, code : codeOrRefresh, redirect_uri : SharedConfig.login.gitlab.url.redirect redirect_uri : this.urlRedirect }); return response.data; Loading
config/SharedConfig.ts +0 −31 Original line number Diff line number Diff line Loading @@ -4,42 +4,11 @@ class SharedConfig { public readonly logsFolder: string; public gitlab: { URL: string, apiURL: string }; public readonly login: { gitlab: { client: { id: string }, url: { redirect: string, token: string } } }; constructor() { this.production = process.env.NODE_ENV === 'production'; this.logsFolder = process.env.LOGS_FOLDER ?? ''; this.gitlab = { URL : process.env.GITLAB_URL ?? '', apiURL: process.env.GITLAB_API_URL ?? '' }; this.login = { gitlab: { client: { id: process.env.LOGIN_GITLAB_CLIENT_ID ?? '' }, url : { redirect: process.env.LOGIN_GITLAB_URL_REDIRECT ?? '', token : process.env.LOGIN_GITLAB_URL_TOKEN ?? '' } } }; } } Loading
helpers/Dojo/SharedAssignmentHelper.ts +8 −2 Original line number Diff line number Diff line Loading @@ -3,10 +3,16 @@ import DojoStatusCode from '../../types/Dojo/DojoStatusCode.js'; import Json5FileValidator from '../Json5FileValidator.js'; import * as Gitlab from '@gitbeaker/rest'; import GitlabPipelineStatus from '../../types/Gitlab/GitlabPipelineStatus.js'; import GitlabManager from '../../../managers/GitlabManager.js'; import SharedGitlabManager from '../../managers/SharedGitlabManager'; class SharedAssignmentHelper { private gitlabManager!: SharedGitlabManager; init(gitlabManager: SharedGitlabManager) { this.gitlabManager = gitlabManager; } validateDescriptionFile(filePathOrStr: string, isFile: boolean = true, version: number = 1): { content: AssignmentFile | undefined, isValid: boolean, error: string | null } { if ( version === 1 ) { return Json5FileValidator.validateFile(AssignmentFile, filePathOrStr, isFile); Loading @@ -20,7 +26,7 @@ class SharedAssignmentHelper { } async isPublishable(repositoryId: number): Promise<{ isPublishable: boolean, lastPipeline: Gitlab.PipelineSchema | null, status?: { code: DojoStatusCode, message: string } }> { const pipelines = await GitlabManager.getRepositoryPipelines(repositoryId, 'main'); const pipelines = await this.gitlabManager.getRepositoryPipelines(repositoryId, 'main'); if ( pipelines.length > 0 ) { const lastPipeline = pipelines[0]; if ( lastPipeline.status !== GitlabPipelineStatus.SUCCESS.valueOf() ) { Loading
managers/SharedGitlabManager.ts +9 −6 Original line number Diff line number Diff line import axios from 'axios'; import SharedConfig from '../config/SharedConfig.js'; import * as GitlabCore from '@gitbeaker/core'; import { GitbeakerRequestError } from '@gitbeaker/requester-utils'; import { Gitlab, PipelineSchema, ProjectSchema, UserSchema } from '@gitbeaker/rest'; Loading @@ -12,11 +11,11 @@ class SharedGitlabManager { setToken(token: string) { this.api = new Gitlab(Object.assign({ host: SharedConfig.gitlab.URL host: this.gitlabUrl ?? '' }, this.refreshTokenFunction ? { oauthToken: token } : { token: token })); } constructor(token: string, refreshTokenFunction?: () => Promise<string>) { constructor(public gitlabUrl: string, token: string, public clientId?: string, public urlRedirect?: string, public urlToken?: string, refreshTokenFunction?: () => Promise<string>) { this.refreshTokenFunction = refreshTokenFunction; this.setToken(token); } Loading @@ -36,13 +35,17 @@ class SharedGitlabManager { } async getTokens(codeOrRefresh: string, isRefresh: boolean = false, clientSecret: string = ''): Promise<GitlabToken> { const response = await axios.post<GitlabToken>(SharedConfig.login.gitlab.url.token, { client_id : SharedConfig.login.gitlab.client.id, if ( !this.urlToken ) { throw new Error('Error when initializing GitlabManager'); } const response = await axios.post<GitlabToken>(this.urlToken, { client_id : this.clientId, client_secret: clientSecret, grant_type : isRefresh ? 'refresh_token' : 'authorization_code', refresh_token: codeOrRefresh, code : codeOrRefresh, redirect_uri : SharedConfig.login.gitlab.url.redirect redirect_uri : this.urlRedirect }); return response.data; Loading