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
  • jw_sonar
  • jw_sonar_backup
  • main
  • move-to-esm-only
  • open_tool_for_self_hosting
  • v5.0
  • v4.1
  • v4.2
8 results

Target

Select target project
  • dojo_project/projects/shared/nodesharedcode
1 result
Select Git revision
  • jw_sonar
  • jw_sonar_backup
  • main
  • move-to-esm-only
  • open_tool_for_self_hosting
  • v5.0
  • v4.1
  • v4.2
8 results
Show changes
Commits on Source (7)
...@@ -8,26 +8,26 @@ import zlib from 'zlib'; ...@@ -8,26 +8,26 @@ import zlib from 'zlib';
class ArchiveHelper { class ArchiveHelper {
private async explore(absoluteBasePath: string, rootPath: string, pack: tar.Pack) { private async explore(absoluteBasePath: string, rootPath: string, pack: tar.Pack) {
for ( let file of await fs.promises.readdir(rootPath) ) { for ( const file of await fs.promises.readdir(rootPath) ) {
if ( file === 'output.tar' ) { let filename = file;
continue; if ( filename !== 'output.tar' ) {
} filename = path.join(rootPath, filename);
file = path.join(rootPath, file); const stat = await fs.promises.stat(filename);
const stat = await fs.promises.stat(file); if ( stat.isDirectory() ) {
if ( stat.isDirectory() ) { await this.explore(absoluteBasePath, filename, pack);
await this.explore(absoluteBasePath, file, pack); } else {
continue; const entry = pack.entry({
} name: filename.replace(absoluteBasePath, ''),
const entry = pack.entry({ size: stat.size
name: file.replace(absoluteBasePath, ''), }, err => {
size: stat.size if ( err ) {
}, (err) => { throw err;
if ( err ) { }
throw err; });
const readStream = fs.createReadStream(filename);
readStream.pipe(entry);
} }
}); }
const stream = fs.createReadStream(file);
stream.pipe(entry);
} }
} }
...@@ -55,7 +55,7 @@ class ArchiveHelper { ...@@ -55,7 +55,7 @@ class ArchiveHelper {
await this.compress(folderPath, tarDataStream); await this.compress(folderPath, tarDataStream);
data = await (new Promise((resolve) => { data = await (new Promise(resolve => {
tarDataStream.on('close', () => { tarDataStream.on('close', () => {
resolve(data); resolve(data);
}); });
......
...@@ -8,15 +8,14 @@ import Json5FileValidator from '../Json5FileValidator'; ...@@ -8,15 +8,14 @@ import Json5FileValidator from '../Json5FileValidator';
class SharedAssignmentHelper { class SharedAssignmentHelper {
validateDescriptionFile(filePathOrStr: string, isFile: boolean = true, version: number = 1): { content: AssignmentFile | undefined, isValid: boolean, error: string | null } { validateDescriptionFile(filePathOrStr: string, isFile: boolean = true, version: number = 1): { content: AssignmentFile | undefined, isValid: boolean, error: string | null } {
switch ( version ) { if ( version === 1 ) {
case 1: return Json5FileValidator.validateFile(AssignmentFile, filePathOrStr, isFile);
return Json5FileValidator.validateFile(AssignmentFile, filePathOrStr, isFile); } else {
default: return {
return { content: undefined,
content: undefined, isValid: false,
isValid: false, error : `Version ${ version } not supported`
error : `Version ${ version } not supported` };
};
} }
} }
...@@ -24,7 +23,7 @@ class SharedAssignmentHelper { ...@@ -24,7 +23,7 @@ class SharedAssignmentHelper {
const pipelines = await SharedGitlabManager.getRepositoryPipelines(repositoryId, 'main'); const pipelines = await SharedGitlabManager.getRepositoryPipelines(repositoryId, 'main');
if ( pipelines.length > 0 ) { if ( pipelines.length > 0 ) {
const lastPipeline = pipelines[0]; const lastPipeline = pipelines[0];
if ( lastPipeline.status != GitlabPipelineStatus.SUCCESS ) { if ( lastPipeline.status !== GitlabPipelineStatus.SUCCESS ) {
return { return {
isPublishable: false, isPublishable: false,
lastPipeline : lastPipeline, lastPipeline : lastPipeline,
......
class LazyVal<T> { class LazyVal<T> {
private val: T | undefined = undefined; private val: T | undefined = undefined;
private readonly valLoader: () => Promise<T> | T;
constructor(private valLoader: () => Promise<T> | T) {} constructor(valLoader: () => Promise<T> | T) {
this.valLoader = valLoader;
}
get value(): Promise<T> { get value(): Promise<T> {
return new Promise<T>((resolve) => { return new Promise<T>(resolve => {
if ( this.val === undefined ) { if ( this.val === undefined ) {
Promise.resolve(this.valLoader()).then((value: T) => { Promise.resolve(this.valLoader()).then((value: T) => {
this.val = value; this.val = value;
......
...@@ -14,8 +14,9 @@ class Toolbox { ...@@ -14,8 +14,9 @@ class Toolbox {
const files = await fs.readdir(dirPath); const files = await fs.readdir(dirPath);
await Promise.all(files.map(async file => { await Promise.all(files.map(async file => {
if ( (await fs.stat(dirPath + '/' + file)).isDirectory() ) { const filePath = path.join(dirPath, file);
arrayOfFiles = await this.getAllFiles(dirPath + '/' + file, arrayOfFiles); if ( (await fs.stat(filePath)).isDirectory() ) {
arrayOfFiles = await this.getAllFiles(filePath, arrayOfFiles);
} else { } else {
arrayOfFiles.push(path.join(dirPath, file)); arrayOfFiles.push(path.join(dirPath, file));
} }
......
...@@ -64,9 +64,7 @@ function registerStringCapitalizeName() { ...@@ -64,9 +64,7 @@ function registerStringCapitalizeName() {
function registerStringConvertWithEnvVars() { function registerStringConvertWithEnvVars() {
String.prototype.convertWithEnvVars = function (this: string): string { String.prototype.convertWithEnvVars = function (this: string): string {
return this.replace(/\${?([a-zA-Z0-9_]+)}?/g, (_match: string, p1: string) => { return this.replace(/\${?([a-zA-Z0-9_]+)}?/g, (_match: string, p1: string) => process.env[p1] || '');
return process.env[p1] || '';
});
}; };
} }
......
...@@ -51,32 +51,36 @@ class RecursiveFilesStats { ...@@ -51,32 +51,36 @@ class RecursiveFilesStats {
return this.getFiles(`${ path.resolve(rootPath) }/`, rootPath, options, [], callback); return this.getFiles(`${ path.resolve(rootPath) }/`, rootPath, options, [], callback);
} }
private async getFiles(absoluteBasePath: string, rootPath: string, options: RecursiveReaddirFilesOptions = {}, files: IFileDirStat[] = [], callback?: Callback): Promise<IFileDirStat[]> { private async getFilesDirsStat(rootPath: string, options: RecursiveReaddirFilesOptions): Promise<Array<IFileDirStat>> {
const {
ignored, include, exclude, filter
} = options;
const filesData = await fs.promises.readdir(rootPath); const filesData = await fs.promises.readdir(rootPath);
const fileDir: IFileDirStat[] = filesData.map((file) => ({ return filesData.map(file => ({
name: file, path: path.join(rootPath, file) name: file,
})).filter((item) => { path: path.join(rootPath, file)
if ( include && include.test(item.path) ) { })).filter(item => {
if ( options.include && options.include.test(item.path) ) {
return true; return true;
} }
if ( exclude && exclude.test(item.path) ) { if ( options.exclude && options.exclude.test(item.path) ) {
return false; return false;
} }
if ( ignored ) { if ( options.ignored ) {
return !ignored.test(item.path); return !options.ignored.test(item.path);
} }
return true; return true;
}); });
}
private async getFiles(absoluteBasePath: string, rootPath: string, options: RecursiveReaddirFilesOptions = {}, files: IFileDirStat[] = [], callback?: Callback): Promise<IFileDirStat[]> {
const fileDir: Array<IFileDirStat> = await this.getFilesDirsStat(rootPath, options);
if ( callback ) { if ( callback ) {
fileDir.map(async (item: IFileDirStat) => { fileDir.forEach(item => {
const stat = await this.getStat(item.path, absoluteBasePath, options); this.getStat(item.path, absoluteBasePath, options).then(stat => {
if ( stat.isDirectory!() ) { if ( stat.isDirectory!() ) {
await this.getFiles(absoluteBasePath, item.path, options, [], callback); this.getFiles(absoluteBasePath, item.path, options, [], callback).then();
} }
callback(item.path, stat); callback(item.path, stat);
});
}); });
} else { } else {
await Promise.all(fileDir.map(async (item: IFileDirStat) => { await Promise.all(fileDir.map(async (item: IFileDirStat) => {
...@@ -89,9 +93,9 @@ class RecursiveFilesStats { ...@@ -89,9 +93,9 @@ class RecursiveFilesStats {
} }
})); }));
} }
return files.filter((item) => { return files.filter(item => {
if ( filter && typeof filter === 'function' ) { if ( options.filter && typeof options.filter === 'function' ) {
return filter(item); return options.filter(item);
} }
return true; return true;
}); });
...@@ -124,10 +128,7 @@ class RecursiveFilesStats { ...@@ -124,10 +128,7 @@ class RecursiveFilesStats {
delete stat.ctimeMs; delete stat.ctimeMs;
delete stat.birthtimeMs; delete stat.birthtimeMs;
delete stat.atime; delete stat.atime;
//delete stat.mtime;
delete stat.ctime; delete stat.ctime;
//delete stat.birthtime;
//delete stat.mode;
} }
return stat; return stat;
......
...@@ -23,7 +23,11 @@ winston.addColors(colors); ...@@ -23,7 +23,11 @@ winston.addColors(colors);
const format = winston.format.combine(winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format(info => ({ const format = winston.format.combine(winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format(info => ({
...info, ...info,
level: info.level.toUpperCase() level: info.level.toUpperCase()
}))(), SharedConfig.production ? winston.format.uncolorize() : winston.format.colorize({ all: true }), winston.format.prettyPrint(), winston.format.errors({ stack: true }), winston.format.align(), winston.format.printf((info) => `[${ info.timestamp }] (${ process.pid }) ${ info.level } ${ info.message } ${ info.metadata ? `\n${ JSON.stringify(info.metadata) }` : '' } ${ info.stack ? `\n${ info.stack }` : '' } `)); }))(), SharedConfig.production ? winston.format.uncolorize() : winston.format.colorize({ all: true }), winston.format.prettyPrint(), winston.format.errors({ stack: true }), winston.format.align(), winston.format.printf(info => {
const metadata = info.metadata ? `\n${ JSON.stringify(info.metadata) }` : '';
const stack = info.stack ? `\n${ info.stack }` : '';
return `[${ info.timestamp }] (${ process.pid }) ${ info.level } ${ info.message } ${ metadata } ${ stack } `;
}));
const commonTransportOptions = { const commonTransportOptions = {
handleRejections: true, handleRejections: true,
...@@ -54,11 +58,11 @@ if ( SharedConfig.production ) { ...@@ -54,11 +58,11 @@ if ( SharedConfig.production ) {
}) ]); }) ]);
} }
const logger = winston.createLogger({ const WinstonLogger = winston.createLogger({
levels, levels,
format, format,
transports, transports,
exitOnError: false exitOnError: false
}); });
export default logger; export default WinstonLogger;
...@@ -5,7 +5,7 @@ import { z } from 'zod'; ...@@ -5,7 +5,7 @@ import { z } from 'zod';
const AssignmentFile = z.object({ const AssignmentFile = z.object({
dojoAssignmentVersion: z.number(), dojoAssignmentVersion: z.number(),
version : z.number(), version : z.number(),
immutable : z.array(ImmutableFileDescriptor.transform(value => value as ImmutableFileDescriptor)), immutable : z.array(ImmutableFileDescriptor),
result : z.object({ result : z.object({
container: z.string(), container: z.string(),
volume : z.string().optional() volume : z.string().optional()
......
enum DojoStatusCode { enum DojoStatusCode {
LOGIN_FAILED = 1, LOGIN_FAILED = 1,
REFRESH_TOKENS_FAILED = 2, REFRESH_TOKENS_FAILED = 2,
CLIENT_NOT_SUPPORTED = 100, CLIENT_NOT_SUPPORTED = 100,
CLIENT_VERSION_NOT_SUPPORTED = 110, CLIENT_VERSION_NOT_SUPPORTED = 110,
ASSIGNMENT_PUBLISH_NO_PIPELINE = 200, ASSIGNMENT_PUBLISH_NO_PIPELINE = 200,
ASSIGNMENT_PUBLISH_PIPELINE_FAILED = 201, ASSIGNMENT_PUBLISH_PIPELINE_FAILED = 201,
ASSIGNMENT_CREATION_GITLAB_ERROR = 202, ASSIGNMENT_CREATION_GITLAB_ERROR = 202,
ASSIGNMENT_CREATION_INTERNAL_ERROR = 203, ASSIGNMENT_CREATION_INTERNAL_ERROR = 203,
EXERCISE_CREATION_GITLAB_ERROR = 302, ASSIGNMENT_EXERCISE_NOT_RELATED = 204,
EXERCISE_CREATION_INTERNAL_ERROR = 303 ASSIGNMENT_NOT_PUBLISHED = 205,
EXERCISE_CORRECTION_NOT_EXIST = 206,
EXERCISE_CORRECTION_ALREADY_EXIST = 207,
ASSIGNMENT_NAME_CONFLICT = 208,
EXERCISE_CREATION_GITLAB_ERROR = 302,
EXERCISE_CREATION_INTERNAL_ERROR = 303,
MAX_EXERCISE_PER_ASSIGNMENT_REACHED = 304,
GITLAB_TEMPLATE_NOT_FOUND = 401,
GITLAB_TEMPLATE_ACCESS_UNAUTHORIZED = 402,
} }
......
const projectIdRoute = '/projects/{{id}}';
enum GitlabRoute { enum GitlabRoute {
NOTIFICATION_SETTINGS = '/notification_settings', NOTIFICATION_SETTINGS = '/notification_settings',
PROFILE_GET = '/user', PROFILE_GET = '/user',
USERS_GET = '/users', USERS_GET = '/users',
REPOSITORY_GET = '/projects/{{id}}', REPOSITORY_GET = '/projects/{{id}}',
REPOSITORY_CREATE = '/projects', // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values REPOSITORY_CREATE = '/projects', // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
REPOSITORY_DELETE = '/projects/{{id}}', // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values REPOSITORY_DELETE = projectIdRoute, // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
REPOSITORY_EDIT = '/projects/{{id}}', REPOSITORY_EDIT = projectIdRoute,
REPOSITORY_FORK = '/projects/{{id}}/fork', REPOSITORY_FORK = '/projects/{{id}}/fork',
REPOSITORY_MEMBER_ADD = '/projects/{{id}}/members', REPOSITORY_MEMBER_ADD = '/projects/{{id}}/members',
REPOSITORY_MEMBERS_GET = '/projects/{{id}}/members/all', REPOSITORY_MEMBERS_GET = '/projects/{{id}}/members/all',
......