From 53ed56e99d73e5f4b53d4188fc45e6bcaf9b812c Mon Sep 17 00:00:00 2001
From: Orestis <orestis.malaspinas@pm.me>
Date: Thu, 4 Jan 2024 20:35:29 +0100
Subject: [PATCH] Fixes bug cloning assignment instead of exercise

---
 .../subcommands/ExerciseCreateCommand.ts      | 78 +++++++++----------
 1 file changed, 39 insertions(+), 39 deletions(-)

diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts
index 2a8f939..0021530 100644
--- a/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts
+++ b/NodeApp/src/commander/exercise/subcommands/ExerciseCreateCommand.ts
@@ -1,12 +1,12 @@
-import CommanderCommand from '../../CommanderCommand';
-import chalk from 'chalk';
-import GitlabManager from '../../../managers/GitlabManager';
-import GitlabUser from '../../../shared/types/Gitlab/GitlabUser';
-import ora from 'ora';
+import CommanderCommand   from '../../CommanderCommand';
+import chalk              from 'chalk';
+import GitlabManager      from '../../../managers/GitlabManager';
+import GitlabUser         from '../../../shared/types/Gitlab/GitlabUser';
+import ora                from 'ora';
 import DojoBackendManager from '../../../managers/DojoBackendManager';
-import AccessesHelper from '../../../helpers/AccessesHelper';
-import Assignment from '../../../sharedByClients/models/Assignment';
-import Exercise from '../../../sharedByClients/models/Exercise';
+import AccessesHelper     from '../../../helpers/AccessesHelper';
+import Assignment         from '../../../sharedByClients/models/Assignment';
+import Exercise           from '../../../sharedByClients/models/Exercise';
 
 
 class ExerciseCreateCommand extends CommanderCommand {
@@ -14,12 +14,12 @@ class ExerciseCreateCommand extends CommanderCommand {
 
     protected defineCommand() {
         this.command
-            .description('create a new exercise from an assignment')
-            .requiredOption('-a, --assignment <value>', 'assignment source (Dojo assignment ID, Dojo assignment name or Gitlab assignment URL)')
-            .option('-i, --members_id <ids...>', 'list of gitlab members ids (group\'s student) to add to the repository')
-            .option('-u, --members_username <usernames...>', 'list of gitlab members username (group\'s student) to add to the repository')
-            .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));
+        .description('create a new exercise from an assignment')
+        .requiredOption('-a, --assignment <value>', 'assignment source (Dojo assignment ID, Dojo assignment name or Gitlab assignment URL)')
+        .option('-i, --members_id <ids...>', 'list of gitlab members ids (group\'s student) to add to the repository')
+        .option('-u, --members_username <usernames...>', 'list of gitlab members username (group\'s student) to add to the repository')
+        .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));
     }
 
     protected async commandAction(options: { assignment: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean }): Promise<void> {
@@ -31,36 +31,36 @@ class ExerciseCreateCommand extends CommanderCommand {
         {
             console.log(chalk.cyan('Please wait while we verify and retrieve data...'));
 
-            if (!await AccessesHelper.checkStudent()) {
+            if ( !await AccessesHelper.checkStudent() ) {
                 return;
             }
 
             members = await GitlabManager.fetchMembers(options);
-            if (!members) {
+            if ( !members ) {
                 return;
             }
 
             ora('Checking assignment:').start().info();
             const assignmentGetSpinner: ora.Ora = ora({
-                text: 'Checking if assignment exists',
-                indent: 4
-            }).start();
+                                                          text  : 'Checking if assignment exists',
+                                                          indent: 4
+                                                      }).start();
             assignment = await DojoBackendManager.getAssignment(options.assignment);
-            if (!assignment) {
-                assignmentGetSpinner.fail(`Assignment "${options.assignment}" doesn't exists`);
+            if ( !assignment ) {
+                assignmentGetSpinner.fail(`Assignment "${ options.assignment }" doesn't exists`);
                 return;
             }
-            assignmentGetSpinner.succeed(`Assignment "${options.assignment}" exists`);
+            assignmentGetSpinner.succeed(`Assignment "${ options.assignment }" exists`);
 
             const assignmentPublishedSpinner: ora.Ora = ora({
-                text: 'Checking if assignment is published',
-                indent: 4
-            }).start();
-            if (!assignment.published) {
-                assignmentPublishedSpinner.fail(`Assignment "${assignment.name}" isn't published`);
+                                                                text  : 'Checking if assignment is published',
+                                                                indent: 4
+                                                            }).start();
+            if ( !assignment.published ) {
+                assignmentPublishedSpinner.fail(`Assignment "${ assignment.name }" isn't published`);
                 return;
             }
-            assignmentPublishedSpinner.succeed(`Assignment "${assignment.name}" is published`);
+            assignmentPublishedSpinner.succeed(`Assignment "${ assignment.name }" is published`);
         }
 
         //Create the exercise
@@ -72,27 +72,27 @@ class ExerciseCreateCommand extends CommanderCommand {
 
                 const oraInfo = (message: string) => {
                     ora({
-                        text: message,
-                        indent: 4
-                    }).start().info();
+                            text  : message,
+                            indent: 4
+                        }).start().info();
                 };
 
-                oraInfo(`${chalk.magenta('Id:')} ${exercise.id}`);
-                oraInfo(`${chalk.magenta('Name:')} ${exercise.name}`);
-                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}`);
-            } catch (error) {
+                oraInfo(`${ chalk.magenta('Id:') } ${ exercise.id }`);
+                oraInfo(`${ chalk.magenta('Name:') } ${ exercise.name }`);
+                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 }`);
+            } catch ( error ) {
                 return;
             }
         }
 
         // Clone the repository
         {
-            if (options.clone) {
+            if ( options.clone ) {
                 console.log(chalk.cyan('Please wait while we are cloning the repository...'));
 
-                await GitlabManager.cloneRepository(options.clone, exercise.gitlabCreationInfo.ssh_url_to_repo, `DojoExercise - ${exercise.assignmentName}`, true, 0);
+                await GitlabManager.cloneRepository(options.clone, exercise.gitlabCreationInfo.ssh_url_to_repo, `DojoExercise - ${ exercise.assignmentName }`, true, 0);
             }
         }
     }
-- 
GitLab