From 4de84df60035ee75d12f6c622d9271a9e24d2fe0 Mon Sep 17 00:00:00 2001 From: Joel von der Weid <joel.von-der-weid@hesge.ch> Date: Tue, 25 Jun 2024 14:41:49 +0200 Subject: [PATCH] Add users to sonar projects and show url --- .../assignment/subcommands/AssignmentCreateCommand.ts | 6 +++++- .../commander/exercise/subcommands/ExerciseCreateCommand.ts | 4 ++++ NodeApp/src/managers/DojoBackendManager.ts | 5 +++++ NodeApp/src/shared | 2 +- NodeApp/src/sharedByClients | 2 +- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/NodeApp/src/commander/assignment/subcommands/AssignmentCreateCommand.ts b/NodeApp/src/commander/assignment/subcommands/AssignmentCreateCommand.ts index 79fd5e4..4d5e781 100644 --- a/NodeApp/src/commander/assignment/subcommands/AssignmentCreateCommand.ts +++ b/NodeApp/src/commander/assignment/subcommands/AssignmentCreateCommand.ts @@ -27,7 +27,8 @@ class AssignmentCreateCommand extends CommanderCommand { .action(this.commandAction.bind(this)); if (SharedConfig.sonar.enabled) { - this.command.requiredOption('-s, --sonar', 'add sonar to the code checking process for exercises derived from the assignment') + this.command.requiredOption('-s, --sonar', 'add sonar to the code checking process for assignment and exercises') + .requiredOption('-d, --no-sonar', 'disable sonar for the code checking process for assignment and exercises') .addOption(new Option('-g, --gate <gate>', 'quality gate for sonar').implies({sonar: true})) .addOption(new Option('-p, --profile <profile...>', 'quality profiles for sonar').default([]).implies({sonar: true})); } @@ -141,6 +142,9 @@ class AssignmentCreateCommand extends CommanderCommand { oraInfo(`${ chalk.magenta('Web URL:') } ${ assignment.gitlabCreationInfo.web_url }`); oraInfo(`${ chalk.magenta('HTTP Repo:') } ${ assignment.gitlabCreationInfo.http_url_to_repo }`); oraInfo(`${ chalk.magenta('SSH Repo:') } ${ assignment.gitlabCreationInfo.ssh_url_to_repo }`); + if (assignment.useSonar) { + oraInfo(`${ chalk.magenta('Sonar project:') } ${SharedConfig.sonar.url}/dashboard?id=${ assignment.sonarKey }`); + } } catch ( error ) { return; } diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts index 0021530..e7d7972 100644 --- a/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts +++ b/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts @@ -7,6 +7,7 @@ import DojoBackendManager from '../../../managers/DojoBackendManager'; import AccessesHelper from '../../../helpers/AccessesHelper'; import Assignment from '../../../sharedByClients/models/Assignment'; import Exercise from '../../../sharedByClients/models/Exercise'; +import SharedConfig from '../../../shared/config/SharedConfig'; class ExerciseCreateCommand extends CommanderCommand { @@ -82,6 +83,9 @@ class ExerciseCreateCommand extends CommanderCommand { oraInfo(`${ chalk.magenta('Web URL:') } ${ exercise.gitlabCreationInfo.web_url }`); oraInfo(`${ chalk.magenta('HTTP Repo:') } ${ exercise.gitlabCreationInfo.http_url_to_repo }`); oraInfo(`${ chalk.magenta('SSH Repo:') } ${ exercise.gitlabCreationInfo.ssh_url_to_repo }`); + if (assignment.useSonar) { + oraInfo(`${ chalk.magenta('Sonar project:') } ${SharedConfig.sonar.url}/dashboard?id=${ exercise.sonarKey }`); + } } catch ( error ) { return; } diff --git a/NodeApp/src/managers/DojoBackendManager.ts b/NodeApp/src/managers/DojoBackendManager.ts index 46e7c6a..441f249 100644 --- a/NodeApp/src/managers/DojoBackendManager.ts +++ b/NodeApp/src/managers/DojoBackendManager.ts @@ -10,6 +10,7 @@ import Exercise from '../sharedByClients/models/Exercise'; import GitlabToken from '../shared/types/Gitlab/GitlabToken'; import User from '../sharedByClients/models/User'; import DojoStatusCode from '../shared/types/Dojo/DojoStatusCode'; +import SharedConfig from '../shared/config/SharedConfig'; class DojoBackendManager { @@ -113,6 +114,8 @@ class DojoBackendManager { } else { if ( (error.response.data as DojoBackendResponse<unknown>).code === DojoStatusCode.ASSIGNMENT_CREATION_GITLAB_ERROR ) { spinner.fail(`Assignment creation error: An unknown error occurred while creating the assignment on Gitlab. Please try again later or contact an administrator.`); + } else if ( (error.response.data as DojoBackendResponse<unknown>).code === DojoStatusCode.ASSIGNMENT_CREATION_SONAR_MEMBER ) { + spinner.fail(`Tous les membres du projet doivent s'être connectés une première fois à SonarQube avec leurs identifiants Gitlab pour pouvoir créer le projet.\nURL: ${SharedConfig.sonar.url}/`); } else { spinner.fail(`Assignment creation error: An unknown error occurred while creating the assignment on Dojo server. Please try again later or contact an administrator.`); } @@ -155,6 +158,8 @@ class DojoBackendManager { } else { if ( (error.response.data as DojoBackendResponse<unknown>).code === DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR ) { spinner.fail(`Exercise creation error: An unknown error occurred while creating the exercise on Gitlab. Please try again later or contact an administrator.`); + } else if ( (error.response.data as DojoBackendResponse<unknown>).code === DojoStatusCode.ASSIGNMENT_CREATION_SONAR_MEMBER ) { + spinner.fail(`Tous les membres du projet doivent s'être connectés une première fois à SonarQube avec leurs identifiants Gitlab pour pouvoir créer le projet.\nURL: ${SharedConfig.sonar.url}/`); } else { spinner.fail(`Exercise creation error: An unknown error occurred while creating the exercise on Dojo server. Please try again later or contact an administrator.`); } diff --git a/NodeApp/src/shared b/NodeApp/src/shared index bd29fe7..8efab43 160000 --- a/NodeApp/src/shared +++ b/NodeApp/src/shared @@ -1 +1 @@ -Subproject commit bd29fe76fdb1b124e3fe2f23e995a2b3b70694a7 +Subproject commit 8efab438a60569011f2757c803a89c81bc46a174 diff --git a/NodeApp/src/sharedByClients b/NodeApp/src/sharedByClients index 41b3d88..d15be9b 160000 --- a/NodeApp/src/sharedByClients +++ b/NodeApp/src/sharedByClients @@ -1 +1 @@ -Subproject commit 41b3d88544eb46171acf36b4fd61332c33db5bf8 +Subproject commit d15be9b16181f5f172d51b13966e0e44bd34f55d -- GitLab