Skip to content
Snippets Groups Projects
Commit e467c56b authored by joel.vonderwe's avatar joel.vonderwe
Browse files

Check sonar on assignment creation

parent d9bfbaa8
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ class AssignmentCreateCommand extends CommanderCommand { ...@@ -23,7 +23,7 @@ class AssignmentCreateCommand extends CommanderCommand {
.option('-c, --clone [string]', 'automatically clone the repository (SSH required) in the specified directory (this will create a subdirectory with the assignment name)') .option('-c, --clone [string]', 'automatically clone the repository (SSH required) in the specified directory (this will create a subdirectory with the assignment name)')
.action(this.commandAction.bind(this)); .action(this.commandAction.bind(this));
if (SharedConfig.useSonar) { 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 exercises derived from the assignment');
} }
} }
...@@ -32,6 +32,7 @@ class AssignmentCreateCommand extends CommanderCommand { ...@@ -32,6 +32,7 @@ class AssignmentCreateCommand extends CommanderCommand {
let members!: Array<GitlabUser> | false; let members!: Array<GitlabUser> | false;
let templateIdOrNamespace: string | null = null; let templateIdOrNamespace: string | null = null;
let assignment!: Assignment; let assignment!: Assignment;
let sonar = false;
// Check access and retrieve data // Check access and retrieve data
{ {
...@@ -46,6 +47,14 @@ class AssignmentCreateCommand extends CommanderCommand { ...@@ -46,6 +47,14 @@ class AssignmentCreateCommand extends CommanderCommand {
return; return;
} }
const assignmentGetSonarSpinner: ora.Ora = ora('Checking server sonar status').start();
sonar = (SharedConfig.sonar.enabled ? options.sonar ?? false : false);
if (sonar && !(await DojoBackendManager.isSonarEnabled())) {
assignmentGetSonarSpinner.fail(`Sonar is currently not supported by the server. Disable sonar integration or try again later.`);
return;
}
assignmentGetSonarSpinner.succeed(`Sonar is supported by the server`);
const assignmentGetSpinner: ora.Ora = ora('Checking assignment name availability').start(); const assignmentGetSpinner: ora.Ora = ora('Checking assignment name availability').start();
if ( await DojoBackendManager.getAssignment(options.name) ) { if ( await DojoBackendManager.getAssignment(options.name) ) {
assignmentGetSpinner.fail(`Assignment name "${ options.name }" is already taken. Please choose another one.`); assignmentGetSpinner.fail(`Assignment name "${ options.name }" is already taken. Please choose another one.`);
...@@ -71,8 +80,6 @@ class AssignmentCreateCommand extends CommanderCommand { ...@@ -71,8 +80,6 @@ class AssignmentCreateCommand extends CommanderCommand {
console.log(chalk.cyan('Please wait while we are creating the assignment (approximately 10 seconds)...')); console.log(chalk.cyan('Please wait while we are creating the assignment (approximately 10 seconds)...'));
try { try {
const sonar = (SharedConfig.useSonar ? options.sonar ?? false : false);
assignment = await DojoBackendManager.createAssignment(options.name, members, templateIdOrNamespace, sonar); assignment = await DojoBackendManager.createAssignment(options.name, members, templateIdOrNamespace, sonar);
const oraInfo = (message: string) => { const oraInfo = (message: string) => {
......
...@@ -91,9 +91,9 @@ class DojoBackendManager { ...@@ -91,9 +91,9 @@ class DojoBackendManager {
try { try {
const response = await axios.post<DojoBackendResponse<Assignment>>(this.getApiUrl(ApiRoute.ASSIGNMENT_CREATE), Object.assign({ const response = await axios.post<DojoBackendResponse<Assignment>>(this.getApiUrl(ApiRoute.ASSIGNMENT_CREATE), Object.assign({
name : name, name : name,
members: JSON.stringify(members), members : JSON.stringify(members),
sonar : sonar useSonar : sonar
}, templateIdOrNamespace ? { template: templateIdOrNamespace } : {})); }, templateIdOrNamespace ? { template: templateIdOrNamespace } : {}));
if ( verbose ) { if ( verbose ) {
...@@ -236,6 +236,11 @@ class DojoBackendManager { ...@@ -236,6 +236,11 @@ class DojoBackendManager {
return false; return false;
} }
} }
public async isSonarEnabled() {
const sonar = await axios.get<DojoBackendResponse<{ sonarEnabled: boolean }>>(this.getApiUrl(ApiRoute.SONAR));
return sonar.data.data.sonarEnabled;
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment