Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • Dojo_Project_Nguyen/backend/dojobackendapi
  • dojo_project/projects/backend/dojobackendapi
2 results
Select Git revision
Show changes
Commits on Source (1)
{ {
"name" : "dojo_backend_api", "name" : "dojo_backend_api",
"description" : "Backend API for the Dojo Project", "description" : "Backend API for the Dojo Project",
"version" : "1.0.0", "version" : "1.0.1",
"license" : "", "license" : "",
"author" : "Michaël Minelli <michael-jean.minelli@hesge.ch>", "author" : "Michaël Minelli <michael-jean.minelli@hesge.ch>",
"main" : "app.js", "main" : "app.js",
......
...@@ -4,7 +4,7 @@ import { CustomValidator, ErrorMessage, FieldMessageFactory, Meta } from 'expres ...@@ -4,7 +4,7 @@ import { CustomValidator, ErrorMessage, FieldMessageFactory, Meta } from 'expres
import { BailOptions, ValidationChain } from 'express-validator/src/chain'; import { BailOptions, ValidationChain } from 'express-validator/src/chain';
import GitlabManager from '../managers/GitlabManager'; import GitlabManager from '../managers/GitlabManager';
import express from 'express'; import express from 'express';
import ExerciceHelper from '../shared/helpers/ExerciceHelper'; import SharedExerciceHelper from '../shared/helpers/Dojo/SharedExerciceHelper';
declare type DojoMeta = Meta & { declare type DojoMeta = Meta & {
...@@ -49,7 +49,7 @@ class DojoValidators { ...@@ -49,7 +49,7 @@ class DojoValidators {
readonly templateUrlValidator = this.toValidatorSchemaOptions({ readonly templateUrlValidator = this.toValidatorSchemaOptions({
bail : true, bail : true,
errorMessage: 'Template doesn\'t exist or you don\'t have access to it', errorMessage: 'Template doesn\'t exist or you don\'t have access to it',
options : (value, { options : (_value, {
req, req,
path path
}) => { }) => {
...@@ -86,14 +86,14 @@ class DojoValidators { ...@@ -86,14 +86,14 @@ class DojoValidators {
readonly exerciceResultsValidator = this.toValidatorSchemaOptions({ readonly exerciceResultsValidator = this.toValidatorSchemaOptions({
bail : true, bail : true,
errorMessage: 'Results: not provided or invalid format', errorMessage: 'Results: not provided or invalid format',
options : (value, { options : (_value, {
req, req,
path path
}) => { }) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const results = this.getParamValue(req, path); const results = this.getParamValue(req, path);
if ( results ) { if ( results ) {
ExerciceHelper.validateResultFile(results, false).isValid ? resolve(true) : reject(); SharedExerciceHelper.validateResultFile(results, false).isValid ? resolve(true) : reject();
} else { } else {
reject(); reject();
} }
......
...@@ -6,15 +6,15 @@ import GitlabMember from '../shared/types/Gitlab/GitlabMember'; ...@@ -6,15 +6,15 @@ import GitlabMember from '../shared/types/Gitlab/GitlabMember';
import { StatusCodes } from 'http-status-codes'; import { StatusCodes } from 'http-status-codes';
import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility'; import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility';
import GitlabUser from '../shared/types/Gitlab/GitlabUser'; import GitlabUser from '../shared/types/Gitlab/GitlabUser';
import GitlabRoutes from '../shared/types/Gitlab/GitlabRoutes';
import GitlabTreeFile from '../shared/types/Gitlab/GitlabTreeFile'; import GitlabTreeFile from '../shared/types/Gitlab/GitlabTreeFile';
import parseLinkHeader from 'parse-link-header'; import parseLinkHeader from 'parse-link-header';
import GitlabFile from '../shared/types/Gitlab/GitlabFile'; import GitlabFile from '../shared/types/Gitlab/GitlabFile';
import express from 'express'; import express from 'express';
import GitlabRoute from '../shared/types/Gitlab/GitlabRoute';
class GitlabManager { class GitlabManager {
private getApiUrl(route: GitlabRoutes): string { private getApiUrl(route: GitlabRoute): string {
return `${ Config.gitlab.apiURL }${ route }`; return `${ Config.gitlab.apiURL }${ route }`;
} }
...@@ -22,7 +22,7 @@ class GitlabManager { ...@@ -22,7 +22,7 @@ class GitlabManager {
try { try {
const params: any = {}; const params: any = {};
params[paramName] = paramToSearch; 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 ) { } } catch ( e ) { }
return undefined; return undefined;
...@@ -37,19 +37,19 @@ class GitlabManager { ...@@ -37,19 +37,19 @@ class GitlabManager {
} }
async getRepository(idOrNamespace: string): Promise<GitlabRepository> { 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; return response.data;
} }
async getRepositoryMembers(idOrNamespace: string): Promise<Array<GitlabMember>> { 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; return response.data;
} }
async createRepository(name: string, description: string, visibility: string, initializeWithReadme: boolean, namespace: number, sharedRunnersEnabled: boolean, wikiEnabled: boolean, import_url: string): Promise<GitlabRepository> { 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, name : name,
description : description, description : description,
import_url : import_url, import_url : import_url,
...@@ -64,7 +64,7 @@ class GitlabManager { ...@@ -64,7 +64,7 @@ class GitlabManager {
} }
async forkRepository(forkId: number, name: string, path: string, description: string, visibility: string, namespace: number): Promise<GitlabRepository> { 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, name : name,
path : path, path : path,
description : description, description : description,
...@@ -76,7 +76,7 @@ class GitlabManager { ...@@ -76,7 +76,7 @@ class GitlabManager {
} }
async editRepository(repoId: number, newAttributes: Partial<GitlabRepository>): Promise<GitlabRepository> { 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; return response.data;
} }
...@@ -86,7 +86,7 @@ class GitlabManager { ...@@ -86,7 +86,7 @@ class GitlabManager {
} }
async addRepositoryMember(repoId: number, userId: number, accessLevel: GitlabAccessLevel): Promise<GitlabMember> { 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, user_id : userId,
access_level: accessLevel access_level: accessLevel
}); });
...@@ -95,7 +95,7 @@ class GitlabManager { ...@@ -95,7 +95,7 @@ class GitlabManager {
} }
async addRepositoryVariable(repoId: number, key: string, value: string, isProtected: boolean, isMasked: boolean): Promise<GitlabMember> { 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, key : key,
variable_type: 'env_var', variable_type: 'env_var',
value : value, value : value,
...@@ -138,7 +138,7 @@ class GitlabManager { ...@@ -138,7 +138,7 @@ class GitlabManager {
} }
async protectBranch(repoId: number, branchName: string, allowForcePush: boolean, allowedToMerge: GitlabAccessLevel, allowedToPush: GitlabAccessLevel, allowedToUnprotect: GitlabAccessLevel): Promise<GitlabMember> { 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, name : branchName,
allow_force_push : allowForcePush, allow_force_push : allowForcePush,
merge_access_level : allowedToMerge.valueOf(), merge_access_level : allowedToMerge.valueOf(),
...@@ -150,7 +150,7 @@ class GitlabManager { ...@@ -150,7 +150,7 @@ class GitlabManager {
} }
async getRepositoryTree(repoId: number, recursive: boolean = true, branch: string = 'main'): Promise<Array<GitlabTreeFile>> { 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 = { let params: any = {
pagination: 'keyset', pagination: 'keyset',
recursive : recursive, recursive : recursive,
...@@ -178,7 +178,7 @@ class GitlabManager { ...@@ -178,7 +178,7 @@ class GitlabManager {
} }
async getFile(repoId: number, filePath: string, branch: string = 'main'): Promise<GitlabFile> { 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: { params: {
ref: branch ref: branch
} }
...@@ -188,7 +188,7 @@ class GitlabManager { ...@@ -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) { 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', encoding : 'base64',
branch : branch, branch : branch,
commit_message: commitMessage, commit_message: commitMessage,
......
Subproject commit eab5c0a5a32079fcb439a1ad79453611c8605536 Subproject commit f33e4e0c7b34f9060e8995550920d25cd3e73c40