From 2f5fb61ad2ce45be05ecbc20a2d5de0d91ec3ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <michael@minelli.me> Date: Sat, 12 Aug 2023 00:33:46 +0200 Subject: [PATCH] Update submodules --- ExpressAPI/package.json | 2 +- ExpressAPI/src/helpers/DojoValidators.ts | 8 +++---- ExpressAPI/src/managers/GitlabManager.ts | 28 ++++++++++++------------ ExpressAPI/src/shared | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/ExpressAPI/package.json b/ExpressAPI/package.json index f70be4a..19de02e 100644 --- a/ExpressAPI/package.json +++ b/ExpressAPI/package.json @@ -1,7 +1,7 @@ { "name" : "dojo_backend_api", "description" : "Backend API for the Dojo Project", - "version" : "1.0.0", + "version" : "1.0.1", "license" : "", "author" : "Michaƫl Minelli <michael-jean.minelli@hesge.ch>", "main" : "app.js", diff --git a/ExpressAPI/src/helpers/DojoValidators.ts b/ExpressAPI/src/helpers/DojoValidators.ts index 617c556..c443036 100644 --- a/ExpressAPI/src/helpers/DojoValidators.ts +++ b/ExpressAPI/src/helpers/DojoValidators.ts @@ -4,7 +4,7 @@ import { CustomValidator, ErrorMessage, FieldMessageFactory, Meta } from 'expres import { BailOptions, ValidationChain } from 'express-validator/src/chain'; import GitlabManager from '../managers/GitlabManager'; import express from 'express'; -import ExerciceHelper from '../shared/helpers/ExerciceHelper'; +import SharedExerciceHelper from '../shared/helpers/Dojo/SharedExerciceHelper'; declare type DojoMeta = Meta & { @@ -49,7 +49,7 @@ class DojoValidators { readonly templateUrlValidator = this.toValidatorSchemaOptions({ bail : true, errorMessage: 'Template doesn\'t exist or you don\'t have access to it', - options : (value, { + options : (_value, { req, path }) => { @@ -86,14 +86,14 @@ class DojoValidators { readonly exerciceResultsValidator = this.toValidatorSchemaOptions({ bail : true, errorMessage: 'Results: not provided or invalid format', - options : (value, { + options : (_value, { req, path }) => { return new Promise((resolve, reject) => { const results = this.getParamValue(req, path); if ( results ) { - ExerciceHelper.validateResultFile(results, false).isValid ? resolve(true) : reject(); + SharedExerciceHelper.validateResultFile(results, false).isValid ? resolve(true) : reject(); } else { reject(); } diff --git a/ExpressAPI/src/managers/GitlabManager.ts b/ExpressAPI/src/managers/GitlabManager.ts index 0b33bd5..53b6ee3 100644 --- a/ExpressAPI/src/managers/GitlabManager.ts +++ b/ExpressAPI/src/managers/GitlabManager.ts @@ -6,15 +6,15 @@ import GitlabMember from '../shared/types/Gitlab/GitlabMember'; import { StatusCodes } from 'http-status-codes'; import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility'; import GitlabUser from '../shared/types/Gitlab/GitlabUser'; -import GitlabRoutes from '../shared/types/Gitlab/GitlabRoutes'; import GitlabTreeFile from '../shared/types/Gitlab/GitlabTreeFile'; import parseLinkHeader from 'parse-link-header'; import GitlabFile from '../shared/types/Gitlab/GitlabFile'; import express from 'express'; +import GitlabRoute from '../shared/types/Gitlab/GitlabRoute'; class GitlabManager { - private getApiUrl(route: GitlabRoutes): string { + private getApiUrl(route: GitlabRoute): string { return `${ Config.gitlab.apiURL }${ route }`; } @@ -22,7 +22,7 @@ class GitlabManager { try { const params: any = {}; params[paramName] = paramToSearch; - return (await axios.get<Array<GitlabUser>>(this.getApiUrl(GitlabRoutes.USERS_GET), { params: params })).data[0]; + return (await axios.get<Array<GitlabUser>>(this.getApiUrl(GitlabRoute.USERS_GET), { params: params })).data[0]; } catch ( e ) { } return undefined; @@ -37,19 +37,19 @@ class GitlabManager { } async getRepository(idOrNamespace: string): Promise<GitlabRepository> { - const response = await axios.get<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_GET).replace('{{id}}', encodeURIComponent(idOrNamespace))); + const response = await axios.get<GitlabRepository>(this.getApiUrl(GitlabRoute.REPOSITORY_GET).replace('{{id}}', encodeURIComponent(idOrNamespace))); return response.data; } async getRepositoryMembers(idOrNamespace: string): Promise<Array<GitlabMember>> { - const response = await axios.get<Array<GitlabMember>>(this.getApiUrl(GitlabRoutes.REPOSITORY_MEMBERS_GET).replace('{{id}}', encodeURIComponent(idOrNamespace))); + const response = await axios.get<Array<GitlabMember>>(this.getApiUrl(GitlabRoute.REPOSITORY_MEMBERS_GET).replace('{{id}}', encodeURIComponent(idOrNamespace))); return response.data; } async createRepository(name: string, description: string, visibility: string, initializeWithReadme: boolean, namespace: number, sharedRunnersEnabled: boolean, wikiEnabled: boolean, import_url: string): Promise<GitlabRepository> { - const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_CREATE), { + const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoute.REPOSITORY_CREATE), { name : name, description : description, import_url : import_url, @@ -64,7 +64,7 @@ class GitlabManager { } async forkRepository(forkId: number, name: string, path: string, description: string, visibility: string, namespace: number): Promise<GitlabRepository> { - const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_FORK).replace('{{id}}', String(forkId)), { + const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoute.REPOSITORY_FORK).replace('{{id}}', String(forkId)), { name : name, path : path, description : description, @@ -76,7 +76,7 @@ class GitlabManager { } async editRepository(repoId: number, newAttributes: Partial<GitlabRepository>): Promise<GitlabRepository> { - const response = await axios.put<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_EDIT).replace('{{id}}', String(repoId)), newAttributes); + const response = await axios.put<GitlabRepository>(this.getApiUrl(GitlabRoute.REPOSITORY_EDIT).replace('{{id}}', String(repoId)), newAttributes); return response.data; } @@ -86,7 +86,7 @@ class GitlabManager { } async addRepositoryMember(repoId: number, userId: number, accessLevel: GitlabAccessLevel): Promise<GitlabMember> { - const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoutes.REPOSITORY_MEMBER_ADD).replace('{{id}}', String(repoId)), { + const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoute.REPOSITORY_MEMBER_ADD).replace('{{id}}', String(repoId)), { user_id : userId, access_level: accessLevel }); @@ -95,7 +95,7 @@ class GitlabManager { } async addRepositoryVariable(repoId: number, key: string, value: string, isProtected: boolean, isMasked: boolean): Promise<GitlabMember> { - const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoutes.REPOSITORY_VARIABLES_ADD).replace('{{id}}', String(repoId)), { + const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoute.REPOSITORY_VARIABLES_ADD).replace('{{id}}', String(repoId)), { key : key, variable_type: 'env_var', value : value, @@ -138,7 +138,7 @@ class GitlabManager { } async protectBranch(repoId: number, branchName: string, allowForcePush: boolean, allowedToMerge: GitlabAccessLevel, allowedToPush: GitlabAccessLevel, allowedToUnprotect: GitlabAccessLevel): Promise<GitlabMember> { - const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoutes.REPOSITORY_BRANCHES_PROTECT).replace('{{id}}', String(repoId)), { + const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoute.REPOSITORY_BRANCHES_PROTECT).replace('{{id}}', String(repoId)), { name : branchName, allow_force_push : allowForcePush, merge_access_level : allowedToMerge.valueOf(), @@ -150,7 +150,7 @@ class GitlabManager { } async getRepositoryTree(repoId: number, recursive: boolean = true, branch: string = 'main'): Promise<Array<GitlabTreeFile>> { - let address: string | undefined = this.getApiUrl(GitlabRoutes.REPOSITORY_TREE).replace('{{id}}', String(repoId)); + let address: string | undefined = this.getApiUrl(GitlabRoute.REPOSITORY_TREE).replace('{{id}}', String(repoId)); let params: any = { pagination: 'keyset', recursive : recursive, @@ -178,7 +178,7 @@ class GitlabManager { } async getFile(repoId: number, filePath: string, branch: string = 'main'): Promise<GitlabFile> { - const response = await axios.get<GitlabFile>(this.getApiUrl(GitlabRoutes.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), { + const response = await axios.get<GitlabFile>(this.getApiUrl(GitlabRoute.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), { params: { ref: branch } @@ -188,7 +188,7 @@ class GitlabManager { } async createFile(repoId: number, filePath: string, fileBase64: string, commitMessage: string, branch: string = 'main', authorName: string = 'Dojo', authorMail: string | undefined = undefined) { - await axios.post(this.getApiUrl(GitlabRoutes.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), { + await axios.post(this.getApiUrl(GitlabRoute.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), { encoding : 'base64', branch : branch, commit_message: commitMessage, diff --git a/ExpressAPI/src/shared b/ExpressAPI/src/shared index eab5c0a..f33e4e0 160000 --- a/ExpressAPI/src/shared +++ b/ExpressAPI/src/shared @@ -1 +1 @@ -Subproject commit eab5c0a5a32079fcb439a1ad79453611c8605536 +Subproject commit f33e4e0c7b34f9060e8995550920d25cd3e73c40 -- GitLab